Skip to content
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

Contributor project automations via workflows #2584

Merged
Merged
64 changes: 64 additions & 0 deletions .github/workflows/move-ready-for-review-prs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
# 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.comment.body == '/pr mark ready' && github.event.issue.pull_request
sam20908 marked this conversation as resolved.
Show resolved Hide resolved
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.rest.projects.listForRepo({
owner: context.repo.owner,
repo: context.repo.repo,
})
const code_reviews = projects.data.find(project => {
return project.name === 'Code Reviews';
})
sam20908 marked this conversation as resolved.
Show resolved Hide resolved
if (!code_reviews) {
return
sam20908 marked this conversation as resolved.
Show resolved Hide resolved
}

// 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.rest.projects.listColumns({
project_id: code_reviews.id,
});
StephanTLavavej marked this conversation as resolved.
Show resolved Hide resolved

const work_in_progress = columns.data.find(column => column.name === 'Work In Progress')
if (!work_in_progress) {
return
}

const initial_review = columns.data.find(column => column.name === 'Initial Review')
if (!initial_review) {
return
}

const work_in_progress_cards = await github.rest.projects.listCards({
sam20908 marked this conversation as resolved.
Show resolved Hide resolved
column_id: work_in_progress.id,
})
const pr_card = work_in_progress_cards.data.find(card => card.content_url === context.payload.issue.url)
if (!pr_card) {
return
}

github.rest.projects.moveCard({
card_id: pr_card.id,
position: 'bottom',
column_id: initial_review.id,
}).catch(error => {
console.error("Error occured while moving card to Initial Review!")
})
70 changes: 70 additions & 0 deletions .github/workflows/move-work-in-progress-prs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
# 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.comment.body == '/pr mark wip' && github.event.issue.pull_request
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.rest.projects.listForRepo({
owner: context.repo.owner,
repo: context.repo.repo,
})
const code_reviews = projects.data.find(project => {
return project.name === 'Code Reviews';
})
if (!code_reviews) {
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.rest.projects.listColumns({
project_id: code_reviews.id,
});

const work_in_progress = columns.data.find(column => column.name === 'Work In Progress')
if (!work_in_progress) {
return
}

columns.data.forEach(column => {
if (column.name !== 'Initial Review' && column.name !== 'Final Review') {
return // no reason to search through other columns and avoids unnecessary API calls
}
sam20908 marked this conversation as resolved.
Show resolved Hide resolved

github.rest.projects.listCards({
column_id: column.id,
}).then(cards => {
cards.data.forEach(card => {
if (card.content_url === context.payload.issue.url) {
// card is the PR card

github.rest.projects.moveCard({
card_id: card.id,
position: 'bottom',
column_id: work_in_progress.id,
}).catch(error => {
console.error("Error occured while moving card to Work In Progress!")
})
}
})
})
.catch(error => {
console.error("Error while fetching cards from column ID " + column.id)
})
})