Skip to content

Test dashboards squad action #314

Test dashboards squad action

Test dashboards squad action #314

name: When epic issues changed, check if part of specified child projects and update on specified parent project
on:
issues:
types: [opened, edited, reopened, assigned, unassigned, labeled, unlabeled]
labels:
- 'type/epic'
env:
GITHUB_TOKEN: ${{ secrets.GH_BOT_ACCESS_TOKEN }}
ORGANIZATION: ${{ github.repository_owner }}
REPO: ${{ github.event.repository.name }}
PARENT_PROJECT: 313
CHILD_PROJECT_1: 312
CHILD_PROJECT_2: 316
concurrency:
group: issue-add-to-parent-project-${{ github.event.number }}
jobs:
main:
if: contains(github.event.issue.labels.*.name, 'type/epic')
runs-on: ubuntu-latest
steps:
- name: Check if issue is in child or parent projects
run: |
gh api graphql -f query='
query($org: String!, $repo: String!) {
repository(name: $repo, owner: $org) {
issue (number: ${{ github.event.issue.number }}) {
projectItems(first:20) {
nodes {
id,
project {
number,
title
},
fieldValueByName(name:"Status") {
... on ProjectV2ItemFieldSingleSelectValue {
optionId
name
}
}
}
}
}
}
}' -f org=$ORGANIZATION -f repo=$REPO > projects_data.json
echo 'IN_PARENT_PROJ='$(jq '.data.repository.issue.projectItems.nodes[] | select(.project.number==${{ env.PARENT_PROJECT }}) | .project != null' projects_data.json) >> $GITHUB_ENV
echo 'PARENT_PROJ_STATUS_ID='$(jq '.data.repository.issue.projectItems.nodes[] | select(.project.number==${{ env.PARENT_PROJECT }}) | select(.fieldValueByName != null) | .fieldValueByName.optionId' projects_data.json) >> $GITHUB_ENV
echo 'ITEM_ID='$(jq '.data.repository.issue.projectItems.nodes[] | select(.project.number==${{ env.PARENT_PROJECT }}) | .id' projects_data.json) >> $GITHUB_ENV
echo 'IN_CHILD_PROJ='$(jq 'first(.data.repository.issue.projectItems.nodes[] | select(.project.number==${{ env.CHILD_PROJECT_1 }} or .project.number==${{ env.CHILD_PROJECT_2 }}) | .project != null)' projects_data.json) >> $GITHUB_ENV
echo 'CHILD_PROJ_STATUS='$(jq -r '.data.repository.issue.projectItems.nodes[] | select(.project.number==${{ env.CHILD_PROJECT_1 }} or .project.number==${{ env.CHILD_PROJECT_2 }}) | select(.fieldValueByName != null) | .fieldValueByName.name' projects_data.json) >> $GITHUB_ENV
- name: Get parent project project data
if: env.IN_CHILD_PROJ
run: |
gh api graphql -f query='
query($org: String!, $number: Int!) {
organization(login: $org){
projectV2(number: $number) {
id
fields(first:20) {
nodes {
... on ProjectV2Field {
id
name
}
... on ProjectV2SingleSelectField {
id
name
options {
id
name
}
}
}
}
}
}
}' -f org=$ORGANIZATION -F number=$PARENT_PROJECT > project_data.json
echo 'PROJECT_ID='$(jq '.data.organization.projectV2.id' project_data.json) >> $GITHUB_ENV
echo 'STATUS_FIELD_ID='$(jq '.data.organization.projectV2.fields.nodes[] | select(.name== "Status") | .id' project_data.json) >> $GITHUB_ENV
echo 'TODO_OPTION_ID='$(jq '.data.organization.projectV2.fields.nodes[] | select(.name== "Status") | .options[] | select(.name=="Todo") |.id' project_data.json) >> $GITHUB_ENV
echo 'PROGRESS_OPTION_ID='$(jq '.data.organization.projectV2.fields.nodes[] | select(.name== "Status") | .options[] | select(.name=="In Progress") |.id' project_data.json) >> $GITHUB_ENV
echo 'DONE_OPTION_ID='$(jq '.data.organization.projectV2.fields.nodes[] | select(.name== "Status") | .options[] | select(.name=="Done") |.id' project_data.json) >> $GITHUB_ENV
- name: Add issue to parent project
if: env.IN_CHILD_PROJ && !env.IN_PARENT_PROJ
run: |
item_id="$( gh api graphql -f query='
mutation($project:ID!, $issue:ID!) {
addProjectV2ItemById(input: {projectId: $project, contentId: $issue}) {
item {
id
}
}
}' -f project=$PROJECT_ID -f issue=${{ github.event.issue.node_id }} --jq '.data.addProjectV2ItemById.item.id')"
echo 'ITEM_ID='$item_id >> $GITHUB_ENV
- name: Set parent project status Done
if: contains(env.CHILD_PROJ_STATUS, 'Done')
run: |
echo 'OPTION_ID='$DONE_OPTION_ID >> $GITHUB_ENV
- name: Set parent project status In Progress
if: contains(env.CHILD_PROJ_STATUS, 'In ') || contains(env.CHILD_PROJ_STATUS, 'Blocked')
run: |
echo 'OPTION_ID='$PROGRESS_OPTION_ID >> $GITHUB_ENV
- name: Set parent project status To do
if: env.CHILD_PROJ_STATUS && !contains(env.CHILD_PROJ_STATUS, 'In ') && !contains(env.CHILD_PROJ_STATUS, 'Blocked') && ! contains(env.CHILD_PROJ_STATUS, 'Done')
run: |
echo 'OPTION_ID='$TODO_OPTION_ID >> $GITHUB_ENV
- name: Set issue status in parent project
if: env.OPTION_ID && (env.OPTION_ID != env.PARENT_PROJ_STATUS_ID)
run: |
gh api graphql -f query='
mutation (
$project: ID!
$item: ID!
$status_field: ID!
$status_value: String!
) {
set_status: updateProjectV2ItemFieldValue(input: {
projectId: $project
itemId: $item
fieldId: $status_field
value: {
singleSelectOptionId: $status_value
}
}) {
projectV2Item {
id
}
}
}' -f project=$PROJECT_ID -f item=$ITEM_ID -f status_field=$STATUS_FIELD_ID -f status_value=${{ env.OPTION_ID }} --silent