From 184a4bf4c62be2fb21b6f571415d65a06eef055a Mon Sep 17 00:00:00 2001 From: Yogesh Ojha Date: Sat, 31 Aug 2024 13:34:53 +0530 Subject: [PATCH 1/4] use pat token for workflow comment --- .github/workflows/auto-comment.yml | 78 +++++++++++++++++------------- 1 file changed, 44 insertions(+), 34 deletions(-) diff --git a/.github/workflows/auto-comment.yml b/.github/workflows/auto-comment.yml index 98cb3c02a..b2fc49f4f 100644 --- a/.github/workflows/auto-comment.yml +++ b/.github/workflows/auto-comment.yml @@ -6,10 +6,6 @@ on: pull_request: types: [opened, closed] -permissions: - issues: write - pull-requests: write - jobs: auto_comment: runs-on: ubuntu-latest @@ -17,12 +13,29 @@ jobs: - name: πŸ€– Auto Comment on Issues and PRs uses: actions/github-script@v7 with: - github-token: ${{secrets.GITHUB_TOKEN}} + github-token: ${{ secrets.PAT_TOKEN }} script: | const { owner, repo } = context.repo; const author = context.payload.sender.login; + async function createComment(issueNumber, body) { + try { + await github.rest.issues.createComment({ + owner, + repo, + issue_number: issueNumber, + body: body + }); + console.log(`Comment created successfully for ${context.eventName} #${issueNumber}`); + } catch (error) { + console.error(`Error creating comment for ${context.eventName} #${issueNumber}:`, error); + core.setFailed(`Failed to create comment: ${error.message}`); + } + } + try { + console.log('Event details:', JSON.stringify(context.payload, null, 2)); + if (context.eventName === 'issues' && context.payload.action === 'opened') { const issue = await github.rest.issues.get({ owner, @@ -30,7 +43,8 @@ jobs: issue_number: context.issue.number }); - const isFeatureRequest = issue.data.title.toLowerCase().includes('feat'); + const isFeatureRequest = issue.data.title.toLowerCase().includes('feature request') || + issue.data.body.toLowerCase().includes('feature request'); let commentBody; if (isFeatureRequest) { @@ -54,37 +68,33 @@ jobs: πŸ“ Provided us all the details related to this bug`; } - await github.rest.issues.createComment({ - issue_number: context.issue.number, - owner, - repo, - body: commentBody - }); - } else if (context.eventName === 'pull_request' && context.payload.action === 'opened') { - await github.rest.issues.createComment({ - issue_number: context.issue.number, - owner, - repo, - body: `Woohoo @${author}! πŸŽ‰ You've just dropped some hot new code! πŸ”₯ + await createComment(context.issue.number, commentBody); + } else if (context.eventName === 'pull_request') { + console.log('Processing pull request event'); + const prNumber = context.payload.pull_request.number; + let commentBody; + + if (context.payload.action === 'opened') { + commentBody = `Woohoo @${author}! πŸŽ‰ You've just dropped some hot new code!!! πŸ”₯ - Hang tight while we review this! You rock! 🀘` - }); - } else if (context.eventName === 'pull_request' && context.payload.action === 'closed') { - await github.rest.issues.createComment({ - issue_number: context.issue.number, - owner, - repo, - body: `Holy smokes, @${author}! 🀯 You've just made reNgine even more awesome! + Hang tight while we review this! You rock! 🀘`; + } else if (context.payload.action === 'closed') { + commentBody = `Holy smokes, @${author}! 🀯 You've just made reNgine even more awesome! - Your code is now part of the reNgine hall of fame. πŸ† - - Keep the cool ideas coming - maybe next time you'll break the internet! πŸ’»πŸ’₯ + Your code is now part of the reNgine hall of fame. πŸ† + + Keep the cool ideas coming - maybe next time you'll break the internet! πŸ’»πŸ’₯ - Virtual high fives all around! πŸ™Œ` - }); + Virtual high fives all around! πŸ™Œ`; + } + + if (commentBody) { + await createComment(prNumber, commentBody); + } else { + console.log(`No action taken for pull request ${context.payload.action} event`); + } } - console.log('Comment created successfully'); } catch (error) { - console.error('Error creating comment:', error); - core.setFailed(`Action failed with error: ${error}`); + console.error('Error in workflow:', error); + core.setFailed(`Workflow failed with error: ${error.message}`); } \ No newline at end of file From bdf3e0a28d0e808c7f4556e3262c5b2ede8997c2 Mon Sep 17 00:00:00 2001 From: Yogesh Ojha Date: Sat, 31 Aug 2024 13:38:12 +0530 Subject: [PATCH 2/4] remove personal account comment --- .github/workflows/auto-comment.yml | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/.github/workflows/auto-comment.yml b/.github/workflows/auto-comment.yml index b2fc49f4f..fe9c54a3d 100644 --- a/.github/workflows/auto-comment.yml +++ b/.github/workflows/auto-comment.yml @@ -6,26 +6,40 @@ on: pull_request: types: [opened, closed] +permissions: + issues: write + pull-requests: write + jobs: auto_comment: runs-on: ubuntu-latest steps: + - name: Dump GitHub context + env: + GITHUB_CONTEXT: ${{ toJson(github) }} + run: echo "$GITHUB_CONTEXT" + - name: πŸ€– Auto Comment on Issues and PRs uses: actions/github-script@v7 with: - github-token: ${{ secrets.PAT_TOKEN }} + github-token: ${{ secrets.GITHUB_TOKEN }} script: | const { owner, repo } = context.repo; const author = context.payload.sender.login; + console.log('Current actor:', context.actor); + console.log('Event name:', context.eventName); + console.log('Action:', context.payload.action); + async function createComment(issueNumber, body) { try { - await github.rest.issues.createComment({ + const response = await github.rest.issues.createComment({ owner, repo, issue_number: issueNumber, body: body }); + console.log('Comment created by:', response.data.user.login); console.log(`Comment created successfully for ${context.eventName} #${issueNumber}`); } catch (error) { console.error(`Error creating comment for ${context.eventName} #${issueNumber}:`, error); @@ -34,8 +48,6 @@ jobs: } try { - console.log('Event details:', JSON.stringify(context.payload, null, 2)); - if (context.eventName === 'issues' && context.payload.action === 'opened') { const issue = await github.rest.issues.get({ owner, @@ -70,12 +82,11 @@ jobs: await createComment(context.issue.number, commentBody); } else if (context.eventName === 'pull_request') { - console.log('Processing pull request event'); const prNumber = context.payload.pull_request.number; let commentBody; if (context.payload.action === 'opened') { - commentBody = `Woohoo @${author}! πŸŽ‰ You've just dropped some hot new code!!! πŸ”₯ + commentBody = `Woohoo @${author}! πŸŽ‰ You've just dropped some hot new code! πŸ”₯ Hang tight while we review this! You rock! 🀘`; } else if (context.payload.action === 'closed') { From eb0fbc0ba96bda18e4ac23042958f6e5984f9f71 Mon Sep 17 00:00:00 2001 From: Yogesh Ojha Date: Sat, 31 Aug 2024 13:49:43 +0530 Subject: [PATCH 3/4] fix comment on fork --- .github/workflows/auto-comment.yml | 143 +++++++++++++---------------- 1 file changed, 64 insertions(+), 79 deletions(-) diff --git a/.github/workflows/auto-comment.yml b/.github/workflows/auto-comment.yml index fe9c54a3d..d2a44a24d 100644 --- a/.github/workflows/auto-comment.yml +++ b/.github/workflows/auto-comment.yml @@ -3,7 +3,7 @@ name: πŸ’¬ Auto Comment on: issues: types: [opened] - pull_request: + pull_request_target: types: [opened, closed] permissions: @@ -14,98 +14,83 @@ jobs: auto_comment: runs-on: ubuntu-latest steps: - - name: Dump GitHub context - env: - GITHUB_CONTEXT: ${{ toJson(github) }} - run: echo "$GITHUB_CONTEXT" - - name: πŸ€– Auto Comment on Issues and PRs uses: actions/github-script@v7 with: - github-token: ${{ secrets.GITHUB_TOKEN }} + github-token: ${{secrets.GITHUB_TOKEN}} script: | const { owner, repo } = context.repo; const author = context.payload.sender.login; - console.log('Current actor:', context.actor); - console.log('Event name:', context.eventName); - console.log('Action:', context.payload.action); + if (context.eventName === 'issues' && context.payload.action === 'opened') { + const issueTitle = context.payload.issue.title.toLowerCase(); + let commentBody; + + if (issueTitle.includes('feat')) { + commentBody = `Hey @${author}! πŸš€ Thanks for this exciting feature idea! + + We love seeing fresh concepts that could take reNgine to the next level. 🌟 - async function createComment(issueNumber, body) { - try { - const response = await github.rest.issues.createComment({ - owner, - repo, - issue_number: issueNumber, - body: body - }); - console.log('Comment created by:', response.data.user.login); - console.log(`Comment created successfully for ${context.eventName} #${issueNumber}`); - } catch (error) { - console.error(`Error creating comment for ${context.eventName} #${issueNumber}:`, error); - core.setFailed(`Failed to create comment: ${error.message}`); - } - } + To help us understand your vision better, could you: - try { - if (context.eventName === 'issues' && context.payload.action === 'opened') { - const issue = await github.rest.issues.get({ - owner, - repo, - issue_number: context.issue.number - }); - - const isFeatureRequest = issue.data.title.toLowerCase().includes('feature request') || - issue.data.body.toLowerCase().includes('feature request'); - - let commentBody; - if (isFeatureRequest) { - commentBody = `Hey @${author}! πŸ‘‹ Thanks for your feature request! πŸ’‘ - - We love hearing new ideas from our community. Here's what happens next: - - 1. πŸ“‹ Our team will review your suggestion - 2. πŸ’¬ We might reach out for more details if needed - 3. πŸ” We'll evaluate how it fits with our roadmap - 4. πŸ“’ We'll update you on the status + πŸ“ Provide a detailed description of the feature + 🎯 Explain the problem it solves or the value it adds + πŸ’‘ Share any implementation ideas you might have + + Your input is invaluable in shaping the future of reNgine. Let's innovate together! πŸ’ͺ`; + } else { + commentBody = `Hey @${author}! πŸ‘‹ Thanks for flagging this bug! πŸ›πŸ” - Thanks for helping make reNgine even better! πŸš€`; - } else { - commentBody = `Hey @${author}! πŸ‘‹ Thanks for flagging this! πŸ›πŸž + You're our superhero bug hunter! πŸ¦Έβ€β™‚οΈπŸ¦Έβ€β™€οΈ Before we suit up to squash this bug, could you please: + + πŸ“š Double-check our documentation: https://rengine.wiki + πŸ•΅οΈ Make sure it's not a known issue + πŸ“ Provide all the juicy details about this sneaky bug + + Together, we'll make reNgine bulletproof! πŸ’ͺ`; + } + + github.rest.issues.createComment({ + issue_number: context.issue.number, + owner, + repo, + body: commentBody + }); + } else if (context.eventName === 'pull_request_target' && context.payload.action === 'opened') { + github.rest.issues.createComment({ + issue_number: context.issue.number, + owner, + repo, + body: `Woohoo @${author}! πŸŽ‰ You've just dropped some hot new code! πŸ”₯ - Before we dig in, Let's make sure you have: + Hang tight while we review this! You rock! 🀘` + }); + } else if (context.eventName === 'pull_request_target' && context.payload.action === 'closed') { + const isPRMerged = context.payload.pull_request.merged; + let commentBody; - πŸ” Gone through the documentation: https://rengine.wiki - πŸ•΅οΈ Make sure it's not a known issue - πŸ“ Provided us all the details related to this bug`; - } - - await createComment(context.issue.number, commentBody); - } else if (context.eventName === 'pull_request') { - const prNumber = context.payload.pull_request.number; - let commentBody; - - if (context.payload.action === 'opened') { - commentBody = `Woohoo @${author}! πŸŽ‰ You've just dropped some hot new code! πŸ”₯ + if (isPRMerged) { + commentBody = `Holy smokes, @${author}! 🀯 You've just made reNgine even more awesome! - Hang tight while we review this! You rock! 🀘`; - } else if (context.payload.action === 'closed') { - commentBody = `Holy smokes, @${author}! 🀯 You've just made reNgine even more awesome! + Your code is now part of the reNgine hall of fame. πŸ† + + Keep the cool ideas coming - maybe next time you'll break the internet! πŸ’»πŸ’₯ - Your code is now part of the reNgine hall of fame. πŸ† - - Keep the cool ideas coming - maybe next time you'll break the internet! πŸ’»πŸ’₯ + Virtual high fives all around! πŸ™Œ`; + } else { + commentBody = `Hey @${author}, thanks for your contribution! πŸ™ - Virtual high fives all around! πŸ™Œ`; - } - - if (commentBody) { - await createComment(prNumber, commentBody); - } else { - console.log(`No action taken for pull request ${context.payload.action} event`); - } + We appreciate the time and effort you put into this PR. + + While we couldn't merge it this time, we value your interest in improving reNgine. + + Feel free to reach out if you have any questions. Thanks again! πŸ‘`; } - } catch (error) { - console.error('Error in workflow:', error); - core.setFailed(`Workflow failed with error: ${error.message}`); + + github.rest.issues.createComment({ + issue_number: context.issue.number, + owner, + repo, + body: commentBody + }); } \ No newline at end of file From 12fd79b716904d25a8c8acef35fe79ab3263c2df Mon Sep 17 00:00:00 2001 From: Yogesh Ojha Date: Sat, 31 Aug 2024 13:53:29 +0530 Subject: [PATCH 4/4] update workflow for including PR --- .github/workflows/auto-comment.yml | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/.github/workflows/auto-comment.yml b/.github/workflows/auto-comment.yml index d2a44a24d..be0ccdfdf 100644 --- a/.github/workflows/auto-comment.yml +++ b/.github/workflows/auto-comment.yml @@ -3,6 +3,8 @@ name: πŸ’¬ Auto Comment on: issues: types: [opened] + pull_request: + types: [opened, closed] pull_request_target: types: [opened, closed] @@ -47,7 +49,7 @@ jobs: πŸ•΅οΈ Make sure it's not a known issue πŸ“ Provide all the juicy details about this sneaky bug - Together, we'll make reNgine bulletproof! πŸ’ͺ`; + Once again - thanks for your vigilance! πŸ› οΈπŸš€`; } github.rest.issues.createComment({ @@ -56,7 +58,7 @@ jobs: repo, body: commentBody }); - } else if (context.eventName === 'pull_request_target' && context.payload.action === 'opened') { + } else if ((context.eventName === 'pull_request' || context.eventName === 'pull_request_target') && context.payload.action === 'opened') { github.rest.issues.createComment({ issue_number: context.issue.number, owner, @@ -65,7 +67,7 @@ jobs: Hang tight while we review this! You rock! 🀘` }); - } else if (context.eventName === 'pull_request_target' && context.payload.action === 'closed') { + } else if ((context.eventName === 'pull_request' || context.eventName === 'pull_request_target') && context.payload.action === 'closed') { const isPRMerged = context.payload.pull_request.merged; let commentBody; @@ -80,11 +82,11 @@ jobs: } else { commentBody = `Hey @${author}, thanks for your contribution! πŸ™ - We appreciate the time and effort you put into this PR. + We appreciate the time and effort you put into this PR. Sadly this is not the right fit for reNgine at the moment. While we couldn't merge it this time, we value your interest in improving reNgine. - Feel free to reach out if you have any questions. Thanks again! πŸ‘`; + Feel free to reach out if you have any questions. Thanks again!`; } github.rest.issues.createComment({