Skip to content

Commit fb43ff3

Browse files
icyphoxaeneasr
authored andcommitted
ci: refactor as a composite action
1 parent 3d3151e commit fb43ff3

File tree

5 files changed

+145
-194
lines changed

5 files changed

+145
-194
lines changed

.github/workflows/labels.yaml

Lines changed: 0 additions & 19 deletions
This file was deleted.

.github/workflows/new-issues-project.yaml

Lines changed: 0 additions & 87 deletions
This file was deleted.

.github/workflows/new-prs-project.yaml

Lines changed: 0 additions & 87 deletions
This file was deleted.

README.md

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,40 @@
1-
# actions-product-board
1+
# actions-product-board
2+
> GitHub Action that helps automate GitHub Projects (beta)
3+
4+
It reacts to `issues` and `pull_request` events, and does the following:
5+
6+
- Sets initial labels
7+
- Adds the issue/PR to the configured project board
8+
- Sets the status of the ticket to Todo
9+
10+
### Inputs
11+
12+
- `project`: Project board number (`github.com/orgs/foo/projects/N`)
13+
- `token`: A personal access token with write:org capabilities.
14+
- `org`: The name of your organization. Defaults to `github.repository_owner`.
15+
- `label`: Initial label for new issues/PRs. Defaults to `needs triage`.
16+
17+
### Complete usage
18+
19+
```yaml
20+
on:
21+
issues:
22+
types: [opened]
23+
pull_request:
24+
types: [opened]
25+
26+
permissions:
27+
issues: write
28+
pull-requests: write
29+
30+
jobs:
31+
automate:
32+
runs-on: ubuntu-latest
33+
name: blah
34+
steps:
35+
- uses: ory-corp/actions-product-board@master
36+
with:
37+
project: 9
38+
token: ${{ secrets.PAT }}
39+
org: ory-corp
40+
```

action.yml

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
name: 'Project Board Automation'
2+
description: 'Automate GitHub Projects with ease'
3+
inputs:
4+
project:
5+
description: Project board number
6+
required: true
7+
default: 1
8+
token:
9+
description: GitHub PAT with org:write
10+
required: true
11+
org:
12+
description: Organization that owns the project
13+
required: false
14+
default: ${{ github.repository_owner }}
15+
label:
16+
description: Initial label for new issues/PRs
17+
required: false
18+
default: "needs triage"
19+
runs:
20+
using: "composite"
21+
steps:
22+
- name: Initial labeling
23+
uses: andymckay/labeler@e6c4322d0397f3240f0e7e30a33b5c5df2d39e90
24+
with:
25+
add-labels: "${{ inputs.label }}"
26+
ignore-if-assigned: true
27+
ignore-if-labeled: true
28+
29+
- name: Fetch project data
30+
run: |
31+
gh api graphql -f query='
32+
query($org: String!, $num: Int!) {
33+
organization(login: $org){
34+
projectNext(number: $num) {
35+
id
36+
fields(first: 20) {
37+
nodes {
38+
id
39+
name
40+
settings
41+
}
42+
}
43+
}
44+
}
45+
}' -f org=$ORG -F num=${{ inputs.project }} > project_data.json
46+
47+
echo 'PROJECT_ID='$(jq -r '.data.organization.projectNext.id' project_data.json) >> $GITHUB_ENV
48+
echo 'STATUS_FIELD_ID='$(jq -r '.data.organization.projectNext.fields.nodes[] | select(.name == "Status").id' project_data.json) >> $GITHUB_ENV
49+
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
50+
env:
51+
GITHUB_TOKEN: ${{ inputs.token }}
52+
ORG: ${{ inputs.org }}
53+
shell: bash
54+
55+
- name: Get issue/PR ID
56+
run: |
57+
if [[ "${{ github.event_name }}" == "pull_request" ]]; then
58+
echo 'ISSUE_PR_ID='${{ github.event.pull_request.node_id }} >> $GITHUB_ENV
59+
elif [[ "${{ github.event_name }}" == "issues" ]]; then
60+
echo 'ISSUE_PR_ID='${{ github.event.issue.node_id }} >> $GITHUB_ENV
61+
fi
62+
shell: bash
63+
64+
- name: Move issue/PR to project
65+
run: |
66+
item_id="$( gh api graphql -f query='
67+
mutation($project: ID!, $id: ID!) {
68+
addProjectNextItem(input: {
69+
projectId: $project,
70+
contentId: $id,
71+
}) {
72+
projectNextItem {
73+
id
74+
}
75+
}
76+
}' -f project=$PROJECT_ID -f id=$ISSUE_PR_ID --jq '.data.addProjectNextItem.projectNextItem.id')"
77+
78+
echo 'ITEM_ID='$item_id >> $GITHUB_ENV
79+
env:
80+
GITHUB_TOKEN: ${{ inputs.token }}
81+
shell: bash
82+
83+
- name: Set fields on project ticket
84+
run: |
85+
gh api graphql -f query='
86+
mutation (
87+
$project: ID!
88+
$item: ID!
89+
$status_field: ID!
90+
$status_value: String!
91+
) {
92+
updateProjectNextItemField(input: {
93+
projectId: $project
94+
itemId: $item
95+
fieldId: $status_field
96+
value: $status_value
97+
}) {
98+
projectNextItem {
99+
id
100+
}
101+
}
102+
}' -f project=$PROJECT_ID -f item=$ITEM_ID -f status_field=$STATUS_FIELD_ID -f status_value=$TODO_OPTION_ID
103+
env:
104+
GITHUB_TOKEN: ${{ inputs.token }}
105+
shell: bash

0 commit comments

Comments
 (0)