close_issues.yml 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. name: Close inactive issues
  2. on:
  3. schedule:
  4. - cron: "10 23 * * *"
  5. jobs:
  6. close-issues:
  7. runs-on: ubuntu-latest
  8. permissions:
  9. issues: write
  10. pull-requests: write
  11. steps:
  12. - uses: actions/stale@v5
  13. with:
  14. stale-issue-message: ""
  15. close-issue-message: "This issue has been closed due to inactivity for 6 weeks. If you believe it is still relevant, please leave a comment below. You can tag a developer in your comment."
  16. days-before-issue-stale: 42
  17. days-before-issue-close: 0
  18. stale-issue-label: "stale"
  19. days-before-pr-stale: -1
  20. days-before-pr-close: -1
  21. repo-token: ${{ secrets.GITHUB_TOKEN }}
  22. - name: Close issues without label or comment
  23. uses: actions/github-script@v3
  24. with:
  25. github-token: ${{secrets.GITHUB_TOKEN}}
  26. script: |
  27. const repo = context.repo;
  28. let page = 1;
  29. let issues = [];
  30. while (true) {
  31. const result = await github.issues.listForRepo({...repo, per_page: 100, page: page});
  32. if (result.data.length === 0) break;
  33. issues = issues.concat(result.data);
  34. page += 1;
  35. }
  36. for (let { number } of issues) {
  37. const issueData = await github.issues.get({...repo, issue_number: number});
  38. const comments = await github.issues.listComments({...repo, issue_number: number});
  39. if (issueData.data.labels.length === 0 && comments.data.length < 1) {
  40. await github.issues.update({...repo, issue_number: number, state: 'closed'});
  41. await github.issues.createComment({...repo, issue_number: number, body: 'Issue closed as it does not have any labels or comments.'});
  42. }
  43. }