Skip to content

Commit

Permalink
fix async issue
Browse files Browse the repository at this point in the history
  • Loading branch information
deniak committed Jul 9, 2018
1 parent 9963612 commit d571154
Showing 1 changed file with 17 additions and 9 deletions.
26 changes: 17 additions & 9 deletions lib/transition-checker.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ TransitionChecker.check = function (profile, latestVersion, previousVersion, isE
var directorApprovalFound = false;
var commApprovalFound = false;
var issueFound = false;
var issueNumber;

repo.issues.fetch(
{
Expand All @@ -45,29 +46,36 @@ TransitionChecker.check = function (profile, latestVersion, previousVersion, isE
for (var issue of content.items) {
if (issue.title.endsWith(' ' + shortname)) {
issueFound = true;
issueNumber = issue.number;
repo.issues(issue.number).comments.fetch()
.then((comments) => {
var promises = [];

for (var comment of comments.items) {
if (comment.body.toLowerCase().startsWith(directorApproval)) {
// Director's approval
octo.teams(global.GH_DIRECTOR_TEAM_ID).members(comment.user.login).fetch((err) => {
var p1 = octo.teams(global.GH_DIRECTOR_TEAM_ID).members(comment.user.login).fetch((err) => {
if (!err) directorApprovalFound = true;
});
promises.push(p1);
}
else if (comment.body.toLowerCase().startsWith(commApproval)) {
// Comm's approval
octo.teams(global.GH_COMM_TEAM_ID).members(comment.user.login).fetch((err) => {
var p2 = octo.teams(global.GH_COMM_TEAM_ID).members(comment.user.login).fetch((err) => {
if (!err) commApprovalFound = true;
});
promises.push(p2);
}
}
if (!directorApprovalFound) errors = errors.push('Director\'s approval not found.');
if (!commApprovalFound) errors = errors.push('Communication team\'s approval not found.');
if (directorApprovalFound && commApprovalFound) {
// Close issue
repo.issues(issue.number).update({ state: 'closed' });
}
return resolve({ errors: errors, requiresCfE: true });
Promise.all(promises).then(function () {
if (!directorApprovalFound) errors = errors.push('Approval from Director not found.');
if (!commApprovalFound) errors = errors.push('Approval from Communication Team not found.');
if (directorApprovalFound && commApprovalFound) {
// Close issue
repo.issues(issueNumber).update({ state: 'closed' });
}
return resolve({ errors: errors, requiresCfE: true });
});
});
}
}
Expand Down

0 comments on commit d571154

Please sign in to comment.