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] 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); + }