Skip to content

Commit 7915dc0

Browse files
committed
Stop locking workflow to a particular organisation
1 parent ad7f3a7 commit 7915dc0

File tree

1 file changed

+29
-13
lines changed

1 file changed

+29
-13
lines changed

.github/workflows/add_prs_to_project.yml

Lines changed: 29 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
# call-add-prs-to-project:
2424
# uses: UoMResearchIT/Actions/.github/workflows/add_prs_to_project.yml@main
2525
# with:
26+
# organisation: UoMResearchIT
27+
# project_number: 123
2628
# personal_access_token: ${{ secrets.TOKEN }}
2729
#
2830

@@ -31,17 +33,31 @@ run-name: "Add PR #${{ github.event.pull_request.id }} to Project #${{ inputs.pr
3133
on:
3234
workflow_call:
3335
inputs:
36+
organisation:
37+
type: string
38+
required: false
39+
# This is the default for compatibility reasons; this is probably wrong but...
40+
default: SpiNNakerManchester
41+
description: >
42+
The name of the organisation that owns the project.
3443
project_number:
3544
type: number
3645
required: true
3746
description: >
3847
The identifier of the project to add the PR to in the organisation being run in.
48+
status_field:
49+
type: string
50+
required: false
51+
default: Status
52+
description: >
53+
The name of the "status" field, in case that is something other than the default.
3954
status_to_change_to:
4055
type: string
4156
required: false
4257
default: Ready To Review
4358
description: >
44-
The name of the option to select in as the Status field. This workflow assumes that the project has a single select field called "Status" that includes an option that this value specifies.
59+
The name of the option to select in as the Status field.
60+
This workflow assumes that the project has a single select field called "Status" (or whatever the status_field input names it as) that includes an option that this value specifies.
4561
secrets:
4662
personal_access_token:
4763
required: true
@@ -54,11 +70,14 @@ jobs:
5470
steps:
5571
- name: Get project data
5672
env:
57-
# Aur
5873
GH_TOKEN: ${{ secrets.personal_access_token }}
59-
ORGANIZATION: SpiNNakerManchester
74+
ORGANIZATION: ${{ inputs.organisation }}
6075
PROJECT_NUMBER: ${{ inputs.project_number }}
61-
# Uses [GitHub CLI](https://cli.github.com/manual/) to query the API for the ID of the project and return the name and ID of the first 20 fields in the project. `fields` returns a union and the query uses inline fragments (`... on`) to return information about any `ProjectV2Field` and `ProjectV2SingleSelectField` fields. The response is stored in a file called `project_data.json`.
76+
STATUS_FIELD: ${{ inputs.status_field }}
77+
STATUS_VALUE: ${{ inputs.status_to_change_to }}
78+
# Uses [GitHub CLI](https://cli.github.com/manual/) to query the API for the ID of the project and return the name and ID of the first 20 fields in the project.
79+
# `fields` returns a union and the query uses inline fragments (`... on`) to return information about any `ProjectV2Field` and `ProjectV2SingleSelectField` fields.
80+
# The response is stored in a file called `project_data.json` that is parsed to get the relevant IDs that are stored as environment variables.
6281
run: |
6382
gh api graphql -f query='
6483
query($org: String!, $number: Int!) {
@@ -84,19 +103,16 @@ jobs:
84103
}
85104
}
86105
}' -f org=$ORGANIZATION -F number=$PROJECT_NUMBER > project_data.json
87-
88-
# Parses the response from the API query and stores the relevant IDs as environment variables.
89-
# **Note:** This workflow assumes that you have a project with a single select field called "Status" that includes an option specified in inputs.status_to_change_to.
90-
91106
echo 'PROJECT_ID='$(jq '.data.organization.projectV2.id' project_data.json) >> $GITHUB_ENV
92-
echo 'STATUS_FIELD_ID='$(jq '.data.organization.projectV2.fields.nodes[] | select(.name== "Status") | .id' project_data.json) >> $GITHUB_ENV
93-
echo 'STATUS_OPTION_ID='$(jq '.data.organization.projectV2.fields.nodes[] | select(.name== "Status") | .options[] | select(.name=="${{ inputs.status_to_change_to }}") |.id' project_data.json) >> $GITHUB_ENV
107+
echo 'STATUS_FIELD_ID='$(jq '.data.organization.projectV2.fields.nodes[] | select(.name==env.STATUS_FIELD) | .id' project_data.json) >> $GITHUB_ENV
108+
echo 'STATUS_OPTION_ID='$(jq '.data.organization.projectV2.fields.nodes[] | select(.name==env.STATUS_FIELD) | .options[] | select(.name==env.STATUS_VALUE) |.id' project_data.json) >> $GITHUB_ENV
94109
95110
- name: Add PR to project
96111
env:
97112
GH_TOKEN: ${{ secrets.personal_access_token }}
98113
PR_ID: ${{ github.event.pull_request.node_id }}
99-
# Uses [GitHub CLI](https://cli.github.com/manual/) and the API to add the pull request that triggered this workflow to the project. The `jq` flag parses the response to get the ID of the created item.
114+
# Uses [GitHub CLI](https://cli.github.com/manual/) and the API to add the pull request that triggered this workflow to the project.
115+
# The `jq` flag parses the response to get the ID of the created item.
100116
run: |
101117
item_id="$( gh api graphql -f query='
102118
mutation($project:ID!, $pr:ID!) {
@@ -113,7 +129,7 @@ jobs:
113129
- name: Set fields
114130
env:
115131
GH_TOKEN: ${{ secrets.personal_access_token }}
116-
# Sets the value of the `Status` field to `Ready to Review`.
132+
# Sets the value of the `Status` field to `Ready to Review`. (Or whatever the field and value are called)
117133
run: |
118134
gh api graphql -f query='
119135
mutation (
@@ -134,4 +150,4 @@ jobs:
134150
id
135151
}
136152
}
137-
}' -f project=$PROJECT_ID -f item=$ITEM_ID -f status_field=$STATUS_FIELD_ID -f status_value=${{ env.STATUS_OPTION_ID }} --silent
153+
}' -f project=$PROJECT_ID -f item=$ITEM_ID -f status_field=$STATUS_FIELD_ID -f status_value=$STATUS_OPTION_ID --silent

0 commit comments

Comments
 (0)