Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Project automation: Update the option selection to no longer be required #255

Open
wants to merge 3 commits into
base: branch-25.02
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions .github/workflows/project-get-item-id.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,15 @@ jobs:
id: get_item_id
env:
GH_TOKEN: ${{ secrets.ADD_TO_PROJECT_GITHUB_TOKEN }}
ENV_ITEM_NODE_ID: ${{ inputs.ITEM_NODE_ID }}
ENV_PROJECT_ID: ${{ inputs.PROJECT_ID }}
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 }}") {
node(id: "${{ env.ENV_ITEM_NODE_ID }}") {
... on PullRequest {
projectItems(first: 10) {
nodes {
Expand All @@ -73,7 +75,7 @@ jobs:

# Use jq to do the actual filtering
item_project_id=$(jq -r '.data.node.projectItems.nodes[] |
select(.project.id == "${{ inputs.PROJECT_ID }}") |
select(.project.id == "${{ env.ENV_PROJECT_ID }}") |
.id' project_data.json)
echo "ITEM_PROJECT_ID=$item_project_id" >> $GITHUB_OUTPUT
continue-on-error: true
15 changes: 10 additions & 5 deletions .github/workflows/project-get-set-iteration-field.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -64,15 +64,17 @@ jobs:
id: get_iteration_option_id
env:
GH_TOKEN: ${{ secrets.ADD_TO_PROJECT_GITHUB_TOKEN }}
ENV_PROJECT_ID: ${{ inputs.PROJECT_ID }}
ENV_ITERATION_FIELD_NAME: ${{ inputs.ITERATION_FIELD_NAME }}
run: |
# Get current iteration iteration id
# The current iteration is always the first element in the returned list
gh api graphql -f query='
query {
node(id: "${{ inputs.PROJECT_ID }}") {
node(id: "${{ env.ENV_PROJECT_ID }}") {
... on ProjectV2 {
id
field(name: "${{ inputs.ITERATION_FIELD_NAME }}") {
field(name: "${{ env.ENV_ITERATION_FIELD_NAME }}") {
... on ProjectV2IterationField {
id
name
Expand All @@ -94,16 +96,19 @@ jobs:
if: ${{ inputs.UPDATE_ITEM == true }}
env:
GH_TOKEN: ${{ secrets.ADD_TO_PROJECT_GITHUB_TOKEN }}
ENV_PROJECT_ID: ${{ inputs.PROJECT_ID }}
ENV_ITEM_PROJECT_ID: ${{ inputs.ITEM_PROJECT_ID }}
ENV_ITERATION_FIELD_ID: ${{ inputs.ITERATION_FIELD_ID }}
run: |
# Set the iteration based on the query above
# This overwrites whatever was in it before, we may want to make an "OVERWRITE" option
gh api graphql -f query='
mutation {
updateProjectV2ItemFieldValue(
input: {
projectId: "${{ inputs.PROJECT_ID }}"
itemId: "${{ inputs.ITEM_PROJECT_ID }}"
fieldId: "${{ inputs.ITERATION_FIELD_ID }}"
projectId: "${{ env.ENV_PROJECT_ID }}"
itemId: "${{ env.ENV_ITEM_PROJECT_ID }}"
fieldId: "${{ env.ENV_ITERATION_FIELD_ID }}"
value: {
iterationId: "${{ steps.get_iteration_option_id.outputs.ITERATION_OPTION_ID }}"
}
Expand Down
65 changes: 46 additions & 19 deletions .github/workflows/project-get-set-single-select-field.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,6 @@ on:
type: string
required: true

SINGLE_SELECT_OPTION_VALUE:
description: "The value of the option we'd like to get/set"
type: string
required: true

SINGLE_SELECT_FIELD_ID:
description: "The graphQL node ID of the single-select field"
type: string
Expand All @@ -46,6 +41,12 @@ on:
default: false
type: boolean

# Optional, if not specified, we default to the first option in the selector
SINGLE_SELECT_OPTION_VALUE:
description: "The value of the option we'd like to get/set"
type: string
default: null

secrets:
ADD_TO_PROJECT_GITHUB_TOKEN:
description: "Project Access Token"
Expand All @@ -69,22 +70,45 @@ jobs:
id: get_single_select_option_id
env:
GH_TOKEN: ${{ secrets.ADD_TO_PROJECT_GITHUB_TOKEN }}
ENV_SINGLE_SELECT_OPTION_VALUE: ${{ inputs.SINGLE_SELECT_OPTION_VALUE }}
ENV_PROJECT_ID: ${{ inputs.PROJECT_ID }}
ENV_SINGLE_SELECT_FIELD_NAME: ${{ inputs.SINGLE_SELECT_FIELD_NAME }}
run: |
# Get single_select option id
gh api graphql -f query='
query {
node(id: "${{ inputs.PROJECT_ID }}") {
... on ProjectV2 {
id
field(name: "${{ inputs.SINGLE_SELECT_FIELD_NAME }}") {
... on ProjectV2SingleSelectField {
if [ -z "${{ env.ENV_SINGLE_SELECT_OPTION_VALUE }}" ]; then
# No option specified, we will get the first option in the list
# graphQL doesn't appear to provide a wildcard option, so separate queries are necessary
gh api graphql -f query='
query {
node(id: "${{ env.ENV_PROJECT_ID }}") {
... on ProjectV2 {
id
options(names: "${{ inputs.SINGLE_SELECT_OPTION_VALUE }}") {id}
field(name: "${{ env.ENV_SINGLE_SELECT_FIELD_NAME }}") {
... on ProjectV2SingleSelectField {
id
options {id}
}
}
}
}
}
}
}' > single_select_option_data.json
}' > single_select_option_data.json
else
# Get the specific value only
gh api graphql -f query='
query {
node(id: "${{ env.ENV_PROJECT_ID }}") {
... on ProjectV2 {
id
field(name: "${{ env.ENV_SINGLE_SELECT_FIELD_NAME }}") {
... on ProjectV2SingleSelectField {
id
options(names: "${{ env.ENV_SINGLE_SELECT_OPTION_VALUE }}") {id}
}
}
}
}
}' > single_select_option_data.json
fi
current_single_select_option_id=$(jq -r '.data.node.field.options[0].id' single_select_option_data.json)
echo "SINGLE_SELECT_OPTION_ID=$current_single_select_option_id" >> "$GITHUB_OUTPUT"

Expand All @@ -93,16 +117,19 @@ jobs:
if: ${{ inputs.UPDATE_ITEM == true }}
env:
GH_TOKEN: ${{ secrets.ADD_TO_PROJECT_GITHUB_TOKEN }}
ENV_PROJECT_ID: ${{ inputs.PROJECT_ID }}
ENV_ITEM_PROJECT_ID: ${{ inputs.ITEM_PROJECT_ID }}
ENV_SINGLE_SELECT_FIELD_ID: ${{ inputs.SINGLE_SELECT_FIELD_ID }}
run: |
# Set the single_select based on the query above
# This overwrites whatever was in it before, we may want to make an "OVERWRITE" option
gh api graphql -f query='
mutation {
updateProjectV2ItemFieldValue(
input: {
projectId: "${{ inputs.PROJECT_ID }}"
itemId: "${{ inputs.ITEM_PROJECT_ID }}"
fieldId: "${{ inputs.SINGLE_SELECT_FIELD_ID }}"
projectId: "${{ env.ENV_PROJECT_ID }}"
itemId: "${{ env.ENV_ITEM_PROJECT_ID }}"
fieldId: "${{ env.ENV_SINGLE_SELECT_FIELD_ID }}"
value: {
singleSelectOptionId: "${{ steps.get_single_select_option_id.outputs.SINGLE_SELECT_OPTION_ID }}"
}
Expand Down
27 changes: 16 additions & 11 deletions .github/workflows/project-set-text-date-numeric-field.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -58,19 +58,24 @@ jobs:
id: update_item_text_date_numeric_field
env:
GH_TOKEN: ${{ secrets.ADD_TO_PROJECT_GITHUB_TOKEN }}
ENV_FIELD_TYPE: ${{ inputs.FIELD_TYPE }}
ENV_PROJECT_ID: ${{ inputs.PROJECT_ID }}
ENV_ITEM_PROJECT_ID: ${{ inputs.ITEM_PROJECT_ID }}
ENV_FIELD_ID: ${{ inputs.FIELD_ID }}
ENV_SET_VALUE: ${{ inputs.SET_VALUE }}
run: |
# Set the field based on the inputted desired value
# This overwrites whatever was in it before, we may want to make an "OVERWRITE" option
if [ "${{ inputs.FIELD_TYPE }}" == "date" ] || \
[ "${{ inputs.FIELD_TYPE }}" == "text" ]; then
if [ "${{ env.ENV_FIELD_TYPE }}" == "date" ] || \
[ "${{ env.ENV_FIELD_TYPE }}" == "text" ]; then
gh api graphql -f query="
mutation {
updateProjectV2ItemFieldValue(
input: {
projectId: \"${{ inputs.PROJECT_ID }}\"
itemId: \"${{ inputs.ITEM_PROJECT_ID }}\"
fieldId: \"${{ inputs.FIELD_ID }}\"
value: { ${{ inputs.FIELD_TYPE }}: \"${{ inputs.SET_VALUE }}\" }
projectId: \"${{ env.ENV_PROJECT_ID }}\"
itemId: \"${{ env.ENV_ITEM_PROJECT_ID }}\"
fieldId: \"${{ env.ENV_FIELD_ID }}\"
value: { ${{ env.ENV_FIELD_TYPE }}: \"${{ env.ENV_SET_VALUE }}\" }
}
) {
projectV2Item {
Expand All @@ -79,15 +84,15 @@ jobs:
}
}"

elif [ "${{ inputs.FIELD_TYPE }}" == "number" ]; then
elif [ "${{ env.ENV_FIELD_TYPE }}" == "number" ]; then
gh api graphql -f query="
mutation {
updateProjectV2ItemFieldValue(
input: {
projectId: \"${{ inputs.PROJECT_ID }}\"
itemId: \"${{ inputs.ITEM_PROJECT_ID }}\"
fieldId: \"${{ inputs.FIELD_ID }}\"
value: { ${{ inputs.FIELD_TYPE }}: ${{ inputs.SET_VALUE }} }
projectId: \"${{ env.ENV_PROJECT_ID }}\"
itemId: \"${{ env.ENV_ITEM_PROJECT_ID }}\"
fieldId: \"${{ env.ENV_FIELD_ID }}\"
value: { ${{ env.ENV_FIELD_TYPE }}: ${{ env.ENV_SET_VALUE }} }
}
) {
projectV2Item {
Expand Down
43 changes: 24 additions & 19 deletions .github/workflows/project-update-linked-issues.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,18 @@ jobs:
id: sync_linked_issues
env:
GITHUB_TOKEN: ${{ secrets.ADD_TO_PROJECT_GITHUB_TOKEN }}
ENV_PR_NODE_ID: ${{ inputs.PR_NODE_ID }}
ENV_PROJECT_ID: ${{ inputs.PROJECT_ID }}
ENV_UPDATE_FIELD_TYPE: ${{ inputs.UPDATE_FIELD_TYPE }}
ENV_UPDATE_FIELD_ID: ${{ inputs.UPDATE_FIELD_ID }}
ENV_UPDATE_FIELD_VALUE: ${{ inputs.UPDATE_FIELD_VALUE }}
run: |
# Find the linked issues to the PR
# If an issue is passed in, the json will return null and the for loop won't trigger
# Potential future improvement could be some nicer error messaging on incorrect input
gh api graphql -f query='
query {
node(id: "${{ inputs.PR_NODE_ID }}") {
node(id: "${{ env.ENV_PR_NODE_ID }}") {
... on PullRequest {
closingIssuesReferences(first: 10) {
nodes {
Expand All @@ -73,43 +78,43 @@ jobs:
}
}' > linked_issues.json
issue_ids=$(jq -r '.data.node.closingIssuesReferences.nodes[].projectItems.nodes[] |
select(.project.id == "${{ inputs.PROJECT_ID }}") | .id' linked_issues.json)
select(.project.id == "${{ env.ENV_PROJECT_ID }}") | .id' linked_issues.json)

for issue_id in $issue_ids; do
# Each field type has a different `value` that is needed by the mutation.

if [ "${{ inputs.UPDATE_FIELD_TYPE }}" == "iteration" ]; then
if [ "${{ env.ENV_UPDATE_FIELD_TYPE }}" == "iteration" ]; then
gh api graphql -f query='
mutation {
updateProjectV2ItemFieldValue(
input: {
projectId: "${{ inputs.PROJECT_ID }}"
projectId: "${{ env.ENV_PROJECT_ID }}"
itemId: "'"$issue_id"'"
fieldId: "${{ inputs.UPDATE_FIELD_ID }}"
value: {iterationId: "${{ inputs.UPDATE_FIELD_VALUE }}"}})
fieldId: "${{ env.ENV_UPDATE_FIELD_ID }}"
value: {iterationId: "${{ env.ENV_UPDATE_FIELD_VALUE }}"}})
{projectV2Item {id}}}'

elif [ "${{ inputs.UPDATE_FIELD_TYPE }}" == "single_select" ]; then
elif [ "${{ env.ENV_UPDATE_FIELD_TYPE }}" == "single_select" ]; then
gh api graphql -f query='
mutation {
updateProjectV2ItemFieldValue(
input: {
projectId: "${{ inputs.PROJECT_ID }}"
projectId: "${{ env.ENV_PROJECT_ID }}"
itemId: "'"$issue_id"'"
fieldId: "${{ inputs.UPDATE_FIELD_ID }}"
value: {singleSelectOptionId: "${{ inputs.UPDATE_FIELD_VALUE }}"}})
fieldId: "${{ env.ENV_UPDATE_FIELD_ID }}"
value: {singleSelectOptionId: "${{ env.ENV_UPDATE_FIELD_VALUE }}"}})
{projectV2Item {id}}}'

elif [ "${{ inputs.UPDATE_FIELD_TYPE }}" == "date" ] || \
[ "${{ inputs.UPDATE_FIELD_TYPE }}" == "text" ]; then
elif [ "${{ env.ENV_UPDATE_FIELD_TYPE }}" == "date" ] || \
[ "${{ env.ENV_UPDATE_FIELD_TYPE }}" == "text" ]; then
gh api graphql -f query="
mutation {
updateProjectV2ItemFieldValue(
input: {
projectId: \"${{ inputs.PROJECT_ID }}\"
projectId: \"${{ env.ENV_PROJECT_ID }}\"
itemId: \"$issue_id\"
fieldId: \"${{ inputs.UPDATE_FIELD_ID }}\"
value: {${{ inputs.UPDATE_FIELD_TYPE }}: \"${{ inputs.UPDATE_FIELD_VALUE }}\"}
fieldId: \"${{ env.ENV_UPDATE_FIELD_ID }}\"
value: {${{ env.ENV_UPDATE_FIELD_TYPE }}: \"${{ env.ENV_UPDATE_FIELD_VALUE }}\"}
}
) {
projectV2Item {
Expand All @@ -118,15 +123,15 @@ jobs:
}
}"

elif [ "${{ inputs.UPDATE_FIELD_TYPE }}" == "number" ]; then
elif [ "${{ env.ENV_UPDATE_FIELD_TYPE }}" == "number" ]; then
gh api graphql -f query="
mutation {
updateProjectV2ItemFieldValue(
input: {
projectId: \"${{ inputs.PROJECT_ID }}\"
projectId: \"${{ env.ENV_PROJECT_ID }}\"
itemId: \"$issue_id\"
fieldId: \"${{ inputs.UPDATE_FIELD_ID }}\"
value: {${{ inputs.UPDATE_FIELD_TYPE }}: ${{ inputs.UPDATE_FIELD_VALUE }}}}
fieldId: \"${{ env.ENV_UPDATE_FIELD_ID }}\"
value: {${{ env.ENV_UPDATE_FIELD_TYPE }}: ${{ env.ENV_UPDATE_FIELD_VALUE }}}}
) {projectV2Item {id}}}"

else
Expand Down