-
Notifications
You must be signed in to change notification settings - Fork 67
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: add stale build label if it is removed before updating branch #235
Conversation
@vojtechjelinek @jameesjohn sir please review this pr. |
manual testing video: bot.mp4 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! Left a few comments.
lib/checkPullRequestLabels.js
Outdated
const commentParams = context.issue({ | ||
body: | ||
'Hi @' + user.login + ', the build of this pr is ' + | ||
' stale please do not remove ' + [OLD_BUILD_LABEL] + |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
' stale please do not remove ' + [OLD_BUILD_LABEL] + | |
' stale please do not remove \'' + OLD_BUILD_LABEL + '\'' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
addressed in latest commits
lib/checkPullRequestLabels.js
Outdated
const commentParams = context.issue({ | ||
body: | ||
'Hi @' + user.login + ', the build of this pr is ' + | ||
' stale please do not remove ' + [OLD_BUILD_LABEL] + | ||
' label. ', | ||
}); | ||
await context.github.issues.createComment(commentParams); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const commentParams = context.issue({ | |
body: | |
'Hi @' + user.login + ', the build of this pr is ' + | |
' stale please do not remove ' + [OLD_BUILD_LABEL] + | |
' label. ', | |
}); | |
await context.github.issues.createComment(commentParams); | |
const commentParams = context.issue({ | |
body: | |
'Hi @' + user.login + ', the build of this pr is ' + | |
' stale please do not remove ' + [OLD_BUILD_LABEL] + | |
' label. ', | |
}); | |
await context.github.issues.createComment(commentParams); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
addressed in latest commits
lib/checkPullRequestLabels.js
Outdated
* This function checks and prevent the removal of critical label | ||
* by unauthorised users. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* This function checks and prevent the removal of critical label | |
* by unauthorised users. | |
* This function checks and prevent the removal of stale build label | |
* by unauthorised users. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
addressed in latest commits
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, @nlok5923. I left some comments.
lib/checkPullRequestLabels.js
Outdated
const commentParams = context.issue({ | ||
body: | ||
'Hi @' + user.login + ', the build of this pr is ' + | ||
' stale please do not remove \'' + OLD_BUILD_LABEL + '\'' + | ||
' label. ', | ||
}); | ||
await context.github.issues.createComment(commentParams); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Before commenting on this PR, we need to actually check if the build of the PR is stale.
See
oppiabot/lib/staleBuildChecks.js
Lines 22 to 30 in 959b59c
const {data: lastCommit} = await context.github.repos.getCommit( | |
context.repo({ | |
ref: pullRequest.head.sha | |
}) | |
); | |
const lastCommitDate = new Date(lastCommit.commit.author.date); | |
// Commit is older than 2 days | |
if (utils.MIN_BUILD_DATE > lastCommitDate) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes sir i agree with you i had added the check in the latest commit.
lib/checkPullRequestLabels.js
Outdated
* | ||
* @param {import('probot').Context} context | ||
*/ | ||
module.exports.checkBuildLabelRemoval = async function (context) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
module.exports.checkBuildLabelRemoval = async function (context) { | |
module.exports.checkStaleBuildLabelRemoval = async function (context) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
changes addressed in latest commit.
index.js
Outdated
@@ -115,6 +115,11 @@ const runChecks = async (context, checkEvent) => { | |||
checkPullRequestLabelsModule.checkCriticalLabel(context) | |||
); | |||
break; | |||
case constants.staleBuildLabelCheck: | |||
callable.push( | |||
checkPullRequestLabelsModule.checkBuildLabelRemoval(context) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
checkPullRequestLabelsModule.checkBuildLabelRemoval(context) | |
checkPullRequestLabelsModule.checkStaleBuildLabelRemoval(context) | |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
changes addressed in latest commit.
@vojtechjelinek @jameesjohn sir please review this pull request. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, two extra comments.
lib/checkPullRequestLabels.js
Outdated
* | ||
* @param {import('probot').Context} context | ||
*/ | ||
module.exports.checkStaleBuildLabelRemoval = async function (context) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No tests are written for this function.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
added test in latest commit
lib/checkPullRequestLabels.js
Outdated
const {data: lastCommit} = await context.github.repos.getCommit( | ||
context.repo({ | ||
ref: pullRequest.head.sha | ||
}) | ||
); | ||
|
||
const lastCommitDate = new Date(lastCommit.commit.author.date); | ||
// Commit is older than 2 days | ||
if (MIN_BUILD_DATE > lastCommitDate) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since we are making this check at multiple locations, this can be extracted into a utility function that accepts the pull request and context as parameters and returns a boolean value if the commit is older than the minimum build date.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
addressed in latest commit.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
also moved the build check repetative script to utils
lib/checkPullRequestLabels.js
Outdated
* | ||
* @param {import('probot').Context} context | ||
*/ | ||
module.exports.checkStaleBuildLabelRemoval = async function (context) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
added test in latest commit
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! Left a few comments.
lib/checkPullRequestLabels.js
Outdated
* | ||
* @param {import('probot').Context} context | ||
*/ | ||
module.exports.checkStaleBuildLabelRemoval = async function (context) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
module.exports.checkStaleBuildLabelRemoval = async function (context) { | |
module.exports.checkStaleBuildLabelRemoved = async function (context) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
changed function name in latest commit.
lib/checkPullRequestLabels.js
Outdated
/*const {data: lastCommit} = await context.github.repos.getCommit( | ||
context.repo({ | ||
ref: pullRequest.head.sha | ||
}) | ||
);*/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do not keep code that is commented.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes removed commented code.
lib/utils.js
Outdated
const checkBuild = async (pullRequest, context) => { | ||
const {data: lastCommit} = await context.github.repos.getCommit( | ||
context.repo({ | ||
ref: pullRequest.head.sha | ||
}) | ||
); | ||
|
||
const lastCommitDate = new Date(lastCommit.commit.author.date); | ||
// Commit is older than 2 days | ||
return (MIN_BUILD_DATE > lastCommitDate) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const checkBuild = async (pullRequest, context) => { | |
const {data: lastCommit} = await context.github.repos.getCommit( | |
context.repo({ | |
ref: pullRequest.head.sha | |
}) | |
); | |
const lastCommitDate = new Date(lastCommit.commit.author.date); | |
// Commit is older than 2 days | |
return (MIN_BUILD_DATE > lastCommitDate) | |
} | |
const checkPrIsNotStale = async (pullRequest, context) => { | |
const {data: lastCommit} = await context.github.repos.getCommit( | |
context.repo({ | |
ref: pullRequest.head.sha | |
}) | |
); | |
const lastCommitDate = new Date(lastCommit.commit.author.date); | |
// Commit is older than 2 days | |
return (MIN_BUILD_DATE > lastCommitDate) | |
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
indented
lib/checkPullRequestLabels.js
Outdated
}) | ||
);*/ | ||
|
||
// const lastCommitDate = new Date(lastCommit.commit.author.date); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
removed
lib/checkPullRequestLabels.js
Outdated
);*/ | ||
|
||
// const lastCommitDate = new Date(lastCommit.commit.author.date); | ||
// Commit is older than 2 days |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This comment can easily become stale, since the number of days depends on the checkBuild
method.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done sir.
lib/checkPullRequestLabels.js
Outdated
if (checkBuild(pullRequest, context)) { | ||
const commentParams = context.issue({ | ||
body: | ||
'Hi @' + user.login + ', the build of this pr is ' + |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
'Hi @' + user.login + ', the build of this pr is ' + | |
'Hi @' + user.login + ', the build of this PR is ' + |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
addressed in latest commit.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, took another pass.
You can run the tests locally to be sure your changes didn't break a previous implementation.
lib/staleBuildChecks.js
Outdated
// Commit is older than 2 days, this can happen when 'synchronize' event | ||
// got triggered as a result of a merge to the main branch. In this case | ||
// we don't want to remove the label. | ||
if (utils.MIN_BUILD_DATE > lastCommitDate) { | ||
if (utils.checkBuild(pullRequest, context)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's no utils.checkBuild
function.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Extremely sorry sir for such mistake fixing it in latest commit.
lib/staleBuildChecks.js
Outdated
const lastCommitDate = new Date(lastCommit.commit.author.date); | ||
// Commit is older than 2 days | ||
if (utils.MIN_BUILD_DATE > lastCommitDate) { | ||
if (utils.checkBuild(pullRequest, context)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's no utils.checkBuild
function.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Extremely sorry sir for such mistake fixing it in latest commit.
spec/checkPullRequestLabelsSpec.js
Outdated
@@ -22,7 +22,10 @@ const checkCriticalPullRequestModule = | |||
require('../lib/checkCriticalPullRequest'); | |||
const checkPullRequestTemplateModule = | |||
require('../lib/checkPullRequestTemplate'); | |||
const checkStaleBuildLabelRemovedModule = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This module has been imported line 21
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
addressed
spec/checkPullRequestLabelsSpec.js
Outdated
getCommit: jasmine.createSpy('getCommit').and.resolveTo({ | ||
commit: { | ||
author: { | ||
date: '2021-04-12T18:33:45Z' | ||
} | ||
} | ||
}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
getCommit: jasmine.createSpy('getCommit').and.resolveTo({ | |
commit: { | |
author: { | |
date: '2021-04-12T18:33:45Z' | |
} | |
} | |
}) | |
getCommit: jasmine.createSpy('getCommit').and.resolveTo({ | |
data: { | |
commit: { | |
author: { | |
date: '2021-04-12T18:33:45Z' | |
} | |
} | |
} | |
}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, move this spy to the different describe blocks that need it so that you will be able to update the data appropriately
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
addressed.
spec/checkPullRequestLabelsSpec.js
Outdated
beforeEach(async () => { | ||
payloadData.payload.action = 'unlabeled'; | ||
payloadData.payload.label = label; | ||
payloadData.payload.sender.login = 'seanlip'; | ||
spyOn( | ||
checkStaleBuildLabelRemovedModule, 'checkStaleBuildLabelRemoved' | ||
).and.callThrough(); | ||
await robot.receive(payloadData); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mock getCommit here to signify that the pull request has been updated recently.
You can set the commit date to be (new Date).toISOString()
, which will make sure that the commit date will always be more than the minimum date.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do this in every other place that requires it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
addressed in latest commit.
Unassigning @jameesjohn since the review is done. |
@jameesjohn can you please provide a little review over the latest commit as my current changes do not reducing the no of failed tests. also please can you comment on why this pr is experiencing merge conflicts. |
@jameesjohn please review this pr i had tried to bring all the changes suggested by you but still i am receiving test failing you can see log here. one more thing is due to recent merge the specs are not running while |
spec/checkPullRequestLabelsSpec.js
Outdated
getCommit: jasmine.createSpy('getCommit').and.resolveTo({ | ||
data: { | ||
commit: { | ||
author: { | ||
date: '2021-04-12T18:33:45Z' | ||
} | ||
} | ||
} | ||
}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be removed from here and only added to places where it is required.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
spec/checkPullRequestLabelsSpec.js
Outdated
await robot.receive(payloadData); | ||
github = { | ||
issues: { | ||
createComment: jasmine.createSpy('createComment').and.returnValue({}), | ||
addAssignees: jasmine.createSpy('addAssignees').and.resolveTo({}), | ||
removeLabel: jasmine.createSpy('removeLabel').and.resolveTo({}), | ||
addLabels: jasmine.createSpy('addLabels').and.resolveTo({}), | ||
}, | ||
repos: { | ||
getCommit: jasmine.createSpy('getCommit').and.resolveTo({ | ||
lastCommit: { | ||
commit: { | ||
author: { | ||
date: (new Date).toISOString() | ||
} | ||
} | ||
} | ||
}) | ||
} | ||
}; | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
await robot.receive(payloadData); | |
github = { | |
issues: { | |
createComment: jasmine.createSpy('createComment').and.returnValue({}), | |
addAssignees: jasmine.createSpy('addAssignees').and.resolveTo({}), | |
removeLabel: jasmine.createSpy('removeLabel').and.resolveTo({}), | |
addLabels: jasmine.createSpy('addLabels').and.resolveTo({}), | |
}, | |
repos: { | |
getCommit: jasmine.createSpy('getCommit').and.resolveTo({ | |
lastCommit: { | |
commit: { | |
author: { | |
date: (new Date).toISOString() | |
} | |
} | |
} | |
}) | |
} | |
}; | |
}); | |
github.repos.getCommit = jasmine.createSpy('getCommit').and.resolveTo({ | |
data: { | |
commit: { | |
author: { | |
date: '2021-04-12T18:33:45Z' | |
} | |
} | |
} | |
}); | |
await robot.receive(payloadData); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
addressed in latest commit
it('check if pr is stale', () => { | ||
expect(github.repos.getCommit).toHaveBeenCalled(); | ||
expect(github.repos.getCommit).toHaveBeenCalledWith({ | ||
ref: payloadData.payload.pull_request.head.sha |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ref: payloadData.payload.pull_request.head.sha | |
owner: 'oppia', | |
repo: 'oppia', | |
ref: payloadData.payload.pull_request.head.sha |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
addressed
spec/checkPullRequestLabelsSpec.js
Outdated
await robot.receive(payloadData); | ||
github = { | ||
issues: { | ||
createComment: jasmine.createSpy('createComment').and.returnValue({}), | ||
addAssignees: jasmine.createSpy('addAssignees').and.resolveTo({}), | ||
removeLabel: jasmine.createSpy('removeLabel').and.resolveTo({}), | ||
addLabels: jasmine.createSpy('addLabels').and.resolveTo({}), | ||
}, | ||
repos: { | ||
getCommit: jasmine.createSpy('getCommit').and.resolveTo({ | ||
lastCommit: { | ||
commit: { | ||
author: { | ||
date: '2021-04-12T18:33:45Z' | ||
} | ||
} | ||
} | ||
}) | ||
} | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
await robot.receive(payloadData); | |
github = { | |
issues: { | |
createComment: jasmine.createSpy('createComment').and.returnValue({}), | |
addAssignees: jasmine.createSpy('addAssignees').and.resolveTo({}), | |
removeLabel: jasmine.createSpy('removeLabel').and.resolveTo({}), | |
addLabels: jasmine.createSpy('addLabels').and.resolveTo({}), | |
}, | |
repos: { | |
getCommit: jasmine.createSpy('getCommit').and.resolveTo({ | |
lastCommit: { | |
commit: { | |
author: { | |
date: '2021-04-12T18:33:45Z' | |
} | |
} | |
} | |
}) | |
} | |
}; | |
github.repos.getCommit = jasmine.createSpy('getCommit').and.resolveTo({ | |
data: { | |
commit: { | |
author: { | |
date: (new Date).toString() | |
} | |
} | |
} | |
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
addressed
spec/checkPullRequestLabelsSpec.js
Outdated
expect(github.repos.getCommit).toHaveBeenCalledWith({ | ||
ref: payloadData.payload.pull_request.head.sha | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
expect(github.repos.getCommit).toHaveBeenCalledWith({ | |
ref: payloadData.payload.pull_request.head.sha | |
}); | |
expect(github.repos.getCommit).toHaveBeenCalledWith({ | |
repo: 'oppia', | |
owner: 'oppia', | |
ref: payloadData.payload.pull_request.head.sha | |
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
addressed
Unassigning @jameesjohn since the review is done. |
Hi @nlok5923, it looks like some changes were requested on this pull request by @jameesjohn. PTAL. Thanks! |
@jameesjohn thanks for guidance now all checks are passing. |
Fixes: #225
Explanation
Added script to add stale build label if it was removed from PR before updating the pr.
Checklist