-
-
Notifications
You must be signed in to change notification settings - Fork 4.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from sugatoray/main
- Loading branch information
Showing
11 changed files
with
170 additions
and
545 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
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,51 @@ | ||
# Automated Review Labels | ||
|
||
These diagrams explain the workflow of the automated review labels actions. | ||
|
||
## Workflow | ||
|
||
```mermaid | ||
sequenceDiagram | ||
actor User | ||
participant issue | ||
participant GitHub actions | ||
actor Authenticated bot | ||
actor Reviewer | ||
Note right of Authenticated bot: Authenticated bot is a GitHub action with the necessary rights for getMembershipForUserInOrg | ||
User->>issue: Adds any comment | ||
activate GitHub actions | ||
alt is PR AND no review-requested label exists | ||
loop Over ['@conda-forge/staged-recipes', '@conda-forge/help-python', '@conda-forge/help-python-c', '@conda-forge/help-r', '@conda-forge/help-java', '@conda-forge/help-nodejs', '@conda-forge/help-c-cpp', '@conda-forge/help-perl', '@conda-forge/help-julia', '@conda-forge/help-ruby'] | ||
alt team is in comment | ||
GitHub actions->>issue: Adds review-requested label | ||
GitHub actions->>issue: Adds team label | ||
GitHub actions->>issue: Remove Awaiting author contribution label | ||
rect rgb(191, 223, 255) | ||
GitHub actions-->>issue: Assigns team for review | ||
end | ||
end | ||
end | ||
end | ||
deactivate GitHub actions | ||
Reviewer->>issue: Adds a review comment | ||
activate Authenticated bot | ||
alt is PR AND commenter is not author of PR AND review-requested label exists | ||
Authenticated bot-->>Reviewer: Checks membership | ||
alt Reviewer is part of staged-recipes | ||
Authenticated bot->>issue: Remove review-requested label | ||
Authenticated bot->>issue: Add Awaiting author contribution label | ||
end | ||
end | ||
deactivate Authenticated bot | ||
``` | ||
|
||
_Note_: The blue part is proposed and not actually integrated yet. | ||
|
||
## Label State Diagram | ||
|
||
```mermaid | ||
stateDiagram-v2 | ||
[*] --> reviewrequested,team: User pings team | ||
reviewrequested,team --> awaitingauthor,team: staged-recipes reviews | ||
awaitingauthor,team --> reviewrequested,team: User pings team | ||
``` |
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,114 @@ | ||
name: 'Automated review labels' | ||
|
||
on: | ||
issue_comment: | ||
types: [created] | ||
pull_request_review: | ||
types: [submitted] | ||
pull_request_review_comment: | ||
types: [created] | ||
|
||
jobs: | ||
add-review-team-label: | ||
name: 'When pinged, label a PR with review team' | ||
if: > | ||
github.event.issue | ||
&& github.event.issue.pull_request | ||
&& !contains(github.event.issue.labels.*.name, 'review-requested') | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: add-labels | ||
uses: actions/github-script@v6 | ||
with: | ||
script: | | ||
const teams = [ | ||
'@conda-forge/staged-recipes', | ||
'@conda-forge/help-c-cpp', | ||
'@conda-forge/help-cdts', | ||
'@conda-forge/help-go', | ||
'@conda-forge/help-java', | ||
'@conda-forge/help-julia', | ||
'@conda-forge/help-nodejs', | ||
'@conda-forge/help-perl', | ||
'@conda-forge/help-python', | ||
'@conda-forge/help-python-c', | ||
'@conda-forge/help-r', | ||
'@conda-forge/help-ruby' | ||
]; | ||
for (const team of teams) { | ||
let text = context.payload.comment.body; | ||
const regex = new RegExp(team + '[^\-]|' + team + '$'); | ||
let result = regex.test(text); | ||
if (result) { | ||
label = team.replace("@conda-forge/help-", ""); | ||
label_no_staged = label.replace("@conda-forge/", ""); | ||
github.rest.issues.addLabels({ | ||
issue_number: context.issue.number, | ||
owner: context.repo.owner, | ||
repo: context.repo.repo, | ||
labels: [label_no_staged, 'review-requested'] | ||
}) | ||
github.rest.issues.removeLabel({ | ||
issue_number: context.issue.number, | ||
owner: context.repo.owner, | ||
repo: context.repo.repo, | ||
name: ['Awaiting author contribution'] | ||
}); | ||
// TODO: Maybe use GitHub API to request review / assign team | ||
} | ||
} | ||
remove-review-requested-label: | ||
name: 'When reviewed, remove review-requested label' | ||
if: > | ||
( | ||
github.event.issue | ||
&& github.event.issue.pull_request | ||
&& (github.event.sender.login != github.event.issue.user.login) | ||
&& contains(github.event.issue.labels.*.name, 'review-requested') | ||
) || ( | ||
github.event.pull_request | ||
&& (github.event.sender.login != github.event.pull_request.user.login) | ||
&& contains(github.event.pull_request.labels.*.name, 'review-requested') | ||
) | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: check-membership | ||
uses: actions/github-script@v6 | ||
with: | ||
github-token: ${{ secrets.GH_TOKEN }} | ||
script: | | ||
// This step is separate from the labeling step because it uses a token | ||
// with different permissions. If it is combined with the following step, | ||
// then the labeling actions are marked as being completed by whomever | ||
// created the token. | ||
const membership_response = github.rest.teams.getMembershipForUserInOrg({ | ||
org: 'conda-forge', | ||
team_slug: 'staged-recipes', | ||
username: '${{ github.event.sender.login }}' | ||
}); | ||
membership_response.then(function(result) { | ||
console.log(result); | ||
if (result.data.state == 'active'){ | ||
return; | ||
} else { | ||
throw new Error('Reviewer not active member of conda-forge/staged-recipes'); | ||
} | ||
}); | ||
- name: swap-labels | ||
if: ${{ success() }} | ||
uses: actions/github-script@v6 | ||
with: | ||
script: | | ||
github.rest.issues.removeLabel({ | ||
issue_number: context.issue.number, | ||
owner: context.repo.owner, | ||
repo: context.repo.repo, | ||
name: ['review-requested'] | ||
}); | ||
github.rest.issues.addLabels({ | ||
issue_number: context.issue.number, | ||
owner: context.repo.owner, | ||
repo: context.repo.repo, | ||
labels: ['Awaiting author contribution'] | ||
}); |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.