From 34c0e65ff4b19104c42d0a79a3392b276c304505 Mon Sep 17 00:00:00 2001 From: Tanish Majumdar <142332924+tanish35@users.noreply.github.com> Date: Mon, 7 Oct 2024 15:41:09 +0530 Subject: [PATCH] Update issue_fetcher.yml --- .github/workflows/issue_fetcher.yml | 38 ++++++++++++++++------------- 1 file changed, 21 insertions(+), 17 deletions(-) diff --git a/.github/workflows/issue_fetcher.yml b/.github/workflows/issue_fetcher.yml index 2bd907c..0b6ab49 100644 --- a/.github/workflows/issue_fetcher.yml +++ b/.github/workflows/issue_fetcher.yml @@ -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"