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

Periodic Checks #119

Merged
merged 21 commits into from
Sep 2, 2020
Merged

Periodic Checks #119

merged 21 commits into from
Sep 2, 2020

Conversation

jameesjohn
Copy link
Contributor

Explanation

Setup periodic checks to be carried out by oppiabot.

Checklist

Copy link
Contributor

@ankita240796 ankita240796 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Took a first pass, PTAL @jameesjohn!

index.js Outdated
break;
}
}
}
}
}
};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Revert.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

index.js Show resolved Hide resolved
lib/utils.js Outdated
q:
'repo:' +
context.payload.repository.full_name +
' review:approved ' +
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change to constant.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

lib/utils.js Outdated
const searchResult = await context.github.search.issuesAndPullRequests(
context.repo({
q:
'repo:' +
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

lib/utils.js Outdated
const searchResult = await context.github.search.issuesAndPullRequests(
context.repo({
q:
'repo:' +
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

* @param {import('probot').Context} context
* @param {import('probot').Octokit.PullsGetResponse} pullRequest
*/
const handleApproval = async (context, pullRequest) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am a bit confused - what is the purpose here - don't we have a similar method in #116 as well?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar, yes. But that in #116, the function is called after a pull request gets approved.
This is function is called when oppiabot goes through all pull requests and finds that one has been approved but has no assignee.

* 5. Ping appropriate assignee.
* @param {import('probot').Context} context
*/
const ensurePullRequestIsAssigned = async (context) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we do one other thing here - log the assignees/reviewers who haven't responded within 24 hours of being assigned?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think I understand what you mean by logging the assignees

* This function ensures that a pull request is assigned.
* 1. Fetch all pull requests.
* 2. Filter out those without assignees.
* 3. Find out appropriate assignee.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How do we find out - explain.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added.

await pingAndAssignReviewers(context, pullRequestData);
} else if (hasChangesRequested) {
console.log('PULL REQUEST HAS CHANGES REQUESTED...');
await assignPrAuthor(context, pullRequestData);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not pingAndAssignAuthor? Pass the comment to the function if it is different for different usecases.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

Comment on lines 190 to 197
console.log('CONFUSED STATE, ASK FOR HELP FROM WELFARE TEAM...');
context.github.issues.createComment(
context.repo({
issue_number: pullRequestData.number,
body:
'Hi @' +
teamLeads.welfareTeam +
', this pull request needs some assistance, PTAL. Thanks!',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, how is this decided, I did not see this in the pull request review doc.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While implementing this, I noticed that there would be an empty else case, although that is highly improbable, I decided to add it.
I also updated the review doc with this change.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let us ping core-maintainers here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

Copy link
Contributor

@ankita240796 ankita240796 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few high level comments, PTAL. Thanks @jameesjohn

index.js Show resolved Hide resolved
index.js Show resolved Hide resolved
lib/periodicChecks.js Show resolved Hide resolved
Comment on lines 53 to 95
const pingAndAssignReviewers = async (context, pullRequest) => {
const reviewers = pullRequest.requested_reviewers.map(
(reviewer) => reviewer.login
);

context.github.issues.addAssignees(
context.repo({
issue_number: pullRequest.number,
assignees: reviewers,
})
);

context.github.issues.createComment(
context.repo({
issue_number: pullRequest.number,
body:
'Assigning @' +
reviewers.join(', @') +
' for codeowner reviews. Thanks!',
})
);
};

/**
* This function assigns the PR author to a pull request.
* @param {import('probot').Context} context
* @param {import('probot').Octokit.PullsGetResponse} pullRequest
* @param {string} comment
*/
const pingAndAssignPrAuthor = async (context, pullRequest, comment) => {
context.github.issues.addAssignees(
context.repo({
issue_number: pullRequest.number,
assignees: [pullRequest.user.login],
})
);
await context.github.issues.createComment(
context.repo({
issue_number: pullRequest.number,
body: comment,
})
);
};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My one concern with all this is aren't we doing similar tasks in #116, shouldn't we reuse the common functions?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, we are doing something similar there.
We can't reuse the function since #116 has not been merged.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function is still valuable after merging #116.

* @param {import('probot').Context} context
* @param {import('probot').Octokit.PullsGetResponse} pullRequest
*/
const handleApprovedPR = async (context, pullRequest) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is exactly similar to the function in pr reviewed module - why not import that and use the function directly?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Modified to use that in the pr reviewed module.

lib/periodicChecks.js Outdated Show resolved Hide resolved
Copy link
Contributor

@ankita240796 ankita240796 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another note - we also plan to have a periodic check to ensure that all issues have a project added to them, are you planning to that in a separate PR?

@oppiabot
Copy link

oppiabot bot commented Aug 28, 2020

Hi @jameesjohn. Due to recent changes in the "develop" branch, this PR now has a merge conflict. Please follow this link if you need help resolving the conflict, so that the PR can be merged. Thanks!

// Assign project owner to merge the pull request.
// A pull request will always have a changelog label because we are
// assigning the PR author to the pull request if it is created without
// changelog label.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove extra space before changelog. Also, have we matched the comments with the ones in this section: https://docs.google.com/document/d/1m-7dZWGw77hZ6GOnjBu4p1XGXxyBPY2n2pzf-76RuTY/edit?ts=5f240b85#heading=h.66ts492p306d

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

lib/checkPullRequestReview.js Outdated Show resolved Hide resolved
Comment on lines 190 to 197
console.log('CONFUSED STATE, ASK FOR HELP FROM WELFARE TEAM...');
context.github.issues.createComment(
context.repo({
issue_number: pullRequestData.number,
body:
'Hi @' +
teamLeads.welfareTeam +
', this pull request needs some assistance, PTAL. Thanks!',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let us ping core-maintainers here.

lib/periodicChecks.js Outdated Show resolved Hide resolved
@jameesjohn
Copy link
Contributor Author

The ensureIssueHasProjects feature has been tested at jameesjohn/comment-on-pr#35, jameesjohn/comment-on-pr#34, jameesjohn/comment-on-pr#29, jameesjohn/comment-on-pr#10.

context
);
break;
case constants.periodicCheck:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ensurePullRequestIsAssigned -> ensureAllPullRequestsAreAssigned

ensureIssueHasProjects -> ensureAllIssuesHaveProjects

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

index.js Outdated
Comment on lines 162 to 163
// interval: 24 * 60 * 60 * 1000, // 1 day
interval: 60 * 0.5 * 1000
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Revert

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

lib/periodicChecks.js Show resolved Hide resolved
Comment on lines 169 to 176
// Add Todo triage label if not already added in a previous iteration.
if (!labels.includes(TODO_TRIAGE_LABEL)) {
context.github.issues.addLabels(
context.repo({
issue_number: issue.number,
labels: [TODO_TRIAGE_LABEL],
})
);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can remove this as discussed.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The approach looks good otherwise!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated.

@oppiabot
Copy link

oppiabot bot commented Sep 1, 2020

Hi @jameesjohn. Due to recent changes in the "develop" branch, this PR now has a merge conflict. Please follow this link if you need help resolving the conflict, so that the PR can be merged. Thanks!

@@ -16,6 +16,7 @@
* @fileoverview File to handle checks when a PR gets reviewed.
*/
const utilityModule = require('./utils');
const { pingAndAssignReviewers } = require('./utils');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can directly use utilityModule. pingAndAssignReviewers. It is already imported.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

lib/utils.js Outdated
* @param {import('probot').Octokit.PullsGetResponse} pullRequest
* @param {string[]} reviewers
*/
const pingAndAssignReviewers = async (context, pullRequest, reviewers) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not here itself? Would prevent any extra follow ups since this is the last PR for your M3.

* - If pull request has pending reviews -- Remaining reviewers.
* - If pull request has changes requested -- PR author.
* - If pull request has been approved -- Any member of the Organisation.
* - If none of the above cases -- Welfare team lead.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Onboarding team lead

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

* - If pull request has a merge conflict -- PR author.
* - If pull request has pending reviews -- Remaining reviewers.
* - If pull request has changes requested -- PR author.
* - If pull request has been approved -- Any member of the Organisation.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Project owner, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Project owner or PR author.

pullRequestData
);
} else {
console.log('CONFUSED STATE, ASK FOR HELP FROM WELFARE TEAM...');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ONBOARDING TEAM

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated.

* This function ensures that all issue are linked to a project.
* 1. Fetch all open issues.
* 2. Fetch all project cards.
* 3. Filter open issues by the ones that have the triage label.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Update comment - we are not using triage label.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

Comment on lines 168 to 180
const labels = issue.labels.map((label) => label.name);
if (labels.includes(TODO_TRIAGE_LABEL)) {
// If label has already been added we do nothing since we have already
// pinged the core maintainers.
return;
}
// Add Todo triage label.
context.github.issues.addLabels(
context.repo({
issue_number: issue.number,
labels: [TODO_TRIAGE_LABEL],
})
);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should not do any of this - just check for project and ping. The label is for project leads to assign a priority to the issue.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Noted.
Removed.

lib/utils.js Outdated

// Pull requests are also returned from the api, hence we need to filter
// them out.
return openIssues.filter((issue) => 'pull_request' in issue === false);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pull_request -> constant.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

* @param {import('probot').Context} context
*/
const getAllProjectCards = async (context) => {
const { data: allProjects } = await context.github.projects.listForRepo(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please make sure line lengths are correct, throughout the PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes.
This has 75 chars.

Copy link
Contributor

@ankita240796 ankita240796 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Final comments - thanks for doing this so patiently @jameesjohn!

);
} else if (hasPendingReviews(pullRequestData)) {
console.log('PULL REQUEST HAS PENDING REVIEWS...');
const reviewers = pullRequest.requested_reviewers.map(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just one nit - can we skip assigning users who are already assigned?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All the checks here are running when no one is assigned.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah ok, yes missed that.

);
} else if (hasChangesRequested) {
console.log('PULL REQUEST HAS CHANGES REQUESTED...');
const review = await getLastReviewOfType(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wasn't this function renamed to getLastReviewOfSpecificType?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. Apparently the refactor functionality in VSCode played a trick here.
I'll update it manually.

Comment on lines 153 to 154
* 4. Get Remaining issues
* 5. Ping core maintainers
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Full stop in end.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

});
});

it('should assign project owner', () => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should not assign author case.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@jameesjohn jameesjohn assigned ankita240796 and unassigned jameesjohn Sep 1, 2020
Copy link
Contributor

@ankita240796 ankita240796 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, Thanks @jameesjohn!

);
} else if (hasPendingReviews(pullRequestData)) {
console.log('PULL REQUEST HAS PENDING REVIEWS...');
const reviewers = pullRequest.requested_reviewers.map(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah ok, yes missed that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants