Skip to content

Commit

Permalink
Adds support for fallback accounts on PRs
Browse files Browse the repository at this point in the history
  • Loading branch information
orta committed Jul 1, 2021
1 parent 942ca5e commit 18884f8
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 2 deletions.
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ packages/documentation/copy/es/**/*.ts @KingDarBoja [translate] [es]

## Config

There are only two options available at the moment:
There are four options available at the moment:

- `cwd`, which can be used to determine the root folder to look for CODEOWNER files in.
- `merge_method`, which can be `merge` (default), `squash` or `rebase`, depending on what you want the action to do.
Expand All @@ -89,6 +89,11 @@ There are only two options available at the moment:
merge_method: 'squash'
```

Then 2 for handling fallbacks on PRs which aren't able to be maintained by anyone in the CODEOWNERs:

- `if_no_maintainers_add_label` - A label to add which denotes it is a maintainers PR to handle
- `if_no_maintainers_assign` - A string of `@` prefixed GitHub usernames, separated by spaces which denotes who should be assigned to PRs which don't get a CODEOWNER.

### Dev

Use `npx jest --watch` to run tests.
Expand Down
13 changes: 13 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,22 @@ inputs:
cwd:
description: 'The path to the root folder where it should look for code owners'
default: ''
required: false

merge_method:
description: "The merge strategy to use: 'merge', 'squash' or 'rebase'"
default: 'merge'
required: false

if_no_maintainers_add_label:
description: "If a PR does not have any community maintainers, apply this label"
default: ''
required: false

if_no_maintainers_assign:
description: 'If a PR does not have any community maintainers, assign these people (e.g. "@orta @sandersn")'
default: ''
required: false

runs:
using: 'node12'
Expand Down
13 changes: 13 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,19 @@ async function commentOnMergablePRs() {
if (!ownersWhoHaveAccessToAllFilesInPR.length) {
console.log("This PR does not have any code-owners who own all of the files in the PR")
listFilesWithOwners(changedFiles, cwd)

const labelToAdd = core.getInput('if_no_maintainers_add_label')
if (labelToAdd) {
const labelConfig = { name: labelToAdd, color: Math.random().toString(16).slice(2, 8) }
await createOrAddLabel(octokit, thisRepo, labelConfig)
}

const assignees = core.getInput('if_no_maintainers_assign')
if (assignees) {
const usernames = assignees.split(" ").map(u => u.replace("@", "").trim())
await octokit.issues.addAssignees({ ...thisRepo, issue_number: pr.number, assignees: usernames})
}

process.exit(0)
}

Expand Down
1 change: 0 additions & 1 deletion index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,3 @@ test("deciding if someone has access to merge", () => {
expect(filesNotInCodeowners).toEqual(["random-path/file.ts"]);
});


0 comments on commit 18884f8

Please sign in to comment.