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
19 changes: 19 additions & 0 deletions .github/workflows/label-prs-as-ready-for-review.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Copyright (c) Microsoft Corporation.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception

name: Label PR As Ready For Review
on:
issue_comment:
types: [created]
branch:
- main
jobs:
label-pr-as-ready-for-review:
if: github.event.issue.pull_request
runs-on: ubuntu-latest
steps:
- name: Add Work In Progress To PR
if: github.event.comment.body == '/pr mark ready'
uses: actions-ecosystem/action-remove-labels@v1
with:
labels: "work in progress"
19 changes: 19 additions & 0 deletions .github/workflows/label-prs-as-work-in-progress.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Copyright (c) Microsoft Corporation.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception

name: Label PR As Work In Progress
on:
issue_comment:
types: [created]
branch:
- main
jobs:
label-pr-as-wip:
if: github.event.issue.pull_request
runs-on: ubuntu-latest
steps:
- name: Add Work In Progress To PR
if: github.event.comment.body == '/pr mark wip'
uses: actions-ecosystem/action-add-labels@v1
with:
labels: "work in progress"
72 changes: 72 additions & 0 deletions .github/workflows/move-ready-for-review-prs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
# 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 === undefined) {
return
sam20908 marked this conversation as resolved.
Show resolved Hide resolved
}

// Find "Initial Review" column manually by name matching
// Also find the card of the PR in all columns
// 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

let work_in_progress = null
sam20908 marked this conversation as resolved.
Show resolved Hide resolved
let pr_card = null
// FIXME forEach is needed instead of a for loop, otherwise it doesn't work
// FIXME find out why
sam20908 marked this conversation as resolved.
Show resolved Hide resolved

// Since .then is asynchronous, cannot guarantee work_in_progress is set before
// the PR card is found. Just loop through the columns again
columns.data.forEach(column => {
if (column.name === 'Initial Review') {
sam20908 marked this conversation as resolved.
Show resolved Hide resolved
work_in_progress = column.id
}
})

// FIXME figure out best way to handle error
sam20908 marked this conversation as resolved.
Show resolved Hide resolved
columns.data.forEach(column => {
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) {
pr_card = card.id // TODO break out early somehow, avoid extra work
sam20908 marked this conversation as resolved.
Show resolved Hide resolved

if (work_in_progress !== null) {
sam20908 marked this conversation as resolved.
Show resolved Hide resolved
github.rest.projects.moveCard({
card_id: pr_card,
position: 'bottom',
column_id: work_in_progress,
}).catch(error => {})
}
}
})
})
.catch(error => {})
})
73 changes: 73 additions & 0 deletions .github/workflows/move-work-in-progress-prs.yml
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.comment.body == '/pr mark wip' && github.event.issue.pull_request
runs-on: ubuntu-latest
steps:
- name: Move To Initial Review
sam20908 marked this conversation as resolved.
Show resolved Hide resolved
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 === undefined) {
return
}

// Find "Work In Progress" column manually by name matching
// Also find the card of the PR in all columns
// This avoids hardcoding the column ID and card ID
const columns = await github.rest.projects.listColumns({
project_id: code_reviews.id,
});

let work_in_progress = null
let pr_card = null
// FIXME forEach is needed instead of a for loop, otherwise it doesn't work
// FIXME find out why

// Since .then is asynchronous, we cannot guarantee work_in_progress is set before
// the PR card is found if we were to process them in the same loop
columns.data.forEach(column => {
if (column.name === 'Work In Progress') {
work_in_progress = column.id
}
})

// FIXME figure out best way to handle error
columns.data.forEach(column => {
github.rest.projects.listCards({
column_id: column.id,
}).then(cards => {
cards.data.forEach(card => {
if (card.content_url === context.payload.issue.url) {
pr_card = card.id // TODO break out early somehow, avoid extra work

if (work_in_progress !== null) {
github.rest.projects.moveCard({
card_id: pr_card,
position: 'bottom',
column_id: work_in_progress,
}).catch(error => {})
}
}
})
})
.catch(error => {})
})