-
Notifications
You must be signed in to change notification settings - Fork 17
79 lines (71 loc) · 2.48 KB
/
project-get-item-id.yaml
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
name: Project - Get Item ID Within the Project
# This workflow gets the project-specific ID for an item within a project
# All downstream queries and mutations of fields within the project require this ID
on:
workflow_call:
inputs:
PROJECT_ID:
description: "The Project's graphQL node ID"
type: string
required: true
ITEM_NODE_ID:
description: "The issue or PR's graphQL node ID"
type: string
required: true
secrets:
ADD_TO_PROJECT_GITHUB_TOKEN:
description: "Project Access Token"
required: true
outputs:
ITEM_PROJECT_ID:
description: "The item's project-specific ID"
value: ${{ jobs.get_items_project_id.outputs.ITEM_PROJECT_ID }}
jobs:
get_items_project_id:
runs-on: ubuntu-latest
outputs:
ITEM_PROJECT_ID: ${{ steps.get_item_id.outputs.ITEM_PROJECT_ID }}
steps:
- name: Sleep 1s
id: sleep_1s
run: |
sleep 1 # Ensure the PR is added to the project before we query its ID
- name: Get Item Project ID
id: get_item_id
env:
GH_TOKEN: ${{ secrets.ADD_TO_PROJECT_GITHUB_TOKEN }}
run: |
# Query up to 10 projects for the PR
# There's no graphQL filter configured to query by a specific project
# So we need to query all projects and filter the result ourselves
gh api graphql -f query='
query {
node(id: "${{ inputs.ITEM_NODE_ID }}") {
... on PullRequest {
projectItems(first: 10) {
nodes {
id
project {
id
}
}
}
}
... on Issue {
projectItems(first: 10) {
nodes {
id
project {
id
}
}
}
}
}
}' > project_data.json
# Use jq to do the actual filtering
item_project_id=$(jq -r '.data.node.projectItems.nodes[] |
select(.project.id == "${{ inputs.PROJECT_ID }}") |
.id' project_data.json)
echo "ITEM_PROJECT_ID=$item_project_id" >> $GITHUB_OUTPUT
continue-on-error: true