From 7f360770b94cd5ea6f17351ae5d12fddbda678c4 Mon Sep 17 00:00:00 2001 From: Sugam Arora Date: Mon, 3 Jun 2024 16:00:19 +0530 Subject: [PATCH] Templates --- .../workflows/auto-comment-issue-close.yml | 35 ++++++--- .../workflows/auto-comment-issue-creation.yml | 2 +- .github/workflows/auto-comment-pr-created.yml | 2 +- ...ose-old-issue.yml => close-old-issues.yml} | 74 +++++++++---------- .../{close-old-pr.yml => close-old-prs.yml} | 64 ++++++++-------- 5 files changed, 95 insertions(+), 82 deletions(-) rename .github/workflows/{close-old-issue.yml => close-old-issues.yml} (97%) rename .github/workflows/{close-old-pr.yml => close-old-prs.yml} (93%) diff --git a/.github/workflows/auto-comment-issue-close.yml b/.github/workflows/auto-comment-issue-close.yml index 7e126c68..8459e22a 100644 --- a/.github/workflows/auto-comment-issue-close.yml +++ b/.github/workflows/auto-comment-issue-close.yml @@ -1,4 +1,4 @@ -name: Comment on Issue Close +name: Auto Comment on Issue Close on: issues: @@ -16,16 +16,29 @@ jobs: github-token: ${{ secrets.GITHUB_TOKEN }} script: | const issue = context.payload.issue; - const issueCreator = issue.user.login; - const issueNumber = issue.number; - const greetingMessage = `Hello @${issueCreator}! Your issue **#${issueNumber} - ${issueTitle}** has been successfully closed. We appreciate your valuable contribution and your help in improving the project. If you have any more ideas, questions, or issues, feel free to open a new issue or join the discussion in our community forum. + // Check if the event is for an issue (not a pull request) + if (!issue.pull_request) { + const issueCreator = issue.user.login; + const issueNumber = issue.number; + const issueTitle = issue.title; - Stay awesome! 😊`; + const greetingMessage = ` + Hello @${issueCreator}! 🎉 - github.rest.issues.createComment({ - owner: context.repo.owner, - repo: context.repo.repo, - issue_number: issueNumber, - body: greetingMessage - }); \ No newline at end of file + Your issue **#${issueNumber} - ${issueTitle}** has been successfully closed. + + We appreciate your valuable contribution and your help in improving the project. If you have any more ideas, questions, or issues, feel free to open a new issue or join the discussion in our community forum. + + Stay awesome! 😊 + `; + + github.rest.issues.createComment({ + owner: context.repo.owner, + repo: context.repo.repo, + issue_number: issueNumber, + body: greetingMessage + }); + } else { + console.log('The closed issue is a pull request. No greeting message sent.'); + } diff --git a/.github/workflows/auto-comment-issue-creation.yml b/.github/workflows/auto-comment-issue-creation.yml index 0fc7fb6e..da5a8799 100644 --- a/.github/workflows/auto-comment-issue-creation.yml +++ b/.github/workflows/auto-comment-issue-creation.yml @@ -1,4 +1,4 @@ -name: Auto Comment on Issue +name: Auto Comment on Issue Creation on: issues: diff --git a/.github/workflows/auto-comment-pr-created.yml b/.github/workflows/auto-comment-pr-created.yml index bedaaafa..e0866632 100644 --- a/.github/workflows/auto-comment-pr-created.yml +++ b/.github/workflows/auto-comment-pr-created.yml @@ -1,4 +1,4 @@ -name: Auto Comment on PR +name: Auto Comment on PR Creation on: pull_request_target: diff --git a/.github/workflows/close-old-issue.yml b/.github/workflows/close-old-issues.yml similarity index 97% rename from .github/workflows/close-old-issue.yml rename to .github/workflows/close-old-issues.yml index 49ceed9e..3ac35d49 100644 --- a/.github/workflows/close-old-issue.yml +++ b/.github/workflows/close-old-issues.yml @@ -1,37 +1,37 @@ -name: Close Old Issues -on: - schedule: - - cron: "0 0 * * *" - -jobs: - close-issues: - runs-on: ubuntu-latest - - steps: - - name: Checkout Repository - uses: actions/checkout@v4 - - - name: Close Old Issues - run: | - open_issues=$(curl -s -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \ - "https://api.github.com/repos/${{ github.repository }}/issues?state=open" \ - | jq -r '.[] | .number') - for issue in $open_issues; do - # Get the last updated timestamp of the issue - last_updated=$(curl -s -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \ - "https://api.github.com/repos/${{ github.repository }}/issues/$issue" \ - | jq -r '.updated_at') - days_since_update=$(( ( $(date +%s) - $(date -d "$last_updated" +%s) ) / 86400 )) - if [ $days_since_update -gt 30 ]; then - curl -s -X PATCH -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \ - -H "Accept: application/vnd.github.v3+json" \ - -d '{"state":"closed"}' \ - "https://api.github.com/repos/${{ github.repository }}/issues/$issue" - - # Add a comment mentioning the repository owner - curl -s -X POST -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \ - -H "Accept: application/vnd.github.v3+json" \ - -d "{\"body\":\"@${{ github.repository_owner }} This issue has been automatically closed because it has been inactive for more than 30 days. If you believe this is still relevant, feel free to reopen it or create a new one. Thank you!\"}" \ - "https://api.github.com/repos/${{ github.repository }}/issues/$issue/comments" - fi - done +name: Close Old Issues +on: + schedule: + - cron: "0 0 * * *" + +jobs: + close-issues: + runs-on: ubuntu-latest + + steps: + - name: Checkout Repository + uses: actions/checkout@v4 + + - name: Close Old Issues + run: | + open_issues=$(curl -s -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \ + "https://api.github.com/repos/${{ github.repository }}/issues?state=open" \ + | jq -r '.[] | .number') + for issue in $open_issues; do + # Get the last updated timestamp of the issue + last_updated=$(curl -s -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \ + "https://api.github.com/repos/${{ github.repository }}/issues/$issue" \ + | jq -r '.updated_at') + days_since_update=$(( ( $(date +%s) - $(date -d "$last_updated" +%s) ) / 86400 )) + if [ $days_since_update -gt 30 ]; then + curl -s -X PATCH -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \ + -H "Accept: application/vnd.github.v3+json" \ + -d '{"state":"closed"}' \ + "https://api.github.com/repos/${{ github.repository }}/issues/$issue" + + # Add a comment mentioning the repository owner + curl -s -X POST -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \ + -H "Accept: application/vnd.github.v3+json" \ + -d "{\"body\":\"@${{ github.repository_owner }} This issue has been automatically closed because it has been inactive for more than 30 days. If you believe this is still relevant, feel free to reopen it or create a new one. Thank you!\"}" \ + "https://api.github.com/repos/${{ github.repository }}/issues/$issue/comments" + fi + done diff --git a/.github/workflows/close-old-pr.yml b/.github/workflows/close-old-prs.yml similarity index 93% rename from .github/workflows/close-old-pr.yml rename to .github/workflows/close-old-prs.yml index d23b6aac..2a2595f3 100644 --- a/.github/workflows/close-old-pr.yml +++ b/.github/workflows/close-old-prs.yml @@ -1,33 +1,33 @@ -name: Close Stale PRs - -on: - schedule: - - cron: '0 0 * * *' # Runs daily at midnight - pull_request: - types: - - opened - - reopened - - synchronize - -permissions: - pull-requests: write - issues: write - -jobs: - close_stale_prs: - runs-on: ubuntu-latest - permissions: - pull-requests: write - - steps: - - uses: actions/stale@v7 - with: - repo-token: ${{ secrets.GITHUB_TOKEN }} - stale-pr-message: 'This PR has been automatically closed due to inactivity from the owner for 15 days.' - days-before-pr-stale: 15 - days-before-pr-close: 0 - exempt-pr-labels: '' - only-labels: '' - operations-per-run: 30 - remove-stale-when-updated: true +name: Close Old PRs + +on: + schedule: + - cron: '0 0 * * *' # Runs daily at midnight + pull_request: + types: + - opened + - reopened + - synchronize + +permissions: + pull-requests: write + issues: write + +jobs: + close_stale_prs: + runs-on: ubuntu-latest + permissions: + pull-requests: write + + steps: + - uses: actions/stale@v7 + with: + repo-token: ${{ secrets.GITHUB_TOKEN }} + stale-pr-message: 'This PR has been automatically closed due to inactivity from the owner for 15 days.' + days-before-pr-stale: 15 + days-before-pr-close: 0 + exempt-pr-labels: '' + only-labels: '' + operations-per-run: 30 + remove-stale-when-updated: true debug-only: false \ No newline at end of file