Skip to content

Commit 3d3151e

Browse files
icyphoxaeneasr
authored andcommitted
ci: setup issue/PR automation for projects
This patch runs workflows on issues and PR events. Initial labels are applied, and the issue/PR is moved to the configured project board as 'Todo'.
1 parent 216571a commit 3d3151e

File tree

3 files changed

+193
-0
lines changed

3 files changed

+193
-0
lines changed

.github/workflows/labels.yaml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
name: Auto-label
2+
3+
on:
4+
issues:
5+
types: [opened]
6+
pull_request:
7+
types: [opened]
8+
9+
jobs:
10+
automate-issues-labels:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- name: initial labeling
14+
uses: andymckay/labeler@master
15+
with:
16+
add-labels: "needs-triage"
17+
ignore-if-assigned: true
18+
ignore-if-labeled: true
19+
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
name: Move new issues to project
2+
# Moves new issues to the project board.
3+
4+
on:
5+
issues:
6+
types: [opened]
7+
8+
jobs:
9+
automate-project-columns:
10+
runs-on: ubuntu-latest
11+
steps:
12+
# This step gets all the project data required to
13+
# build a GraphQL mutation that moves a new issue
14+
# to the correct project column.
15+
# We make use of the magic GITHUB_ENV environment variable
16+
# to have these accessible across our workflow run.
17+
- name: Get project data
18+
id: project_data
19+
env:
20+
GITHUB_TOKEN: ${{ secrets.PAT }}
21+
ORG: "ory-corp"
22+
PROJECT_NUMBER: 9
23+
run: |
24+
gh api graphql -f query='
25+
query($org: String!, $num: Int!) {
26+
organization(login: $org){
27+
projectNext(number: $num) {
28+
id
29+
fields(first: 20) {
30+
nodes {
31+
id
32+
name
33+
settings
34+
}
35+
}
36+
}
37+
}
38+
}' -f org=$ORG -F num=$PROJECT_NUMBER > project_data.json
39+
40+
echo 'PROJECT_ID='$(jq -r '.data.organization.projectNext.id' project_data.json) >> $GITHUB_ENV
41+
echo 'STATUS_FIELD_ID='$(jq -r '.data.organization.projectNext.fields.nodes[] | select(.name == "Status").id' project_data.json) >> $GITHUB_ENV
42+
echo 'TODO_OPTION_ID='$(jq -r '.data.organization.projectNext.fields.nodes[] | select(.name == "Status").settings | fromjson.options[] | select(.name=="Todo").id' project_data.json) >> $GITHUB_ENV
43+
44+
# We simply add the issue to the project.
45+
# Setting the 'Status' field is done in the next step.
46+
- name: Add issue to project
47+
env:
48+
GITHUB_TOKEN: ${{ secrets.PAT }}
49+
ISSUE_ID: ${{ github.event.issue.node_id }}
50+
run: |
51+
item_id="$( gh api graphql -f query='
52+
mutation($project: ID!, $issue: ID!) {
53+
addProjectNextItem(input: {
54+
projectId: $project,
55+
contentId: $issue
56+
}) {
57+
projectNextItem {
58+
id
59+
}
60+
}
61+
}' -f project=$PROJECT_ID -f issue=$ISSUE_ID --jq '.data.addProjectNextItem.projectNextItem.id')"
62+
63+
echo 'ITEM_ID='$item_id >> $GITHUB_ENV
64+
65+
# Set the relevant fields. Add as many as required.
66+
- name: Set fields
67+
env:
68+
GITHUB_TOKEN: ${{ secrets.PAT }}
69+
run: |
70+
gh api graphql -f query='
71+
mutation (
72+
$project: ID!
73+
$item: ID!
74+
$status_field: ID!
75+
$status_value: String!
76+
) {
77+
updateProjectNextItemField(input: {
78+
projectId: $project
79+
itemId: $item
80+
fieldId: $status_field
81+
value: $status_value
82+
}) {
83+
projectNextItem {
84+
id
85+
}
86+
}
87+
}' -f project=$PROJECT_ID -f item=$ITEM_ID -f status_field=$STATUS_FIELD_ID -f status_value=$TODO_OPTION_ID
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
name: Move new PRs to project
2+
# Moves new PRs to the project board.
3+
4+
on:
5+
pull_request:
6+
types: [opened]
7+
8+
jobs:
9+
automate-project-columns:
10+
runs-on: ubuntu-latest
11+
steps:
12+
# This step gets all the project data required to
13+
# build a GraphQL mutation that moves a new PR
14+
# to the correct project column.
15+
# We make use of the magic GITHUB_ENV environment variable
16+
# to have these accessible across our workflow run.
17+
- name: Get project data
18+
id: project_data
19+
env:
20+
GITHUB_TOKEN: ${{ secrets.PAT }}
21+
ORG: "icyphox"
22+
PROJECT_NUMBER: 1
23+
run: |
24+
gh api graphql -f query='
25+
query($org: String!, $num: Int!) {
26+
user(login: $org){
27+
projectNext(number: $num) {
28+
id
29+
fields(first: 20) {
30+
nodes {
31+
id
32+
name
33+
settings
34+
}
35+
}
36+
}
37+
}
38+
}' -f org=$ORG -F num=$PROJECT_NUMBER > project_data.json
39+
40+
echo 'PROJECT_ID='$(jq -r '.data.user.projectNext.id' project_data.json) >> $GITHUB_ENV
41+
echo 'STATUS_FIELD_ID='$(jq -r '.data.user.projectNext.fields.nodes[] | select(.name == "Status").id' project_data.json) >> $GITHUB_ENV
42+
echo 'TODO_OPTION_ID='$(jq -r '.data.user.projectNext.fields.nodes[] | select(.name == "Status").settings | fromjson.options[] | select(.name=="Todo").id' project_data.json) >> $GITHUB_ENV
43+
44+
# We simply add the PR to the project.
45+
# Setting the 'Status' field is done in the next step.
46+
- name: Add PR to project
47+
env:
48+
GITHUB_TOKEN: ${{ secrets.PAT }}
49+
PR_ID: ${{ github.event.pull_request.node_id }}
50+
run: |
51+
item_id="$( gh api graphql -f query='
52+
mutation($project: ID!, $pr: ID!) {
53+
addProjectNextItem(input: {
54+
projectId: $project,
55+
contentId: $pr
56+
}) {
57+
projectNextItem {
58+
id
59+
}
60+
}
61+
}' -f project=$PROJECT_ID -f pr=$PR_ID --jq '.data.addProjectNextItem.projectNextItem.id')"
62+
63+
echo 'ITEM_ID='$item_id >> $GITHUB_ENV
64+
65+
# Set the relevant fields. Add as many as required.
66+
- name: Set fields
67+
env:
68+
GITHUB_TOKEN: ${{ secrets.PAT }}
69+
run: |
70+
gh api graphql -f query='
71+
mutation (
72+
$project: ID!
73+
$item: ID!
74+
$status_field: ID!
75+
$status_value: String!
76+
) {
77+
updateProjectNextItemField(input: {
78+
projectId: $project
79+
itemId: $item
80+
fieldId: $status_field
81+
value: $status_value
82+
}) {
83+
projectNextItem {
84+
id
85+
}
86+
}
87+
}' -f project=$PROJECT_ID -f item=$ITEM_ID -f status_field=$STATUS_FIELD_ID -f status_value=$TODO_OPTION_ID

0 commit comments

Comments
 (0)