Skip to content

Commit 1fab56b

Browse files
subatoiCopilotCopilot
authored
Add more guardrails for low-value PRs (#62947)
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
1 parent 95b6334 commit 1fab56b

3 files changed

Lines changed: 18 additions & 7 deletions

File tree

.github/workflows/triage-unallowed-contributions.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,13 @@ jobs:
4040
filters: 'src/workflows/unallowed-contribution-filters.yml'
4141

4242
- name: Set up Node and dependencies
43-
if: ${{ steps.filter.outputs.notAllowed || steps.filter.outputs.contentTypes}}
43+
if: ${{ steps.filter.outputs.notAllowed == 'true' || steps.filter.outputs.contentTypes == 'true' }}
4444
uses: ./.github/actions/node-npm-setup
4545

4646
# When there are changes to files we can't accept, leave a comment
47-
# explaining this to the PR author
47+
# explaining this to the PR author, and why their PR will close
4848
- name: "Comment about changes we can't accept"
49-
if: ${{ steps.filter.outputs.notAllowed || steps.filter.outputs.contentTypes}}
49+
if: ${{ steps.filter.outputs.notAllowed == 'true' || steps.filter.outputs.contentTypes == 'true' }}
5050
run: npm run unallowed-contributions
5151
env:
5252
REPO_OWNER_AND_NAME: ${{ github.repository }}

src/workflows/unallowed-contribution-filters.yml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
notAllowed:
2+
- '*'
23
- '.devcontainer/**'
34
- '.github/**'
45
- 'data/reusables/rai/**'
5-
- 'Dockerfile*'
66
- 'src/**'
7-
- 'package*.json'
8-
- 'content/actions/how-tos/security-for-github-actions/security-hardening-your-deployments/**'
7+
- 'content/actions/how-tos/secure-your-work/security-harden-deployments/**'
98
contentTypes:
109
- 'content/**'
1110
# allows getting a list of just added files from the dorny/paths-filter action

src/workflows/unallowed-contributions.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,24 @@ async function main() {
4646
const listUnallowedChangedFiles = unallowedChangedFiles.map((file) => `\n - ${file}`).join('')
4747
const listUnallowedFiles = filters.notAllowed.map((file: string) => `\n - ${file}`).join('')
4848

49-
const reviewMessage = `👋 Hey there spelunker. It looks like you've modified some files that we can't accept as contributions:${listUnallowedChangedFiles}\n\nYou'll need to revert all of the files you changed that match 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-in-github-desktop) or \`git checkout origin/main <file name>\`. Once you get those files reverted, we can continue with the review process. :octocat:\n\nThe complete list of files we can't accept are:${listUnallowedFiles}\n\nWe also can't accept contributions to files in the content directory with frontmatter \`contentType: rai\`.`
49+
const reviewMessage = `👋 Hi there! It looks like you've modified some files that we can't accept as contributions:${listUnallowedChangedFiles}\n\nYou'll need to raise a new PR that doesn't include those files, before we can review.\n\nThe complete list of files we can't accept are:${listUnallowedFiles}\n\nWe also can't accept contributions to files in the content directory with frontmatter \`contentType: rai\`. You can always check out our full [contribution guidelines](https://docs.github.com/en/contributing).`
5050

5151
let workflowFailMessage =
5252
"It looks like you've modified some files that we can't accept as contributions."
5353
let createdComment
5454

55+
// Add the `invalid` label so the PR gets closed
56+
try {
57+
await octokit.rest.issues.addLabels({
58+
owner,
59+
repo,
60+
issue_number: Number(PR_NUMBER || ''),
61+
labels: ['invalid'],
62+
})
63+
} catch (err) {
64+
console.log('Error adding the `invalid` label.', err)
65+
}
66+
5567
try {
5668
createdComment = await octokit.rest.issues.createComment({
5769
owner,

0 commit comments

Comments
 (0)