Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix issues count in repo #121

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
152 changes: 76 additions & 76 deletions lib/checking.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,88 +90,88 @@ function confirmCrawler(options) {
} else {
return reject(err);
}
}
repo.find({}, {full_name:1}).toArray().then(repos => {
var repo_names = repos.map(r => { return r.full_name.toLowerCase(); });
var unfound = [];
options.userConfig.github_repositories.forEach(ur => {
if (repo_names.indexOf(ur.toLowerCase()) == -1) {
unfound.push(ur);
}
})
if (unfound.length > 0) {
console.warn(wrap(NICE_ERRORS.notyetWarning(orgs, unfound), {width: 65}));
}
})
repo.find({}, {full_name:1, open_issues_count:1}).toArray().then(repos => {
var repo_names = repos.map(r => { return r.full_name.toLowerCase(); });
var unfound = [];
options.userConfig.github_repositories.forEach(ur => {
if (repo_names.indexOf(ur.toLowerCase()) == -1) {
unfound.push(ur);
}
})
if (unfound.length > 0) {
console.warn(wrap(NICE_ERRORS.notyetWarning(orgs, unfound), {width: 65}));
}

/*
Confirm that there are at least some issues for each repo in your
config. If not, show a warning.
*/
var open_issues_expected_per_repo = {};
repos.forEach(function(r) {
open_issues_expected_per_repo[r.full_name.toLowerCase()] = r.open_issues_count;
})
async.eachLimit(options.userConfig.github_repositories, 5, function(repo_name, done) {
issue.find({html_url: { $regex: new RegExp(repo_name), $options: 'i' }}).sort({updated_at:-1}).limit(1).toArray().then(iss => {
var fetched_issue_count = iss.length,
fetched_open_issue_count = 0,
fetched_closed_issue_count = 0;
var expected_open_issue_count = open_issues_expected_per_repo[repo_name.toLowerCase()];
iss.forEach(function(i) {
if (i.closed_at) {
fetched_closed_issue_count += 1;
} else {
fetched_open_issue_count += 1;
}
});
/*
Confirm that there are at least some issues for each repo in your
config. If not, show a warning.
*/
var open_issues_expected_per_repo = {};
repos.forEach(function(r) {
open_issues_expected_per_repo[r.full_name.toLowerCase()] = r.open_issues_count;
})
async.eachLimit(options.userConfig.github_repositories, 5, function(repo_name, done) {
issue.find({html_url: { $regex: new RegExp(repo_name), $options: 'i' }}).sort({updated_at:-1}).limit(1).toArray().then(iss => {
var fetched_issue_count = iss.length,
fetched_open_issue_count = 0,
fetched_closed_issue_count = 0;
var expected_open_issue_count = open_issues_expected_per_repo[repo_name.toLowerCase()];
iss.forEach(function(i) {
if (i.closed_at) {
fetched_closed_issue_count += 1;
} else {
fetched_open_issue_count += 1;
}
});

/* we now know:
how many open issues github thinks this repo has (expected_open_issue_count)
how many open issues we actually have data for (fetched_open_issue_count)
how many issues in total we actually have data for (fetched_issue_count)
Some or all of these figures may be out of date, if we're in the process
of fetching data, of course. But they give us some indication of how
to warn the user. */
/* we now know:
how many open issues github thinks this repo has (expected_open_issue_count)
how many open issues we actually have data for (fetched_open_issue_count)
how many issues in total we actually have data for (fetched_issue_count)
Some or all of these figures may be out of date, if we're in the process
of fetching data, of course. But they give us some indication of how
to warn the user. */

var warning;
if (fetched_issue_count === 0) {
// We don't have any data in our DB about issues for this repo
if (fetched_open_issue_count === 0) {
// and we're not expecting there to be any *open* issues.
// It's possible that there are closed issues which remain
// unfetched, so we can't assume we're up to date, but the
// message can be somewhat conciliatory.
warning = "WARNING: there are no issues in our database for the " +
repo_name + " repository. It's quite likely that this is because " +
"there actually aren't any, but it's possible that there are closed " +
"issues which we are still in the process of fetching data for.";
} else {
warning = "WARNING: there are no issues recorded for the " +
repo_name + " repository. This is very likely because we are still " +
"in the process of fetching that data. Dashboards may be inaccurate " +
"until the data fetch is complete and they are regenerated.";
}
var warning;
if (fetched_issue_count === 0) {
// We don't have any data in our DB about issues for this repo
if (fetched_open_issue_count === 0) {
// and we're not expecting there to be any *open* issues.
// It's possible that there are closed issues which remain
// unfetched, so we can't assume we're up to date, but the
// message can be somewhat conciliatory.
warning = "WARNING: there are no issues in our database for the " +
repo_name + " repository. It's quite likely that this is because " +
"there actually aren't any, but it's possible that there are closed " +
"issues which we are still in the process of fetching data for.";
} else {
if (fetched_open_issue_count < expected_open_issue_count) {
warning = "WARNING: there are fewer open issues in our database for the " +
repo_name + " repository than we expect. This is very likely because " +
"we are still in the process of fetching that data. Dashboards " +
"may be inaccurate until the data fetch is complete and " +
"they are regenerated.";
}
warning = "WARNING: there are no issues recorded for the " +
repo_name + " repository. This is very likely because we are still " +
"in the process of fetching that data. Dashboards may be inaccurate " +
"until the data fetch is complete and they are regenerated.";
}

if (warning) {
console.warn(wrap(warning, {width: 65}));
} else {
if (fetched_open_issue_count < expected_open_issue_count) {
warning = "WARNING: there are fewer open issues in our database for the " +
repo_name + " repository than we expect. This is very likely because " +
"we are still in the process of fetching that data. Dashboards " +
"may be inaccurate until the data fetch is complete and " +
"they are regenerated.";
}
done();
}).catch(e => { done(e); })
}, function(err) {
if (err) { return reject(err); }
return resolve(options);
})
}).catch(e => { return reject(e); })
})
}

if (warning) {
console.warn(wrap(warning, {width: 65}));
}
done();
}).catch(e => { done(e); })
}, function(err) {
if (err) { return reject(err); }
return resolve(options);
})
}).catch(e => { return reject(e); })
})
});
});
Expand Down Expand Up @@ -246,4 +246,4 @@ module.exports = {
confirmCrawler: confirmCrawler,
confirmActivity: confirmActivity,
confirmTokens: confirmTokens
}
}