diff --git a/.github/workflows/issue_parser.yaml b/.github/workflows/issue_parser.yaml deleted file mode 100644 index 4ffe81f..0000000 --- a/.github/workflows/issue_parser.yaml +++ /dev/null @@ -1,19 +0,0 @@ -on: - issue_comment: - types: [created, edited] - -jobs: - parse-comment: - runs-on: ubuntu-latest - name: Parse Comment - steps: - - name: Issue Refs Parser Action - uses: FujiHaruka/issue-refs-parser-action@v1.1 - id: action - with: - body: ${{ github.event.comment.body }} - self_slug: hugo-toha/toha - - name: Get The Outputs - run: | - echo "refs: ${{ steps.action.outputs.refs }}" - echo "external_refs: ${{ steps.action.outputs.external_refs }}" diff --git a/.github/workflows/project-automation-pr.yaml b/.github/workflows/project-automation-pr.yaml index 41b026a..9d80589 100644 --- a/.github/workflows/project-automation-pr.yaml +++ b/.github/workflows/project-automation-pr.yaml @@ -9,6 +9,7 @@ on: - closed - labeled - unlabeled + - synchronize jobs: pr_automation: runs-on: ubuntu-latest @@ -148,6 +149,9 @@ jobs: OPTION_ID=$STATUS_IN_PROGRESS fi + # Expose the OPTION_ID so that it can be used in later steps + echo 'PR_STATUS='$OPTION_ID >> $GITHUB_ENV + gh api graphql -f query=' mutation ($project: ID!, $item: ID!, $field: ID!, $status_id: ID!) { updateProjectNextItemField(input: { @@ -161,3 +165,55 @@ jobs: } } }' -f project="$PROJECT_ID" -f item="$ITEM_ID" -f field="$STATUS_ID" -f status_id="$OPTION_ID" --silent + + - name: Find Linked Issues + id: linked_issues + uses: hossainemruz/linked-issues@main + with: + pr_url: ${{github.event.pull_request.html_url}} + format: IssueNumber + + - name: Update Linked Issues Status + env: + GITHUB_TOKEN: ${{secrets.PROJECT_AUTOMATION}} + run: | + declare -a issues=(${{ steps.linked_issues.outputs.issues }}) + + # Loop through the every issues and update their Status to same as the PR Status + for i in "${issues[@]}" + do + # Find the Issue ID + ISSUE_ID="$(gh api graphql -f query=' + query($owner: String!, $name: String!, $issue_number: Int!) { + repository(owner: $owner, name: $name) { + issue(number: $issue_number) { + id + } + } + }' -f owner="${{github.event.pull_request.head.repo.owner.login}}" -f name="${{github.event.pull_request.head.repo.name}}" -F issue_number=$i --jq='.data.repository.issue.id')" + + # Find the id of the Issue at the project board + item_id="$( gh api graphql -f query=' + mutation($project:ID!, $pr:ID!) { + addProjectNextItem(input: {projectId: $project, contentId: $pr}) { + projectNextItem { + id + } + } + }' -f project="$PROJECT_ID" -f pr="$ISSUE_ID" --jq '.data.addProjectNextItem.projectNextItem.id')" + + # Update the Issue Status + gh api graphql -f query=' + mutation ($project: ID!, $item: ID!, $field: ID!, $status_id: ID!) { + updateProjectNextItemField(input: { + projectId: $project + itemId: $item + fieldId: $field + value: $status_id + }) { + projectNextItem { + id + } + } + }' -f project="$PROJECT_ID" -f item="$item_id" -f field="$STATUS_ID" -f status_id="$PR_STATUS" --silent + done