forked from sillsdev/web-languageforge
-
Notifications
You must be signed in to change notification settings - Fork 0
100 lines (91 loc) · 3.5 KB
/
set-backlog-fields.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
name: Add Issue to Project
on:
issues:
types: [ opened ]
jobs:
steve:
if: ${{ !github.event.issue.pull_request }}
runs-on: ubuntu-latest
steps:
- name: determine if issue is already on a project
env:
GITHUB_TOKEN: ${{ secrets.PERSONAL_TOKEN }}
ISSUE_NUMBER: ${{ github.event.issue.number }}
REPO: ${{ toJson(github.event.repository.name) }}
run: |
echo issue $ISSUE_NUMBER added to $REPO
gh api graphql -f query='
query($issue_number:Int!) {
repository(name:"web-languageforge", owner:"josephmyers") {
issue(number: $issue_number) {
id
projectNextItems(first:100) {
nodes {
id
}
}
}
}
}' -F issue_number=$ISSUE_NUMBER > project_data.json
echo 'IN_PROJECT='$(jq '.data.repository.issue.projectNextItems[] | length' project_data.json) >> $GITHUB_ENV
- name: get required info for set operations
env:
GITHUB_TOKEN: ${{ secrets.PERSONAL_TOKEN }}
ORGANIZATION: josephmyers
run: |
gh api graphql -f query='
query($org: String!) {
user(login: $org){
projectNext(number: 1) {
id
fields(first:20) {
nodes {
id
name
settings
}
}
}
}
}' -f org=$ORGANIZATION > project_data.json
echo 'PROJECT_ID='$(jq '.data.user.projectNext.id' project_data.json) >> $GITHUB_ENV
echo 'FIELD_ID='$(jq '.data.user.projectNext.fields.nodes[] | select(.name== "ProductOwner") | .id' project_data.json) >> $GITHUB_ENV
echo 'TRIAGE_ID='$(jq '.data.user.projectNext.fields.nodes[] | select(.name== "ProductOwner") | .settings | fromjson.options[] | select(.name=="Triage") | .id' project_data.json) >> $GITHUB_ENV
- name: Add issue to project
if: env.IN_PROJECT == 0
env:
GITHUB_TOKEN: ${{ secrets.PERSONAL_TOKEN }}
ISSUE_ID: ${{ github.event.issue.node_id }} #use ITEM_ID for finding on projects
run: |
item_id="$( gh api graphql -f query='
mutation($project:ID!, $item:ID!) {
addProjectNextItem(input: {projectId: $project, contentId: $item}) {
projectNextItem {
id
}
}
}' -f project=$PROJECT_ID -f item=$ISSUE_ID --jq '.data.addProjectNextItem.projectNextItem.id')"
echo 'ITEM_ID='$item_id >> $GITHUB_ENV
- name: set Backlog field
if: env.IN_PROJECT == 0
env:
GITHUB_TOKEN: ${{ secrets.PERSONAL_TOKEN }}
run: |
gh api graphql -f query='
mutation(
$project:ID!
$item:ID!
$field: ID!
$field_value: String!)
{
updateProjectNextItemField(input: {
projectId: $project
itemId: $item
fieldId: $field
value: $field_value})
{
projectNextItem {
id
}
}
}' -f project=$PROJECT_ID -f item=$ITEM_ID -f field=$FIELD_ID -f field_value=${{ env.TRIAGE_ID }}