|
| 1 | +# Borrowed from https://github.com/sgl-project/sglang/blob/main/.github/workflows/close-inactive-issues.yml |
| 2 | +name: Close Inactive Issues |
| 3 | +on: |
| 4 | + schedule: |
| 5 | + - cron: '0 0 * * *' |
| 6 | +permissions: |
| 7 | + issues: write |
| 8 | + contents: read |
| 9 | +jobs: |
| 10 | + close-inactive-issues: |
| 11 | + if: github.repository == '1038lab/ComfyUI-RMBG' |
| 12 | + runs-on: ubuntu-latest |
| 13 | + steps: |
| 14 | + - name: Check and close inactive issues |
| 15 | + uses: actions/github-script@v6 |
| 16 | + with: |
| 17 | + github-token: ${{secrets.GITHUB_TOKEN}} |
| 18 | + script: | |
| 19 | + const thirtyDaysAgo = new Date(Date.now() - 30 * 24 * 60 * 60 * 1000); |
| 20 | +
|
| 21 | + const [owner, repo] = process.env.GITHUB_REPOSITORY.split('/'); |
| 22 | + console.log(`Owner: ${owner}, Repo: ${repo}`); |
| 23 | +
|
| 24 | + async function fetchIssues(page = 1) { |
| 25 | + console.log(`Fetching issues for ${owner}/${repo}, page ${page}`); |
| 26 | + return await github.rest.issues.listForRepo({ |
| 27 | + owner, |
| 28 | + repo, |
| 29 | + state: 'open', |
| 30 | + sort: 'updated', |
| 31 | + direction: 'asc', |
| 32 | + per_page: 100, |
| 33 | + page: page |
| 34 | + }); |
| 35 | + } |
| 36 | +
|
| 37 | + async function processIssues() { |
| 38 | + console.log('Starting to process issues'); |
| 39 | + console.log(`Repository: ${owner}/${repo}`); |
| 40 | +
|
| 41 | + let page = 1; |
| 42 | + let hasMoreIssues = true; |
| 43 | + while (hasMoreIssues) { |
| 44 | + try { |
| 45 | + const issues = await fetchIssues(page); |
| 46 | + console.log(`Fetched ${issues.data.length} issues on page ${page}`); |
| 47 | +
|
| 48 | + if (issues.data.length === 0) { |
| 49 | + hasMoreIssues = false; |
| 50 | + break; |
| 51 | + } |
| 52 | +
|
| 53 | + for (const issue of issues.data) { |
| 54 | + // Skip if the issue has 'good first issue' label |
| 55 | + if (issue.labels.some(label => label.name === 'good first issue')) { |
| 56 | + console.log(`Skipping issue #${issue.number} as it's marked as 'good first issue'`); |
| 57 | + continue; |
| 58 | + } |
| 59 | + if (new Date(issue.updated_at) < thirtyDaysAgo) { |
| 60 | + try { |
| 61 | + await github.rest.issues.update({ |
| 62 | + owner, |
| 63 | + repo, |
| 64 | + issue_number: issue.number, |
| 65 | + state: 'closed', |
| 66 | + labels: [...issue.labels.map(l => l.name), 'inactive'] |
| 67 | + }); |
| 68 | + await github.rest.issues.createComment({ |
| 69 | + owner, |
| 70 | + repo, |
| 71 | + issue_number: issue.number, |
| 72 | + body: 'This issue has been automatically closed due to 30-day inactivity. Please feel free to reopen it with \`/reopen\` if needed.' |
| 73 | + }); |
| 74 | + console.log(`Closed issue #${issue.number} due to inactivity.`); |
| 75 | + } catch (error) { |
| 76 | + console.error(`Failed to close issue #${issue.number}: ${error.message}`); |
| 77 | + } |
| 78 | + } else { |
| 79 | + console.log(`Issue #${issue.number} is still active. Stopping processing.`); |
| 80 | + hasMoreIssues = false; |
| 81 | + break; |
| 82 | + } |
| 83 | + } |
| 84 | + page += 1; |
| 85 | + } catch (error) { |
| 86 | + console.error(`Error fetching issues on page ${page}: ${error.message}`); |
| 87 | + hasMoreIssues = false; |
| 88 | + } |
| 89 | + } |
| 90 | + console.log('Finished processing issues'); |
| 91 | + } |
| 92 | +
|
| 93 | + await processIssues(); |
0 commit comments