Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add workflow to check for wrong branches #3716

Draft
wants to merge 7 commits into
base: current
Choose a base branch
from
Draft
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
96 changes: 96 additions & 0 deletions .github/workflows/wrong-branch.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
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: Remove wrong-base-branch label
id: remove-wrong-base-branch-label
uses: actions/[email protected]
if: |
contains(github.event.pull_request.labels.*.name, 'wrong-base-branch') &&
(
(contains(github.event.pull_request.labels.*.name, 'current') && !contains(github.event.pull_request.labels.*.name, 'has-parent'))
||
(contains(github.event.pull_request.labels.*.name, 'next') && contains(github.event.pull_request.labels.*.name, 'has-parent'))
)
with:
script: |
await github.rest.issues.removeLabel({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
name: '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.'
});
}
}
Loading