Reply to issue comments #95
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Reply to issue comments | |
| on: | |
| issue_comment: | |
| types: [created] | |
| permissions: | |
| issues: write | |
| jobs: | |
| reply: | |
| runs-on: ubuntu-latest | |
| if: contains(github.event.comment.body, '@njzjz-bot') | |
| steps: | |
| - uses: actions/checkout@v6 | |
| - name: Extract identifiers | |
| id: extract-identifiers | |
| env: | |
| COMMENT_BODY: ${{ github.event.comment.body }} | |
| shell: bash | |
| run: | | |
| identifiers="$( | |
| printf '%s\n' "$COMMENT_BODY" \ | |
| | grep -oE '@njzjz-bot .*' \ | |
| | head -n1 \ | |
| | cut -c12- \ | |
| | xargs | |
| )" | |
| printf 'identifiers=%s\n' "$identifiers" >> "$GITHUB_OUTPUT" | |
| - name: Run wenxian | |
| id: wenxian | |
| uses: ./ | |
| with: | |
| id: ${{ steps.extract-identifiers.outputs.identifiers }} | |
| - name: Prepare the comment body | |
| id: prepare-comment | |
| env: | |
| COMMENT_USER: ${{ github.event.comment.user.login }} | |
| IDENTIFIERS: ${{ steps.extract-identifiers.outputs.identifiers }} | |
| OUTPUT_BIBTEX: ${{ steps.wenxian.outputs.bibtex }} | |
| shell: bash | |
| run: | | |
| { | |
| echo 'comment<<EOF' | |
| printf '@%s Here is the BibTeX entry for `%s`:\n' "$COMMENT_USER" "$IDENTIFIERS" | |
| echo '```bibtex' | |
| printf '%s\n' "$OUTPUT_BIBTEX" | |
| echo '```' | |
| echo 'EOF' | |
| } >> "$GITHUB_OUTPUT" | |
| - name: Post comment | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| OUTPUT_COMMENT: ${{ steps.prepare-comment.outputs.comment }} | |
| ISSUE_NUMBER: ${{ github.event.issue.number }} | |
| shell: bash | |
| run: | | |
| printf '%s\n' "$OUTPUT_COMMENT" | gh issue comment "$ISSUE_NUMBER" --body-file - |