-
Notifications
You must be signed in to change notification settings - Fork 84
99 lines (96 loc) · 3.79 KB
/
add-issues-to-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
# GitHub action that automatically adds newly filed issues to the Lit project.
#
# Based on the example at
# https://docs.github.com/en/issues/trying-out-the-new-projects-experience/automating-projects#example-workflow-authenticating-with-a-personal-access-token
on:
issues:
types: [opened]
jobs:
add-issue-to-project:
# Don't run on forks. Issues on forks aren't relevant, and secrets aren't
# available anyway.
if: github.repository == 'webcomponents/webcomponents.org'
runs-on: ubuntu-latest
steps:
- name: Add issue to project
env:
GITHUB_TOKEN: ${{ secrets.LIT_ROBOT_AUTOMATION_PAT }}
# The project ID can be found by running the following query at
# https://docs.github.com/en/graphql/overview/explorer
#
# {
# organization(login: "lit") {
# projectV2(number: 4) {
# id
# }
# }
# }
PROJECT_ID: PVT_kwDOARoh9s4AAixo
# Note: issue.url is the REST API url, but we want issue.html_url
# which is the regular public URL.
ISSUE_URL: ${{ github.event.issue.html_url }}
# The addProjectV2ItemById API refuses to add an issue to a project
# unless the issue is in the same org as the project -- even though it's
# possible to do so through the UI. However, it turns out if you set the
# URL as the title using the addProjectV2DraftIssue API, that does the
# right thing!
run: |
gh api graphql -f query='
mutation($project_id:ID!, $issue_url:String!) {
addProjectV2DraftIssue(input: {projectId: $project_id, title: $issue_url}) {
projectItem {
id
}
}
}' -f project_id=$PROJECT_ID -f issue_url=$ISSUE_URL > item.json
echo 'ITEM_ID='$(jq '.data.addProjectV2DraftIssue.projectItem.id' item.json) >> $GITHUB_ENV
- name: Add area to item
env:
GITHUB_TOKEN: ${{ secrets.LIT_ROBOT_AUTOMATION_PAT }}
PROJECT_ID: PVT_kwDOARoh9s4AAixo
# Field and value IDs can be found by running the following query at
# https://docs.github.com/en/graphql/overview/explorer
#
# {
# node(id: "PVT_kwDOARoh9s4AAixo") {
# ... on ProjectV2 {
# fields(first: 100) {
# nodes {
# ... on ProjectV2Field {
# id
# name
# }
# ... on ProjectV2IterationField {
# id
# name
# configuration {
# iterations {
# startDate
# id
# }
# }
# }
# ... on ProjectV2SingleSelectField {
# id
# name
# options {
# id
# name
# }
# }
# }
# }
# }
# }
# }
FIELD_ID: PVTSSF_lADOARoh9s4AAixozgASjcA # Area
VALUE_ID: 9a4cb01d # webcomponents.org
run: |
gh api graphql -f query='
mutation ($project_id: ID!, $item_id: ID!, $field_id: ID!, $value_id: String!) {
updateProjectV2ItemFieldValue(
input: {projectId: $project_id, itemId: $item_id, fieldId: $field_id, value: {singleSelectOptionId: $value_id}}
) {
clientMutationId
}
}' -f project_id=$PROJECT_ID -f item_id=$ITEM_ID -f field_id=$FIELD_ID -f value_id=$VALUE_ID