|
| 1 | +name: Add Unanswered PRs and Issues to PyTorch Project 133 |
| 2 | + |
| 3 | +on: |
| 4 | + schedule: |
| 5 | + - cron: '0 * * * *' |
| 6 | + workflow_dispatch: |
| 7 | + |
| 8 | +jobs: |
| 9 | + add_to_project: |
| 10 | + runs-on: ubuntu-latest |
| 11 | + steps: |
| 12 | + - name: Query unanswered PRs and issues and add to project |
| 13 | + uses: actions/github-script@v7 |
| 14 | + with: |
| 15 | + github-token: ${{ secrets.GITHUB_TOKEN }} |
| 16 | + script: | |
| 17 | + const projectId = "PVT_kwDOAUB9vs4A-j69"; |
| 18 | +
|
| 19 | + async function addItem(contentId) { |
| 20 | + try { |
| 21 | + await github.graphql(` |
| 22 | + mutation { |
| 23 | + addProjectV2ItemById(input: {projectId: "${projectId}", contentId: "${contentId}"}) { |
| 24 | + item { id } |
| 25 | + } |
| 26 | + } |
| 27 | + `); |
| 28 | + console.log(`Added item with contentId: ${contentId}`); |
| 29 | + } catch (error) { |
| 30 | + console.log(`Error adding item ${contentId}: ${error.message}`); |
| 31 | + } |
| 32 | + } |
| 33 | +
|
| 34 | + try { |
| 35 | + // Get unanswered PRs: open, not draft, not approved |
| 36 | + const prs = await github.paginate( |
| 37 | + github.rest.pulls.list, |
| 38 | + { |
| 39 | + owner: 'pytorch', |
| 40 | + repo: 'executorch', |
| 41 | + state: 'open', |
| 42 | + draft: false, |
| 43 | + } |
| 44 | + ); |
| 45 | +
|
| 46 | + for (const pr of prs) { |
| 47 | + const reviews = await github.rest.pulls.listReviews({ |
| 48 | + owner: 'pytorch', |
| 49 | + repo: 'executorch', |
| 50 | + pull_number: pr.number |
| 51 | + }); |
| 52 | + const approved = reviews.data.some(r => r.state === 'APPROVED'); |
| 53 | + if (!approved) { |
| 54 | + console.log(`Adding unanswered PR #${pr.number}`); |
| 55 | + await addItem(pr.node_id); |
| 56 | + } |
| 57 | + } |
| 58 | +
|
| 59 | + // Get open issues (not PRs) |
| 60 | + const issues = await github.paginate( |
| 61 | + github.rest.issues.listForRepo, |
| 62 | + { |
| 63 | + owner: 'pytorch', |
| 64 | + repo: 'executorch', |
| 65 | + state: 'open', |
| 66 | + filter: 'all' |
| 67 | + } |
| 68 | + ); |
| 69 | +
|
| 70 | + for (const issue of issues) { |
| 71 | + if (!issue.pull_request) { |
| 72 | + console.log(`Adding open issue #${issue.number}`); |
| 73 | + await addItem(issue.node_id); |
| 74 | + } |
| 75 | + } |
| 76 | + } catch (error) { |
| 77 | + core.setFailed(`Workflow failed: ${error.message}`); |
| 78 | + } |
0 commit comments