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

repo sync #9001

Merged
merged 2 commits into from
Aug 12, 2021
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
72 changes: 20 additions & 52 deletions .github/workflows/triage-unallowed-contributions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,28 +29,6 @@ jobs:
if: github.repository == 'github/docs' && github.event.pull_request.user.login != 'Octomerger'
runs-on: ubuntu-latest
steps:
- name: Check for existing requested changes
id: requested-change
uses: actions/github-script@2b34a689ec86a68d8ab9478298f91d5401337b7d
with:
github-token: ${{secrets.GITHUB_TOKEN}}
result-encoding: json
script: |
const pullReviews = await github.pulls.listReviews({
...context.repo,
pull_number: context.payload.number
})

const botReviews = pullReviews.data
.filter(review => review.user.login === 'github-actions[bot]')
.sort((a, b) => new Date(b.submitted_at) - new Date(a.submitted_at))
.shift()

if (botReviews) {
console.log(`Pull request reviews authored by the github-action bot: ${botReviews}`)
}
return botReviews

- name: Get files changed
uses: dorny/paths-filter@eb75a1edc117d3756a18ef89958ee59f9500ba58
id: filter
Expand Down Expand Up @@ -86,11 +64,10 @@ jobs:
- 'scripts/**'
- 'translations/**'

# When there are changes to files we can't accept
# and no review exists,leave a REQUEST_CHANGES review
- name: Request pull request changes
# Check for no reviews or reviews that aren't CHANGES_REQUESTED
if: ${{ steps.filter.outputs.notAllowed == 'true' && (!steps.requested-change.outputs.result || fromJSON(steps.requested-change.outputs.result).state != 'CHANGES_REQUESTED') }}
# When there are changes to files we can't accept, leave a comment
# explaining this to the PR author
- name: "Comment about changes we can't accept"
if: ${{ steps.filter.outputs.notAllowed }}
uses: actions/github-script@2b34a689ec86a68d8ab9478298f91d5401337b7d
with:
github-token: ${{secrets.GITHUB_TOKEN}}
Expand All @@ -109,36 +86,27 @@ jobs:
'lib/webhooks/**',
'lib/search/indexes/**',
'package*.json',
'Procfile'
'Procfile',
'scripts/**',
'translations/**'
'translations/**',
]

const badFiles = badFilesArr.join('\n')

let reviewMessage = `👋 Hey there spelunker. It looks like you've modified some files that we can't accept as contributions. The complete list of files we can't accept are:\n${badFiles}\n\nYou'll need to revert all of the files you changed in that list using [GitHub Desktop](https://docs.github.com/en/free-pro-team@latest/desktop/contributing-and-collaborating-using-github-desktop/managing-commits/reverting-a-commit) or \`git checkout origin/main <file name>\`. Once you get those files reverted, we can continue with the review process. :octocat:`
let workflowFailMessage = "It looks like you've modified some files that we can't accept as contributions."

await github.pulls.createReview({
...context.repo,
pull_number: context.payload.number,
body: reviewMessage,
event: 'REQUEST_CHANGES'
})
try {
createdComment = await github.issues.createComment ({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.payload.number,
body: reviewMessage,
})

core.setFailed("It looks like you've modified some files we don't accept contributions for. Please see the review with requested changes for details.")
# When the most recent review was CHANGES_REQUESTED and the existing
# PR no longer contains unallowed changes, dismiss the previous review
- name: Dismiss pull request review
# Check that unallowed files aren't modified and that a
# CHANGES_REQUESTED review already exists
if: ${{ steps.filter.outputs.notAllowed == 'false' && steps.requested-change.outputs.result && fromJSON(steps.requested-change.outputs.result).state == 'CHANGES_REQUESTED' }}
uses: actions/github-script@2b34a689ec86a68d8ab9478298f91d5401337b7d
with:
github-token: ${{secrets.GITHUB_TOKEN}}
script: |
await github.pulls.dismissReview({
...context.repo,
pull_number: context.payload.number,
review_id: ${{fromJSON(steps.requested-change.outputs.result).id}},
message: `✨Looks like you reverted all files we don't accept contributions for. 🙌 A member of the docs team will review your PR soon. 🚂`
})
workflowFailMessage = `${workflowFailMessage} Please see ${createdComment.data.html_url} for details.`
} catch(err) {
console.log("Error creating comment.", err)
}

core.setFailed(workflowFailMessage)