Skip to content

Add workflow to check for wrong branches #4

Add workflow to check for wrong branches

Add workflow to check for wrong branches #4

Workflow file for this run

name: Wrong Branch
on:
pull_request:
types: [labeled, unlabeled]
jobs:
check:
name: Check
runs-on: ubuntu-latest
steps:
- name: Add wrong-base-branch label
id: add-wrong-base-branch-label
uses: actions/[email protected]
if: contains(github.event.pull_request.labels.*.name, 'current') && contains(github.event.pull_request.labels.*.name, 'has-parent')
with:
script: |
await github.rest.issues.addLabels({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
labels: ['wrong-base-branch']
});
- name: Has wrong-base-branch label
if: contains(github.event.pull_request.labels.*.name, 'wrong-base-branch') || steps.add-wrong-base-branch-label.outcome == 'success'
uses: actions/[email protected]
with:
script: core.setFailed('This PR has the wrong-base-branch label');
- if: failure() && contains(github.event.pull_request.labels.*.name, 'current')
name: Review PR to change to next
uses: actions/[email protected]
with:
script: |
await github.rest.pulls.createReview({
pull_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
event: 'REQUEST_CHANGES',
body: "As this is a feature matched with a PR in https://github.com/esphome/esphome, please target your PR to the 'next' branch and rebase."
});
- if: failure() && contains(github.event.pull_request.labels.*.name, 'next')
name: Review PR to change to current
uses: actions/[email protected]
with:
script: |
await github.rest.pulls.createReview({
pull_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
event: 'REQUEST_CHANGES',
body: "Please target your PR to the 'current' branch and rebase."
}
- if: success()
name: Dismiss review
uses: actions/[email protected]
with:
script: |
let reviews = await github.rest.pulls.listReviews({
pull_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo
});
for (let review of reviews.data) {
if (review.user.login === 'github-actions[bot]' && review.state === 'CHANGES_REQUESTED') {
await github.rest.pulls.dismissReview({
pull_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
review_id: review.id,
message: 'Target branch is correct.'
});
}
}