From 4f1cf2d70dfbe41c3676aef3dd2572abd8ed7753 Mon Sep 17 00:00:00 2001 From: Lee Dohm <1038121+lee-dohm@users.noreply.github.com> Date: Thu, 26 Aug 2021 11:33:55 -0700 Subject: [PATCH 1/8] Create workflow to post comment when a PR is opened without maintainer edit access --- .../notify-when-maintainers-cannot-edit.yaml | 61 +++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 .github/workflows/notify-when-maintainers-cannot-edit.yaml diff --git a/.github/workflows/notify-when-maintainers-cannot-edit.yaml b/.github/workflows/notify-when-maintainers-cannot-edit.yaml new file mode 100644 index 0000000000..403cef1794 --- /dev/null +++ b/.github/workflows/notify-when-maintainers-cannot-edit.yaml @@ -0,0 +1,61 @@ +name: Notify When Maintainers Cannot Edit + +# **What it does**: Notifies the author of a PR when their PR does not allow maintainers to edit it. +# **Why we have it**: To prevent having to do this manually. +# **Who does it impact**: Open-source. + +on: + pull_request: + types: + - opened + +jobs: + notify-when-maintainers-cannot-edit: + if: github.repository == 'github/docs' + runs-on: ubuntu-latest + steps: + - uses: actions/github-script@2b34a689ec86a68d8ab9478298f91d5401337b7d + with: + script: | + const query = ` + query($number: Int!) { + repository(owner: "github", name: "docs") { + pullRequest(number: $number) { + headRepositoryOwner { + login + } + maintainerCanModify + } + } + } + `; + + const pullNumber = context.issues.number; + const variables = { number: pullNumber }; + + try { + console.log(`Check github/docs#${pullNumber} for maintainer edit access ...`); + const result = await github.graphql(query, variables); + + console.log(JSON.stringify(result, null, 2)); + + const pullRequest = result.data.repository.pullRequest; + + if (pullRequest.headRepositoryOwner.login == 'github') { + console.log('PR owned by github'); + return; + } + + if (!pullRequest.maintainerCanModify) { + console.log('PR not owned by github and does not have maintainer edits enabled'); + + await github.issues.createComment({ + issue_number: pullNumber, + owner: 'github', + repo: 'docs', + body: "Thanks for submitting a PR to the GitHub Docs project!\n\nIn order to review and merge PRs most efficiently, we require that all PRs grant maintainer edit access before we review them. For more information about this, [check the contribution guide](https://github.com/github/docs/blob/main/CONTRIBUTING.md)." + }); + } + } catch(e) { + console.log(error); + } From 4a067f14672449088134a1f035f7ff230524cf14 Mon Sep 17 00:00:00 2001 From: Lee Dohm <1038121+lee-dohm@users.noreply.github.com> Date: Mon, 11 Oct 2021 13:29:04 -0700 Subject: [PATCH 2/8] Point to docs on how to change setting --- .github/workflows/notify-when-maintainers-cannot-edit.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/notify-when-maintainers-cannot-edit.yaml b/.github/workflows/notify-when-maintainers-cannot-edit.yaml index 403cef1794..06e7e5f6a8 100644 --- a/.github/workflows/notify-when-maintainers-cannot-edit.yaml +++ b/.github/workflows/notify-when-maintainers-cannot-edit.yaml @@ -53,7 +53,7 @@ jobs: issue_number: pullNumber, owner: 'github', repo: 'docs', - body: "Thanks for submitting a PR to the GitHub Docs project!\n\nIn order to review and merge PRs most efficiently, we require that all PRs grant maintainer edit access before we review them. For more information about this, [check the contribution guide](https://github.com/github/docs/blob/main/CONTRIBUTING.md)." + body: "Thanks for submitting a PR to the GitHub Docs project!\n\nIn order to review and merge PRs most efficiently, we require that all PRs grant maintainer edit access before we review them. For information on how to do this, [see the documentation](https://docs.github.com/en/github/collaborating-with-pull-requests/working-with-forks/allowing-changes-to-a-pull-request-branch-created-from-a-fork)." }); } } catch(e) { From 6684ac0451ec36e525ec91627d9459ebf3e85155 Mon Sep 17 00:00:00 2001 From: Lee Dohm <1038121+lee-dohm@users.noreply.github.com> Date: Mon, 11 Oct 2021 13:36:23 -0700 Subject: [PATCH 3/8] Add pull request write permission specifier --- .github/workflows/notify-when-maintainers-cannot-edit.yaml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/notify-when-maintainers-cannot-edit.yaml b/.github/workflows/notify-when-maintainers-cannot-edit.yaml index 06e7e5f6a8..55f4abf830 100644 --- a/.github/workflows/notify-when-maintainers-cannot-edit.yaml +++ b/.github/workflows/notify-when-maintainers-cannot-edit.yaml @@ -9,6 +9,9 @@ on: types: - opened +permissions: + pull-requests: write + jobs: notify-when-maintainers-cannot-edit: if: github.repository == 'github/docs' From 04e051ae220c80e60c83ab7380a20cf4d919698f Mon Sep 17 00:00:00 2001 From: Lee Dohm <1038121+lee-dohm@users.noreply.github.com> Date: Tue, 12 Oct 2021 10:40:44 -0700 Subject: [PATCH 4/8] Fix mismatched error variable name --- .github/workflows/notify-when-maintainers-cannot-edit.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/notify-when-maintainers-cannot-edit.yaml b/.github/workflows/notify-when-maintainers-cannot-edit.yaml index 55f4abf830..b3b84686ee 100644 --- a/.github/workflows/notify-when-maintainers-cannot-edit.yaml +++ b/.github/workflows/notify-when-maintainers-cannot-edit.yaml @@ -60,5 +60,5 @@ jobs: }); } } catch(e) { - console.log(error); + console.log(e); } From dcac2615766ab86db53e57d81022f3d793104244 Mon Sep 17 00:00:00 2001 From: Lee Dohm <1038121+lee-dohm@users.noreply.github.com> Date: Tue, 12 Oct 2021 10:41:19 -0700 Subject: [PATCH 5/8] Use strict equality matching --- .github/workflows/notify-when-maintainers-cannot-edit.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/notify-when-maintainers-cannot-edit.yaml b/.github/workflows/notify-when-maintainers-cannot-edit.yaml index b3b84686ee..988bf1524e 100644 --- a/.github/workflows/notify-when-maintainers-cannot-edit.yaml +++ b/.github/workflows/notify-when-maintainers-cannot-edit.yaml @@ -44,7 +44,7 @@ jobs: const pullRequest = result.data.repository.pullRequest; - if (pullRequest.headRepositoryOwner.login == 'github') { + if (pullRequest.headRepositoryOwner.login === 'github') { console.log('PR owned by github'); return; } From 4cc2a76776b20398708a67e7bf31fd2c6beecf93 Mon Sep 17 00:00:00 2001 From: Lee Dohm <1038121+lee-dohm@users.noreply.github.com> Date: Tue, 12 Oct 2021 12:30:02 -0700 Subject: [PATCH 6/8] Fix incorrect specifier Co-authored-by: Robert Sese --- .github/workflows/notify-when-maintainers-cannot-edit.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/notify-when-maintainers-cannot-edit.yaml b/.github/workflows/notify-when-maintainers-cannot-edit.yaml index 988bf1524e..77b85f8505 100644 --- a/.github/workflows/notify-when-maintainers-cannot-edit.yaml +++ b/.github/workflows/notify-when-maintainers-cannot-edit.yaml @@ -33,7 +33,7 @@ jobs: } `; - const pullNumber = context.issues.number; + const pullNumber = context.issue.number; const variables = { number: pullNumber }; try { From 93a11c32eb61895df8e14132ec1cef78b26180cb Mon Sep 17 00:00:00 2001 From: Lee Dohm <1038121+lee-dohm@users.noreply.github.com> Date: Tue, 12 Oct 2021 12:40:20 -0700 Subject: [PATCH 7/8] Remove unnecessary data specifier --- .github/workflows/notify-when-maintainers-cannot-edit.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/notify-when-maintainers-cannot-edit.yaml b/.github/workflows/notify-when-maintainers-cannot-edit.yaml index 77b85f8505..9ad2328f9b 100644 --- a/.github/workflows/notify-when-maintainers-cannot-edit.yaml +++ b/.github/workflows/notify-when-maintainers-cannot-edit.yaml @@ -42,7 +42,7 @@ jobs: console.log(JSON.stringify(result, null, 2)); - const pullRequest = result.data.repository.pullRequest; + const pullRequest = result.repository.pullRequest; if (pullRequest.headRepositoryOwner.login === 'github') { console.log('PR owned by github'); From 58b6af7ebc41c60109c4e9ba61d971eb89d0a42d Mon Sep 17 00:00:00 2001 From: Lee Dohm <1038121+lee-dohm@users.noreply.github.com> Date: Tue, 12 Oct 2021 12:49:43 -0700 Subject: [PATCH 8/8] Use pull_request_target trigger --- .github/workflows/notify-when-maintainers-cannot-edit.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/notify-when-maintainers-cannot-edit.yaml b/.github/workflows/notify-when-maintainers-cannot-edit.yaml index 9ad2328f9b..85edabb89b 100644 --- a/.github/workflows/notify-when-maintainers-cannot-edit.yaml +++ b/.github/workflows/notify-when-maintainers-cannot-edit.yaml @@ -5,7 +5,7 @@ name: Notify When Maintainers Cannot Edit # **Who does it impact**: Open-source. on: - pull_request: + pull_request_target: types: - opened