Skip to content
Merged
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
83 changes: 83 additions & 0 deletions .github/workflows/review.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
name: Pull request reviews

on:
pull_request_review:
types: [submitted]

jobs:
check-author:
if: github.event.review.state == 'approved'
runs-on: ubuntu-latest
permissions:
pull-requests: write
contents: read
issues: write
steps:
- name: Check if PR author is a contributor
uses: actions/github-script@v7
with:
script: |
const { pull_request, review } = context.payload;
const { owner, repo } = context.repo;

const author = pull_request.user.login;
const reviewer = review.user.login;

if (reviewer === author) {
core.info("Author reviewed their own pull request, skipping.");
return;
}

const getPermissionLevel = async (username) => {
const { data } = await github.rest.repos.getCollaboratorPermissionLevel({
username,
owner,
repo,
});

return data.permission;
};

const isMaintainer = async (username) =>
["maintain", "admin"].includes(await getPermissionLevel(username));

const isContributor = async (username) =>
["write", "maintain", "admin"].includes(await getPermissionLevel(username));

if (await isContributor(author)) {
core.info(`Author @${author} already has write access.`);
return;
}

if (!await isMaintainer(reviewer)) {
core.info(`Reviewer @${reviewer} is not a maintainer.`);
return;
}

const comments = await github.paginate(github.rest.issues.listComments, {
issue_number: pull_request.number,
per_page: 100,
owner,
repo,
});

const nudgeMarker = "<!-- @jj-vcs/contributors nudge -->";

if (comments.some(c => (c.body || "").includes(nudgeMarker))) {
core.info("Reviewer has already been nudged.");
return;
};

const body = `Hey @${reviewer}! Thanks for the approval. Please `
+ `make sure to add ${author} to jj-vcs/contributors so they `
+ "can merge their pull request. Feel free to also drop a note "
+ "in Discord so they can get their contributor role. Thanks!";

await github.rest.issues.createComment({
issue_number: pull_request.number,
body: nudgeMarker + body,
owner,
repo,
});

core.notice(`Pinged ${reviewer} to add ${author} to jj-vcs/contributors.`);