-
-
Notifications
You must be signed in to change notification settings - Fork 299
142 lines (134 loc) · 5.38 KB
/
organize_gh_project.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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
name: "Organize Issues and PRs on GH project"
on:
issues:
types:
- opened
- reopened
- closed
- assigned
- labeled
- unlabeled
- milestoned
issue_comment:
types:
- created
permissions:
repository-projects: write
contents: write
issues: write
jobs:
add_issue_to_project:
if: ${{ github.event_name == 'issues' && (github.event.action == 'opened' || github.event.action == 'reopened') }}
runs-on: ubuntu-latest
steps:
- name: Get project data
env:
GITHUB_TOKEN: ${{ secrets.NCP_PROJECT_PAT }}
ORGANIZATION: nextcloud
PROJECT_NUMBER: 67
run: |
gh api graphql -f query='
query($org: String!, $number: Int!) {
organization(login: $org){
projectV2(number: $number) {
id
fields(first:20) {
nodes {
... on ProjectV2Field {
id
name
}
... on ProjectV2SingleSelectField {
id
name
options {
id
name
}
}
}
}
}
}
}' -f org=$ORGANIZATION -F number=$PROJECT_NUMBER > project_data.json
echo 'PROJECT_ID='$(jq '.data.organization.projectV2.id' project_data.json) >> $GITHUB_ENV
echo "BUGS_STATUS_FIELD_ID=$(jq '.data.organization.projectV2.fields.nodes[] | select(.name== "Status") | .id' project_data.json)" >> $GITHUB_ENV
echo "BUGS_STATUS_OPTION_NEW_ID=$(jq '.data.organization.projectV2.fields.nodes[] | select(.name== "Status") | .options[] | select(.name=="New") |.id' project_data.json)" >> $GITHUB_ENV
echo "BUGS_STATUS_OPTION_BUG_ID=$(jq '.data.organization.projectV2.fields.nodes[] | select(.name== "Status") | .options[] | select(.name=="Bugs") |.id' project_data.json)" >> $GITHUB_ENV
echo "DEVEL_STATUS_FIELD_ID=$(jq '.data.organization.projectV2.fields.nodes[] | select(.name== "Development Status") | .id' project_data.json)" >> $GITHUB_ENV
echo "DEVEL_STATUS_OPTION_BACKLOG_ID=$(jq '.data.organization.projectV2.fields.nodes[] | select(.name== "Development Status") | .options[] | select(.name=="Backlog") |.id' project_data.json)" >> $GITHUB_ENV
- name: Add Issue to project
env:
GH_TOKEN: ${{ secrets.NCP_PROJECT_PAT }}
ISSUE_ID: ${{ github.event.issue.node_id }}
run: |
item_id="$( gh api graphql -f query='
mutation($project:ID!, $issue:ID!) {
addProjectV2ItemById(input: {projectId: $project, contentId: $issue}) {
item {
id
}
}
}' -f project=$PROJECT_ID -f issue=$ISSUE_ID --jq '.data.addProjectV2ItemById.item.id')"
echo 'ITEM_ID='$item_id >> $GITHUB_ENV
# - name: Set fields
# env:
# GH_TOKEN: ${{ secrets.NCP_PROJECT_PAT }}
# IS_ENHANCMENET: ${{ contains( github.event.issue.labels.*.name, 'enhancement') || contains( github.event.issue.labels.*.name, 'feature-request') || contains( github.event.issue.labels.*.name, 'roadmap') }}
# IS_BUG: ${{ contains( github.event.issue.labels.*.name, 'bug') }}
# run: |
#
# if [[ "$IS_ENHANCEMENT" == true ]]
# then
# STATUS_FIELD_ID="$DEVEL_STATUS_FIELD_ID"
# STATUS_OPTION_ID="$DEVEL_STATUS_OPTION_BACKLOG_ID"
# elif [[ "$IS_BUG" == true ]]
# then
# STATUS_FIELD_ID="$BUGS_STATUS_FIELD_ID"
# STATUS_OPTION_ID="$BUGS_STATUS_OPTION_BUG_ID"
# else
# STATUS_FIELD_ID="$BUGS_STATUS_FIELD_ID"
# STATUS_OPTION_ID="$BUGS_STATUS_OPTION_NEW_ID"
# fi
#
# echo "project=$PROJECT_ID
# item=$ITEM_ID
# status_field=$STATUS_FIELD_ID
# status_value=$STATUS_OPTION_ID"
#
# gh api graphql -f query='
# mutation(
# $project: ID!
# $item: ID!
# $status_field: ID!
# $status_value: String!
# ) {
# set_status: updateProjectV2ItemFieldValue(input: {
# projectId: $project
# itemId: $item
# fieldId: $status_field
# value: {
# singleSelectOptionId: $status_value
# }
# }) {
# projectV2Item {
# id
# }
# }
# }' \
# -f project=$PROJECT_ID \
# -f "item=$ITEM_ID" \
# -f "status_field=$STATUS_FIELD_ID" \
# -f "status_value=$STATUS_OPTION_ID" \
# --silent
set_update_label:
if: ${{ github.event_name == 'issue_comment' && !github.event.issue.pull_request && !contains( github.event.issue.assignees.*.login, github.event.comment.user.login ) }}
runs-on: ubuntu-latest
steps:
- name: Add update label to issue
if: ${{ ! contains( github.event.issue.labels.*.name, 'update' ) }}
env:
ISSUE_ID: ${{ github.event.issue.number }}
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
gh issue edit --repo "${{ github.repository }}" --add-label has-updates "$ISSUE_ID"