From 78f2a9dc142341ba361420c63200a60c6d58da81 Mon Sep 17 00:00:00 2001 From: Matěj Cepl Date: Sun, 4 Sep 2011 03:11:54 +0200 Subject: Add some comments on very ugly function libbz.loginToAllBugzillas. --- lib/libbugzilla.js | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) (limited to 'lib') diff --git a/lib/libbugzilla.js b/lib/libbugzilla.js index d03cd3c..f7ae37b 100644 --- a/lib/libbugzilla.js +++ b/lib/libbugzilla.js @@ -294,16 +294,19 @@ exports.createUpstreamBug = function createUpstreamBug(urlStr, subjectStr, comme }; function loginToAllBugzillas(callback) { - var callbacksCounter = 0, bugzilla = ""; + var loginCallsCounter = 0, bugzilla = ""; if ("enabledPackages" in config.gJSONData.configData) { + // For all bugzillas we are interested in ... for (bugzillaHost in config.gJSONData.configData.enabledPackages) { passUtils.search({ url: "https://" + bugzillaHost, realm: BTSPassRealm, + // ... and for which we have credentials on file ... onComplete: function onComplete(credentials) { + // (we can have more than one set of credentials per bugzilla; + // well, theoretically) credentials.forEach(function(credential) { - debug("credential = " + credential.toSource()); - // function makeJSONRPCCall(url, method, params, callback) + // ... login! makeJSONRPCCall(credential.url + "/jsonrpc.cgi", "User.login", { login: credential.username, @@ -311,13 +314,15 @@ function loginToAllBugzillas(callback) { remember: false }, function(logResult) { debug("Logging as " + credential.username + " to " + credential.url); - callbacksCounter--; - if (callbacksCounter <= 0) { + loginCallsCounter--; + // When we complete all logins, execute the callback + if (loginCallsCounter <= 0) { debug("All logins done!"); callback(); } }); - callbacksCounter++; + // Increment call counter + loginCallsCounter++; }); }, onError: function onError() { -- cgit