|
| 1 | +on: |
| 2 | + pull_request_target: |
| 3 | + types: |
| 4 | + - closed |
| 5 | + |
| 6 | +env: |
| 7 | + RELEASE_LABEL: "pending-release" |
| 8 | + MAINTAINERS_TEAM: "@awslabs/aws-lambda-powertools-python" |
| 9 | + |
| 10 | +jobs: |
| 11 | + release_label_on_merge: |
| 12 | + if: github.event.pull_request.merged == true && github.event.pull_request.user.login != 'dependabot[bot]' |
| 13 | + runs-on: ubuntu-latest |
| 14 | + steps: |
| 15 | + - name: "Label PR related issue for release" |
| 16 | + uses: actions/github-script@v6 |
| 17 | + with: |
| 18 | + github-token: ${{ secrets.GITHUB_TOKEN }} |
| 19 | + script: | |
| 20 | + const prBody = context.payload.body; |
| 21 | + const prNumber = context.payload.number; |
| 22 | + const releaseLabel = process.env.RELEASE_LABEL; |
| 23 | +
|
| 24 | + const RELATED_ISSUE_REGEX = /Issue number:.+(\d)/ |
| 25 | +
|
| 26 | + const matcher = new RegExp(RELATED_ISSUE_REGEX) |
| 27 | + const isMatch = matcher.exec(prBody) |
| 28 | + if (isMatch != null) { |
| 29 | + let relatedIssueNumber = isMatch[1] |
| 30 | + console.info(`Auto-labeling related issue ${relatedIssueNumber} for release`) |
| 31 | +
|
| 32 | + await github.rest.issues.addLabels({ |
| 33 | + issue_number: relatedIssueNumber, |
| 34 | + owner: context.repo.owner, |
| 35 | + repo: context.repo.repo, |
| 36 | + labels: [releaseLabel] |
| 37 | + }) |
| 38 | + } else { |
| 39 | + let msg = `${MAINTAINERS_TEAM} No related issues found. Please ensure '${RELEASE_LABEL}.' label is applied before releasing.`; |
| 40 | + await github.rest.issues.createComment({ |
| 41 | + owner: context.repo.owner, |
| 42 | + repo: context.repo.repo, |
| 43 | + body: msg, |
| 44 | + issue_number: prNumber, |
| 45 | + }); |
| 46 | + } |
0 commit comments