feat(ci): add new feature notifier #1
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Feature Branch Listener | |
on: | |
pull_request_target: | |
types: [opened, reopened, edited] | |
issue_comment: | |
types: [created, edited] | |
jobs: | |
check-comment-and-branch: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Check for '[new feature]' in comment and base branch | |
if: github.event_name == 'issue_comment' && contains(github.event.comment.body, '[new feature]') | |
uses: actions/github-script@v5 | |
with: | |
github-token: ${{secrets.GITHUB_TOKEN}} | |
script: | | |
const issue_number = context.issue.number; | |
const issue_comment_author = context.actor; | |
const { data: pullRequest } = await github.rest.issues.get({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
issue_number: issue_number | |
}); | |
if (!pullRequest.pull_request) { | |
console.log("The comment is not on a pull request."); | |
return; | |
} | |
const { data: pullRequestDetails } = await github.rest.pulls.get({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
pull_number: issue_number | |
}); | |
if (pullRequestDetails.base.ref !== 'develop') { | |
const message = "It looks like your PR contains a new feature. Please rebase and point your PR to the `develop` branch. You are currently pointing to the `" + pullRequestDetails.base.ref + "` branch."; | |
await github.rest.issues.createComment({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
issue_number: issue_number, | |
body: message | |
}); | |
} |