|
| 1 | +name: PR Management |
| 2 | + |
| 3 | +on: |
| 4 | + pull_request_target: |
| 5 | + types: [opened, reopened, synchronize, closed] |
| 6 | + |
| 7 | +jobs: |
| 8 | + manage_pr: |
| 9 | + runs-on: ubuntu-latest |
| 10 | + permissions: |
| 11 | + pull-requests: write |
| 12 | + issues: write |
| 13 | + steps: |
| 14 | + - name: Auto Add Label |
| 15 | + if: github.event.action == 'opened' || github.event.action == 'reopened' || github.event.action == 'synchronize' |
| 16 | + uses: actions/github-script@v8 |
| 17 | + with: |
| 18 | + script: | |
| 19 | + github.rest.issues.addLabels({ |
| 20 | + issue_number: context.issue.number, |
| 21 | + owner: context.repo.owner, |
| 22 | + repo: context.repo.repo, |
| 23 | + labels: ['Waiting On Review'] |
| 24 | + }) |
| 25 | +
|
| 26 | + - name: Auto Remove Label |
| 27 | + if: github.event.action == 'closed' |
| 28 | + uses: actions/github-script@v8 |
| 29 | + continue-on-error: true |
| 30 | + with: |
| 31 | + script: | |
| 32 | + try { |
| 33 | + await github.rest.issues.removeLabel({ |
| 34 | + issue_number: context.issue.number, |
| 35 | + owner: context.repo.owner, |
| 36 | + repo: context.repo.repo, |
| 37 | + name: 'Waiting On Review' |
| 38 | + }); |
| 39 | + } catch (error) { |
| 40 | + console.log('Label "Waiting On Review" not found or could not be removed.'); |
| 41 | + } |
| 42 | +
|
| 43 | + - name: Auto Assign Milestone |
| 44 | + if: github.event.action == 'opened' |
| 45 | + uses: actions/github-script@v8 |
| 46 | + with: |
| 47 | + script: | |
| 48 | + // Fetch open milestones and assign the closest one |
| 49 | + const { data: milestones } = await github.rest.issues.listMilestones({ |
| 50 | + owner: context.repo.owner, |
| 51 | + repo: context.repo.repo, |
| 52 | + state: 'open', |
| 53 | + sort: 'due_on', |
| 54 | + direction: 'asc' |
| 55 | + }); |
| 56 | +
|
| 57 | + if (milestones.length > 0) { |
| 58 | + const latestMilestone = milestones[0]; |
| 59 | + await github.rest.issues.update({ |
| 60 | + issue_number: context.issue.number, |
| 61 | + owner: context.repo.owner, |
| 62 | + repo: context.repo.repo, |
| 63 | + milestone: latestMilestone.number |
| 64 | + }); |
| 65 | + } |
0 commit comments