From 9a56e1fd8e297dd269223ca210234dbddc2450ba Mon Sep 17 00:00:00 2001 From: Abhisek Roy <69287212+abhisek247767@users.noreply.github.com> Date: Sat, 19 Oct 2024 13:47:55 +0530 Subject: [PATCH] Create issue-auto-commenter.yml --- .github/workflows/issue-auto-commenter.yml | 53 ++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 .github/workflows/issue-auto-commenter.yml diff --git a/.github/workflows/issue-auto-commenter.yml b/.github/workflows/issue-auto-commenter.yml new file mode 100644 index 0000000..4b572d3 --- /dev/null +++ b/.github/workflows/issue-auto-commenter.yml @@ -0,0 +1,53 @@ +name: Issue Auto Commenter +on: + issues: + types: [opened] + +env: + OWNER: 'abhisek247767' + REPO: 'Hello-World' + +jobs: + comment: + runs-on: ubuntu-latest + permissions: + issues: write + steps: + - name: Debug info + run: | + echo "Repository: ${{ github.repository }}" + echo "Issue number: ${{ github.event.issue.number }}" + echo "Owner: ${{ env.OWNER }}" + echo "Repo: ${{ env.REPO }}" + - name: Add comment to new issue + uses: actions/github-script@v7 + env: + ISSUE_NUMBER: ${{ github.event.issue.number }} + with: + github-token: ${{secrets.GITHUB_TOKEN}} + script: | + const owner = process.env.OWNER; + const repo = process.env.REPO; + const issue_number = process.env.ISSUE_NUMBER; + + try { + console.log(`Attempting to comment on issue ${issue_number} in ${owner}/${repo}`); + + const result = await github.rest.issues.createComment({ + owner: owner, + repo: repo, + issue_number: parseInt(issue_number), + body: '👋 Thanks for opening this issue! First please star the repository and follow me in github. We appreciate your feedback and will look into it as soon as possible.' + }); + + console.log('API call details:', JSON.stringify({ + method: 'POST', + url: `https://api.github.com/repos/${owner}/${repo}/issues/${issue_number}/comments`, + status: result.status, + data: result.data + }, null, 2)); + + console.log('Comment added successfully.'); + } catch (error) { + core.setFailed(`Action failed with error: ${error.message}`); + }