Skip to content
Merged
Changes from all 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
44 changes: 44 additions & 0 deletions .github/workflows/targeting-valid-branch.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
name: Targeting Valid Branch
on:
pull_request_target:
types:
- opened
- reopened
- synchronize
jobs:
Test:
runs-on: windows-latest
defaults:
run:
shell: pwsh
if: github.base_ref == 'live'
steps:
- name: Authorized to Target Live Branch
env:
GITHUB_TOKEN: ${{ github.token }}
run: |
$Query = @'
query author_collaborator_permission($owner: String!, $repo: String!, $actor: String!) {
repository(owner: $owner, name: $repo) {
collaborators(query: $actor) {
edges {
permission
}
}
}
}
'@
$ApiParameters = @(
'api', 'graphql'
'-F', "owner=${{ github.event.pull_request.base.repo.owner.login}}"
'-F', "repo=${{ github.event.pull_request.base.repo.name }}"
'-F', "actor=${{ github.event.pull_request.user.login }}"
'-f', "query=$Query"
'--jq', '.data.repository.collaborators.edges[].permission'
)
[string[]]$Permissions = gh @ApiParameters
if ($Permissions -notcontains 'MAINTAIN' -and $Permissions -notcontains 'ADMIN') {
throw "Author does not have permissions to target ${{ github.base_ref }}"
} else {
echo "Author has permissions to target ${{ github.base_ref }}"
}