Weekly Issues Collection #17
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Weekly Issues Collection | |
| on: | |
| schedule: | |
| - cron: '0 0 * * 1' # Run every Monday at midnight UTC | |
| workflow_dispatch: # Allow manual trigger | |
| jobs: | |
| collect-issues: | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: write | |
| issues: read | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| - name: Get last week's issues | |
| id: get-issues | |
| uses: actions/github-script@v7 | |
| with: | |
| script: | | |
| const now = new Date(); | |
| const lastWeek = new Date(now.getTime() - 7 * 24 * 60 * 60 * 1000); | |
| const issues = await github.rest.issues.listForRepo({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| since: lastWeek.toISOString(), | |
| state: 'all', | |
| per_page: 100 | |
| }); | |
| const weeklyIssues = issues.data.filter(issue => | |
| !issue.pull_request && | |
| new Date(issue.created_at) >= lastWeek | |
| ); | |
| let issueList = ''; | |
| if (weeklyIssues.length === 0) { | |
| issueList = 'No new issues created this week.'; | |
| } else { | |
| const issuePromises = weeklyIssues.map(async issue => { | |
| const issueDetail = await github.rest.issues.get({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| issue_number: issue.number | |
| }); | |
| const body = issueDetail.data.body || 'No content'; | |
| return `### [#${issue.number}](${issue.html_url}) ${issue.title}\n${body}\n`; | |
| }); | |
| const issueDetails = await Promise.all(issuePromises); | |
| issueList = issueDetails.join('\n'); | |
| } | |
| const weekStart = lastWeek.toISOString().split('T')[0]; | |
| const weekEnd = now.toISOString().split('T')[0]; | |
| core.setOutput('issues', issueList); | |
| core.setOutput('week-start', weekStart); | |
| core.setOutput('week-end', weekEnd); | |
| - name: Add new issues to TODO Collection | |
| run: | | |
| ISSUES="${{ steps.get-issues.outputs.issues }}" | |
| # Check if there are new issues to add | |
| if [[ "$ISSUES" != "No new issues created this week." && -n "$ISSUES" ]]; then | |
| # Create a temporary file with new issues | |
| echo -e "\n\n$ISSUES" > new_issues.txt | |
| # Use awk to insert new issues after TODO Collection header | |
| awk ' | |
| /^## TODO Collection$/ { | |
| print $0 | |
| while ((getline line < "new_issues.txt") > 0) { | |
| print line | |
| } | |
| close("new_issues.txt") | |
| next | |
| } | |
| { print } | |
| ' README.md > README_temp.md && mv README_temp.md README.md | |
| # Clean up | |
| rm -f new_issues.txt | |
| fi | |
| - name: Commit and push changes | |
| run: | | |
| git config --local user.email "jiahaoxiang2000@gmail.com" | |
| git config --local user.name "isomo" | |
| git add README.md | |
| git diff --staged --quiet || git commit -m "π Add new TODO issues to collection" | |
| git push |