diff --git a/.github/actions/create-comment/action.yml b/.github/actions/create-comment/action.yml deleted file mode 100644 index 484f1e5af..000000000 --- a/.github/actions/create-comment/action.yml +++ /dev/null @@ -1,155 +0,0 @@ -name: Create Issue Comment -description: Create or update an issue comment -inputs: - comment: - description: Comment Text - required: true - comment_path: - description: "Path to txt file to be parsed" - required: false - comment_id: - description: "Unique identifier for deduplicating comments" - default: "Create Issue Action" - required: false - issue_number: - description: Local Pull Request/Issue number to work on - required: true - gh_token: - description: gh api access token to use - required: true - repository: - description: the OWNER/REPOSITORY to operate on - default: ${{ github.repository }} - -runs: - using: "composite" - steps: - - name: Generate Comment Text - shell: bash - env: - COMMENT_ID: ${{ inputs.comment_id }} - COMMENT_TEXT: ${{ inputs.comment }} - COMMENT_FILE: ${{ inputs.comment_path }} - run: | - comment_body="${COMMENT_TEXT}" - if [ -f "$COMMENT_FILE" ] ; then - echo "Reading comment file from ${COMMENT_FILE}" - comment_body="${comment_body}$(cat "$COMMENT_FILE")" - fi - echo 'COMMENT_BODY<> "$GITHUB_ENV" - echo "$comment_body" >> "$GITHUB_ENV" - echo 'EOF' >> "$GITHUB_ENV" - - - name: Get Existing Comment Id - shell: bash - env: - GH_TOKEN: ${{ inputs.gh_token }} - ISSUE_NUMBER: ${{ inputs.issue_number }} - REPOSITORY: ${{ inputs.repository }} - COMMENT_ID: ${{ inputs.comment_id }} - run: | - owner=$(echo "$REPOSITORY" | cut -d '/' -f 1) - repo=$(echo "$REPOSITORY" | cut -d '/' -f 2) - data=$( - gh api graphql \ - --paginate \ - --slurp \ - -f owner="$owner" \ - -f repo="$repo" \ - -F issue="$ISSUE_NUMBER" \ - -f query=' - query($repo: String!, $owner: String!, $issue: Int!, $endCursor: String) { - repository(name: $repo, owner: $owner) { - issueOrPullRequest(number: $issue) { - ... on Issue { - id - number - comments(first: 100, after: $endCursor) { - nodes { - id - body - } - pageInfo { - hasNextPage - endCursor - } - } - } - ... on PullRequest { - id - number - comments(first: 100, after: $endCursor) { - nodes { - id - body - } - pageInfo { - hasNextPage - endCursor - } - } - } - } - } - } - ' \ - | jq -c --arg comment_id "" ' - .[0].data.repository.issueOrPullRequest.id as $id | - [ .[].data.repository.issueOrPullRequest.comments.nodes[] ] as $data | - [ $data.[] | select(.body | startswith($comment_id)) ] as $id_comments | - if ($id_comments | length) > 0 then - { "issueId": $id, "commentId": $id_comments[0].id } - else - { "issueId": $id, "commentId": "" } - end - ' - ) - echo "ISSUE_NODE_ID=$(jq -r '.issueId' <<< "$data")" >> "$GITHUB_ENV" - echo "COMMENT_NODE_ID=$(jq -r '.commentId' <<< "$data")" >> "$GITHUB_ENV" - - - name: Edit Existing Comment - if: env.COMMENT_NODE_ID != '' - shell: bash - env: - GH_TOKEN: ${{ inputs.gh_token }} - run: | - gh api graphql \ - -f comment_id="$COMMENT_NODE_ID" \ - -f comment_body="$COMMENT_BODY" \ - -f query=' - mutation($comment_id: ID!, $comment_body: String!) { - updateIssueComment(input: { - id: $comment_id, - body: $comment_body, - }) { - issueComment { - lastEditedAt - } - } - } - ' - - - name: Create Comment - if: env.COMMENT_NODE_ID == '' - shell: bash - env: - GH_TOKEN: ${{ inputs.gh_token }} - run: | - gh api graphql \ - -f issue_id="$ISSUE_NODE_ID" \ - -f comment_body="$COMMENT_BODY" \ - -f query=' - mutation ($issue_id: ID!, $comment_body: String!) { - addComment(input: { subjectId: $issue_id, body: $comment_body }) { - commentEdge { - node { - id - } - } - } - } - ' - - - - diff --git a/.github/workflows/blocked-prs.yml b/.github/workflows/blocked-prs.yml index 4c1840b01..9a6caab7d 100644 --- a/.github/workflows/blocked-prs.yml +++ b/.github/workflows/blocked-prs.yml @@ -27,11 +27,6 @@ jobs: app-id: ${{ vars.PULL_REQUEST_APP_ID }} private-key: ${{ secrets.PULL_REQUEST_APP_PRIVATE_KEY }} - - name: Checkout Default Branch - uses: actions/checkout@v4 - with: - ref: ${{ github.event.repository.default_branch }} - - name: Setup From Dispatch Event if: github.event_name == 'workflow_dispatch' id: dispatch_event_setup @@ -198,15 +193,14 @@ jobs: done < <(jq -c '.[]' <<< "$BLOCKING_DATA") - name: Context Comment - id: blocked_comment + id: generate-comment if: fromJSON(steps.pr_ids.outputs.prs).numBlocking > 0 continue-on-error: true env: BLOCKING_DATA: ${{ steps.blocking_data.outputs.data }} run: | COMMENT_PATH="$(pwd)/temp_comment_file.txt" - touch "$COMMENT_PATH" - echo "" > "$COMMENT_PATH" + echo '

PR Dependencies :pushpin:

' > "$COMMENT_PATH" pr_head_label=$(jq -r '.prHeadLabel' <<< "$JOB_DATA") while read -r pr_data ; do base_pr=$(jq -r '.number' <<< "$pr_data") @@ -218,17 +212,20 @@ jobs: type=$(jq -r '.type' <<< "$pr_data") echo " - $type #$base_pr $status [(compare)]($compare_url)" >> "$COMMENT_PATH" done < <(jq -c '.[]' <<< "$BLOCKING_DATA") - echo "file_path=${COMMENT_PATH}" >> "$GITHUB_OUTPUT" + + echo 'body<> "$GITHUB_OUTPUT" + cat "${COMMENT_PATH}" >> "$GITHUB_OUTPUT" + echo 'EOF' >> "$GITHUB_OUTPUT" - name: 💬 PR Comment if: fromJSON(steps.pr_ids.outputs.prs).numBlocking > 0 continue-on-error: true - uses: ./.github/actions/create-comment - with: - comment: "

PR Dependencies :pushpin:

" - comment_path: ${{ steps.blocked_comment.outputs.file_path }} - comment_id: "block_pr_dependencies" - issue_number: ${{ env.PR_NUMBER }} - repository: ${{ github.repository }} - gh_token: ${{ steps.generate-token.outputs.token }} + env: + GH_TOKEN: ${{ steps.generate-token.outputs.token }} + COMMENT_BODY: ${{ steps.generate-comment.outputs.body }} + run: | + gh -R ${{ github.repository }} issue comment "$PR_NUMBER" \ + --body "$COMMENT_BODY" \ + --create-if-none \ + --edit-last