Skip to content

Commit

Permalink
Update issue_fetcher.yml
Browse files Browse the repository at this point in the history
  • Loading branch information
tanish35 authored Oct 7, 2024
1 parent 1d90eca commit 34c0e65
Showing 1 changed file with 21 additions and 17 deletions.
38 changes: 21 additions & 17 deletions .github/workflows/issue_fetcher.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,28 +5,32 @@ on:
types: [created]

jobs:
fetch-issue-details:
fetch_issue_details:
runs-on: ubuntu-latest
steps:
- name: Check if comment references an issue
id: check
- name: Checkout repository
uses: actions/checkout@v2

- name: Fetch issue details
id: fetch_issue
run: |
echo "COMMENT_BODY=${{ github.event.comment.body }}" >> $GITHUB_ENV
echo "ISSUE_NUMBER=$(echo '${{ github.event.comment.body }}' | grep -o '#[0-9]*' | tr -d '#')" >> $GITHUB_ENV
if [ -z "${{ env.ISSUE_NUMBER }}" ]; then
echo "No issue reference found." >> $GITHUB_ENV
if [[ "${{ github.event.comment.body }}" =~ ^#[0-9]+$ ]]; then
ISSUE_NUMBER=${{ github.event.comment.body:1 }}
echo "Fetching issue #$ISSUE_NUMBER"
ISSUE_DATA=$(gh issue view $ISSUE_NUMBER --json title,state,body --jq '.')
echo "ISSUE_DATA=$ISSUE_DATA" >> $GITHUB_ENV
else
echo "No valid issue reference found in comment."
exit 0
fi
- name: Fetch issue details
id: fetch_issue
- name: Add comment with issue details
if: env.ISSUE_DATA != ''
run: |
ISSUE_DETAILS=$(gh issue view ${{ env.ISSUE_NUMBER }} --json title,body,state)
echo "ISSUE_DETAILS=${ISSUE_DETAILS}" >> $GITHUB_ENV
TITLE=$(echo $ISSUE_DATA | jq -r '.title')
STATE=$(echo $ISSUE_DATA | jq -r '.state')
BODY=$(echo $ISSUE_DATA | jq -r '.body')
- name: Post issue details as a comment
if: success() && env.ISSUE_NUMBER != ''
run: |
gh issue comment ${{ github.event.issue.number }} --body "Issue #${{ env.ISSUE_NUMBER }} Details:\n\nTitle: ${{ fromJson(env.ISSUE_DETAILS).title }}\n\nState: ${{ fromJson(env.ISSUE_DETAILS).state }}\n\nDescription:\n\n${{ fromJson(env.ISSUE_DETAILS).body }}"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
COMMENT="### Issue Details\n\n**Title:** $TITLE\n**State:** $STATE\n**Description:** $BODY"
echo "Adding comment with issue details..."
gh issue comment ${{ github.event.issue.number }} --body "$COMMENT"

0 comments on commit 34c0e65

Please sign in to comment.