-
Notifications
You must be signed in to change notification settings - Fork 76
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ci(pr-bot): add write permissions for pull requests (#7517)
**Related Issue:** #7510 ## Summary Adds pull request write permission to the pr-bot so it doesn't fail for people who don't have write permissions --------- Co-authored-by: Calcite Admin <calcite-admin@esri.com> Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com> Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> Co-authored-by: JC Franco <jfranco@esri.com> Co-authored-by: Matt Driscoll <mdriscoll@esri.com>
- Loading branch information
1 parent
7e40a34
commit 07baeef
Showing
3 changed files
with
87 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
module.exports = async ({ github, context }) => { | ||
const { | ||
assignees, | ||
number, | ||
user: { login: author }, | ||
} = context.payload.pull_request; | ||
|
||
const updatedAssignees = | ||
assignees && assignees.length | ||
? [...assignees.map((a) => a.login).filter((a) => a !== author), author] | ||
: [author]; | ||
|
||
try { | ||
await github.rest.issues.addAssignees({ | ||
owner: context.repo.owner, | ||
repo: context.repo.repo, | ||
issue_number: number, | ||
assignees: updatedAssignees, | ||
}); | ||
} catch (e) { | ||
console.error( | ||
"Unable to assign the PR author, they likely do not have write permissions\n", | ||
e, | ||
); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
module.exports = async ({ github, context }) => { | ||
const { title, number } = context.payload.pull_request; | ||
|
||
const conventionalCommitRegex = | ||
/^(build|chore|ci|docs|feat|fix|perf|refactor|revert|style|test)(\([\w ,-]+\))?(!?:\s+)([\w ]+[\s\S]*)/i; | ||
|
||
if (!title) { | ||
console.log("No title found, ending run."); | ||
return; | ||
} | ||
|
||
const match = title.match(conventionalCommitRegex); | ||
|
||
if (!match || match.length < 2) { | ||
console.log("Title does not match conventional commit regex, ending run."); | ||
return; | ||
} | ||
|
||
// commit type is in the first match group | ||
const typeLabel = getLabelName(match[1]); | ||
|
||
try { | ||
await github.rest.issues.addLabels({ | ||
issue_number: number, | ||
owner: context.repo.owner, | ||
repo: context.repo.repo, | ||
labels: [typeLabel], | ||
}); | ||
} catch (e) { | ||
console.error("Unable to label pull request, the author likely does not have write permissions\n", e); | ||
} | ||
}; | ||
|
||
function getLabelName(type) { | ||
switch (type) { | ||
case "feat": | ||
return "enhancement"; | ||
case "fix": | ||
return "bug"; | ||
case "docs": | ||
return "docs"; | ||
case "test": | ||
return "testing"; | ||
case "refactor": | ||
return "refactor"; | ||
case "tooling": | ||
return "tooling"; | ||
default: | ||
return "chore"; | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters