-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Contributor project automations via workflows #2584
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
Merged
StephanTLavavej
merged 14 commits into
microsoft:main
from
celonymire:contributor-project-automation
Oct 26, 2022
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
a3b49b4
Support marking as WIP and initial review
celonymire dac0f76
Add copyright
celonymire e9794be
Review comments + cleanups
celonymire 31647fc
Remove "work in progress" label automations
celonymire 6c64a78
Print error to console
celonymire ad3f7d8
Missed handling of non-existing "Code Reviews"
celonymire 2d7d0a7
Log error message if corresponding columns aren't found
celonymire b248159
Apply most comments
celonymire 17121c3
Properly use template literals
celonymire 4bab90a
Use pagination instead of `list*` methods
celonymire 3b716a6
Merge branch 'main' into contributor-project-automation
StephanTLavavej 95ca181
Fix typos.
StephanTLavavej 9d28f64
Add semicolons.
StephanTLavavej d9074df
Check PR first, author second, substring third. Shorten commands.
StephanTLavavej File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,68 @@ | ||
| # Copyright (c) Microsoft Corporation. | ||
| # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
|
|
||
| name: Move PR To Initial Review | ||
| on: | ||
| issue_comment: | ||
| types: [created] | ||
| branch: | ||
| - main | ||
|
|
||
| jobs: | ||
| move-pr-to-initial-review: | ||
| if: > | ||
| github.event.issue.pull_request | ||
| && github.event.comment.user.login == github.event.issue.user.login | ||
| && contains(github.event.comment.body, '/pr review') | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - name: Move To Initial Review | ||
| uses: actions/github-script@v6 | ||
| with: | ||
| script: | | ||
| // Find "Code Reviews" project manually by name matching | ||
| // This avoids hardcoding the project ID | ||
| const projects = await github.paginate(github.rest.projects.listForRepo, { | ||
| owner: context.repo.owner, | ||
| repo: context.repo.repo, | ||
| }); | ||
| const code_reviews = projects.find(project => project.name === 'Code Reviews'); | ||
| if (!code_reviews) { | ||
| console.error("'Code Reviews' project not found!"); | ||
| return; | ||
| } | ||
|
|
||
| // Find "Initial Review" column manually by name matching | ||
| // This assumes the card is in "Work In Progress" column | ||
| // This avoids hardcoding the column ID and card ID | ||
| const columns = await github.paginate(github.rest.projects.listColumns, { | ||
| project_id: code_reviews.id, | ||
| }); | ||
|
|
||
| const work_in_progress = columns.find(column => column.name === 'Work In Progress'); | ||
| if (!work_in_progress) { | ||
| console.error("'Work In Progress' column not found!"); | ||
| return; | ||
| } | ||
|
|
||
| const initial_review = columns.find(column => column.name === 'Initial Review'); | ||
| if (!initial_review) { | ||
| console.error("'Initial Review' column not found!"); | ||
| return; | ||
| } | ||
|
|
||
| const pr_card = await github.paginate(github.rest.projects.listCards, { | ||
| column_id: work_in_progress.id, | ||
| }).then(cards => cards.find(card => card.content_url === context.payload.issue.url)); | ||
| if (!pr_card) { | ||
| console.error("Corresponding card for PR not found!"); | ||
| return; | ||
| } | ||
|
|
||
| github.rest.projects.moveCard({ | ||
| card_id: pr_card.id, | ||
| position: 'bottom', | ||
| column_id: initial_review.id, | ||
| }).catch(error => { | ||
| console.error(`Error occurred while moving card to 'Initial Review': ${error}`); | ||
| }); | ||
This file contains hidden or 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,73 @@ | ||
| # Copyright (c) Microsoft Corporation. | ||
| # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
|
|
||
| name: Move PR To Work In Progress | ||
| on: | ||
| issue_comment: | ||
| types: [created] | ||
| branch: | ||
| - main | ||
|
|
||
| jobs: | ||
| move-pr-to-wip: | ||
| if: > | ||
| github.event.issue.pull_request | ||
| && github.event.comment.user.login == github.event.issue.user.login | ||
| && contains(github.event.comment.body, '/pr wip') | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - name: Move To Work In Progress | ||
| uses: actions/github-script@v6 | ||
| with: | ||
| script: | | ||
| // Find "Code Reviews" project manually by name matching | ||
| // This avoids hardcoding the project ID | ||
| const projects = await github.paginate(github.rest.projects.listForRepo, { | ||
| owner: context.repo.owner, | ||
| repo: context.repo.repo, | ||
| }); | ||
| const code_reviews = projects.find(project => project.name === 'Code Reviews'); | ||
| if (!code_reviews) { | ||
| console.error("'Code Reviews' project not found!"); | ||
| return; | ||
| } | ||
|
|
||
| // Find "Work In Progress" column manually by name matching | ||
| // Also find the card of the PR in either "Initial Review" or "Final Review" | ||
| // This avoids hardcoding the column ID and card ID | ||
| const columns = await github.paginate(github.rest.projects.listColumns, { | ||
| project_id: code_reviews.id, | ||
| }); | ||
|
|
||
| const work_in_progress = columns.find(column => column.name === 'Work In Progress'); | ||
| if (!work_in_progress) { | ||
| console.error("'Work In Progress' column not found!"); | ||
| return; | ||
| } | ||
|
|
||
| const move_card_in_column = async (column) => { | ||
| const cards = await github.paginate(github.rest.projects.listCards, { | ||
| column_id: column.id, | ||
| }); | ||
|
|
||
| const pr_card = cards.find(card => card.content_url === context.payload.issue.url); | ||
| if (!pr_card) { | ||
| return; // the PR card is not in this column | ||
| } | ||
|
|
||
| await github.rest.projects.moveCard({ | ||
| card_id: pr_card.id, | ||
| position: 'bottom', | ||
| column_id: work_in_progress.id, | ||
| }); | ||
| }; | ||
|
|
||
| columns.forEach(column => { | ||
| if (column.name !== 'Initial Review' && column.name !== 'Final Review') { | ||
| return; // no reason to search through other columns and avoids unnecessary API calls | ||
| } | ||
|
|
||
| move_card_in_column(column).catch(error => { | ||
| console.error(`Error occurred while moving card to 'Work In Progress': ${error}`); | ||
| }); | ||
| }); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.