-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathaction.yml
112 lines (105 loc) · 4.1 KB
/
action.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
name: Add User Pull Requests to Project Board
author: Aaron Waggener
description: Add open pull requests that match an organization and list of usernames to a project board.
inputs:
usernames:
description: 'A space separated list of usernames. Example: octocat mona-lisa'
required: true
project-id:
description: 'The numerical ID of the project, typically found in the URL after "projects/" [organization-name]/projects/[project-id]'
required: true
organization:
description: 'The URL friendly name of the organization where the project is located. Defaults to the current organization where the action is being run.'
required: false
default: ${{ github.repository_owner }}
runs:
using: composite
steps:
- id: get-project-node-id
run: |
if ! echo "${{ inputs.project-id }}" | grep -Eq '^[0-9]+$'; then
echo "Error: project must be a number"
exit 1
fi
if [ -z "${{ inputs.organization }}" ]; then
echo "Error: No organization provided"
exit 1
fi
PROJECT_DATA=$(gh api graphql -f query='
query($org: String!, $number: Int!) {
organization(login: $org) {
projectV2(number: $number) {
id
fields(first: 100) {
nodes {
... on ProjectV2Field {
id
name
}
}
}
}
}
}' -f org=${{ inputs.organization }} -F number=${{ inputs.project-id }})
PROJECT_ID=$(echo $PROJECT_DATA | jq -r '.data.organization.projectV2.id')
CREATED_AT_FIELD_ID=$(echo $PROJECT_DATA | jq -r '.data.organization.projectV2.fields.nodes[] | select(.name == "Created At") | .id')
echo "PROJECT_ID=$PROJECT_ID" >> $GITHUB_ENV
echo "CREATED_AT_FIELD_ID=$CREATED_AT_FIELD_ID" >> $GITHUB_ENV
shell: bash
- id: get-pr-ids
run: |
USERNAMES_FORMATTED=""
for username in ${{ inputs.usernames }}; do
USERNAMES_FORMATTED="${USERNAMES_FORMATTED}author:${username} "
done
USERNAMES_FORMATTED=${USERNAMES_FORMATTED%+}
if [ -z "$USERNAMES_FORMATTED" ]; then
echo "Error: No usernames provided"
exit 1
fi
PR_DATA=$(gh api graphql --paginate -F query="
query(\$cursor: String){
search(first: 100, type: ISSUE, query: \"org:${{ inputs.organization }} is:pr is:open $USERNAMES_FORMATTED\", after: \$cursor) {
pageInfo {
hasNextPage
endCursor
}
nodes {
... on PullRequest {
id
createdAt
}
}
}
}
" | jq -c '.data.search.nodes[]')
echo "$PR_DATA" > pr_data.json
shell: bash
- id: add-prs-to-project
run: |
PR_DATA_FILE=pr_data.json
for pr_info in $(cat $PR_DATA_FILE); do
PR_ID=$(echo $pr_info | jq -r '.id')
PR_CREATED_AT=$(echo $pr_info | jq -r '.createdAt')
# Add PR to project
ADD_PR_RESULT=$(gh api graphql -f query='
mutation($project_id: ID!, $pr_id: ID!) {
addProjectV2ItemById(input: {projectId: $project_id, contentId: $pr_id}) {
item {
id
}
}
}' -f project_id=$PROJECT_ID -f pr_id=$PR_ID)
PR_ITEM_ID=$(echo $ADD_PR_RESULT | jq -r '.data.addProjectV2ItemById.item.id')
# Set custom Created At field value
SET_CREATED_AT_RESULT=$(gh api graphql -f query='
mutation($item_id: ID!, $field_id: ID!, $value: Date!, $project_id: ID!) {
updateProjectV2ItemFieldValue(input: {itemId: $item_id, fieldId: $field_id, value: {date: $value}, projectId: $project_id}) {
clientMutationId
}
}' -f item_id=$PR_ITEM_ID -f field_id=$CREATED_AT_FIELD_ID -f value=$PR_CREATED_AT -f project_id=$PROJECT_ID)
done
shell: bash
branding:
icon: activity
color: purple