-
Notifications
You must be signed in to change notification settings - Fork 0
/
action.yml
41 lines (41 loc) · 1.34 KB
/
action.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
name: 'Require PR Action'
description: Use this action to revert commits on a branch that were pushed without a PR. Can limit to only certain users
inputs:
users:
description: 'Comma separated list of users to deny to push without a PR. By default this applies to all users'
required: false
default: ''
runs:
using: composite
steps:
- name: Checkout
uses: actions/checkout@v4
with:
ref: ${{ github.event.push.ref }}
fetch-depth: 2
- name: Determine if push from PR
uses: actions/github-script@v7
id: determine_if_pr
with:
script: |
const users = '${{ inputs.users }}'.split(',');
if (!users.includes(context.actor) && users[0]) {
return true;
}
const result = await github.rest.repos.listPullRequestsAssociatedWithCommit({
commit_sha: context.sha,
owner: context.repo.owner,
repo: context.repo.repo
})
if (result.data[0] && result.data[0].number > 0) {
return true;
} else {
return false;
}
result-encoding: string
- name: Undo direct push
if: ${{ steps.determine_if_pr.outputs.result == 'false' }}
shell: bash
run: |
git reset --hard HEAD~1
git push -f origin ${{ github.ref_name }}