This commit is contained in:
Harsh Shandilya 2023-01-12 16:39:49 +05:30
parent d8559f9fab
commit 0f6f3b7893
No known key found for this signature in database
2 changed files with 8 additions and 33 deletions

View File

@ -1,21 +1,8 @@
module.exports = async ({github, context}) => {
const pr = await github.rest.pulls.get({
owner: context.payload.repository.owner.login,
repo: context.payload.repository.name,
pull_number: context.payload.number,
});
console.log(Object.getOwnPropertyNames(pr));
const shouldWarn = pr.head.ref != "staging" && pr.base.ref == "main";
if (shouldWarn) {
octokit.rest.issues.createComment({
owner: context.payload.repository.owner.login,
repo: context.payload.repository.name,
issue_number: context.payload.number,
body: `This PR is targeting the 'main' branch but did not originate from 'staging', please make sure this intentional`,
});
}
return shouldWarn
}

View File

@ -15,24 +15,12 @@ jobs:
check-pr-base:
runs-on: ubuntu-latest
steps:
- name: .
shell: bash
env:
BASE_REF: ${{ github.base_ref }}
HEAD_REF: ${{ github.head_ref }}
run: echo $BASE_REF $HEAD_REF
- name: Validate PR head and base branches
if: "${{ github.base_ref == 'refs/heads/main' && github.head_ref != 'refs/heads/staging' }}"
run: exit 1
# - name: Checkout repository
# uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c # v3.3.0
#
# - name: Validate PR head and base branches
# uses: actions/github-script@d556feaca394842dc55e4734bf3bb9f685482fa0 # v6.3.3
# id: validate-pr-base
# with:
# result-encoding: string
# github-token: ${{ secrets.GITHUB_TOKEN }}
# script: |
# const script = require('.github/check-pr-base.js')
# return await script({github, context})
if: "${{ github.base_ref == 'main' && github.head_ref != 'staging' }}"
uses: actions/github-script@d556feaca394842dc55e4734bf3bb9f685482fa0 # v6.3.3
id: validate-pr-base
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const script = require('.github/check-pr-base.js')
await script({github, context})