Skip to content

Commit

Permalink
action
Browse files Browse the repository at this point in the history
  • Loading branch information
codeallthethingz committed Jan 8, 2025
1 parent 07a95f2 commit a2c0562
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 3 deletions.
50 changes: 50 additions & 0 deletions .github/actions/pin_comment/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
name: "Pin Comment"
description: "Pins a comment by hiding it with HTML comments and a unique ID"

inputs:
message:
description: "The message to pin"
required: true
token:
description: "GitHub token"
required: true
issue_number:
description: "The issue or PR number"
required: true
comment_id:
description: "Unique identifier for this pinned comment"
required: true

runs:
using: "composite"
steps:
- name: Pin comment
shell: bash
env:
GH_TOKEN: ${{ inputs.token }}
MESSAGE: ${{ inputs.message }}
ISSUE_NUMBER: ${{ inputs.issue_number }}
COMMENT_ID: ${{ inputs.comment_id }}
run: |
# Create comment with hidden marker and ID
COMMENT="<!--pin-comment-marker-${COMMENT_ID}-->
${MESSAGE}"
# Find and delete old comment with same ID
gh api graphql -f query='
query($owner:String!, $repo:String!, $number:Int!) {
repository(owner:$owner, name:$repo) {
issueOrPullRequest(number:$number) {
... on Issue { comments(first:100) { nodes { id body } } }
... on PullRequest { comments(first:100) { nodes { id body } } }
}
}
}' -f owner="${GITHUB_REPOSITORY%/*}" -f repo="${GITHUB_REPOSITORY#*/}" -f number="${ISSUE_NUMBER}" |
jq -r ".data.repository.issueOrPullRequest.comments.nodes[] | select(.body | startswith(\"<!--pin-comment-marker-${COMMENT_ID}-->\")) | .id" |
while read -r comment_id; do
gh api --method DELETE "/graphql" -f query="mutation { deleteIssueComment(input: {id: \"$comment_id\"}) { clientMutationId } }"
done
# Create new pinned comment
gh issue comment "${ISSUE_NUMBER}" --body "${COMMENT}"
15 changes: 12 additions & 3 deletions .github/workflows/docs-preview.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,11 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Create initial PR comment
uses: marocchino/sticky-pull-request-comment@v2
uses: ./.github/actions/pin_comment
with:
token: ${{ secrets.GITHUB_TOKEN }}
issue_number: ${{ github.event.pull_request.number }}
comment_id: docs-preview
message: |
📚 **Documentation Preview**
Expand Down Expand Up @@ -81,8 +84,11 @@ jobs:
python -m tools.github_readme_sync.cli upload docs "${VERSION}-${BRANCH_NAME}"
- name: Update PR comment on success
if: success()
uses: marocchino/sticky-pull-request-comment@v2
uses: ./.github/actions/pin_comment
with:
token: ${{ secrets.GITHUB_TOKEN }}
issue_number: ${{ github.event.pull_request.number }}
comment_id: docs-preview
message: |
📚 **Documentation Preview**
Expand All @@ -92,8 +98,11 @@ jobs:
Last updated: ${{ env.DATE }}
- name: Update PR comment on failure
if: failure()
uses: marocchino/sticky-pull-request-comment@v2
uses: ./.github/actions/pin_comment
with:
token: ${{ secrets.GITHUB_TOKEN }}
issue_number: ${{ github.event.pull_request.number }}
comment_id: docs-preview
message: |
📚 **Documentation Preview**
Expand Down

0 comments on commit a2c0562

Please sign in to comment.