actions: introduce handle_potential_conflicts.py to only warn on true conflicts. Fail CI when there is a conflict (#4655)

* introduce handle_potential_conflicts.py to only warn on true conflicts. Fail CI when there is a conflict

Signed-off-by: Pasta <pasta@dashboost.org>

* remove unneeded input assign

Co-authored-by: UdjinM6 <UdjinM6@users.noreply.github.com>

* use dashpay instead of PastaPastaPasta

Signed-off-by: Pasta <pasta@dashboost.org>

* Update .github/workflows/handle_potential_conflicts.py

Co-authored-by: UdjinM6 <UdjinM6@users.noreply.github.com>

* more linter fixes

Co-authored-by: UdjinM6 <UdjinM6@users.noreply.github.com>
This commit is contained in:
PastaPastaPasta 2022-01-13 21:26:47 +07:00 committed by GitHub
parent 22f335e268
commit f3cd4046c9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 65 additions and 3 deletions

View File

@ -0,0 +1,58 @@
import sys
import requests
# need to install via pip
import hjson
'''Looks like'''
'''{ pull_number: 26,
conflictPrs:
[ { number: 25,
files: [ '.github/workflows/testfile' ],
conflicts: [ '.github/workflows/testfile' ] }
{ number: 24,
files: [ '.github/workflows/testfile' ],
conflicts: [ '.github/workflows/testfile' ] } ] }'''
def main():
input = sys.argv[1]
print(input)
j_input = hjson.loads(input)
print(j_input)
our_pr_num = j_input['pull_number']
our_pr_label = get_label(our_pr_num)
conflictPrs = j_input['conflictPrs']
good = []
bad = []
for conflict in conflictPrs:
this_pr_num = conflict['number']
print(this_pr_num)
r = requests.get(f'https://api.github.com/repos/dashpay/dash/pulls/{conflict["number"]}')
print(r.json()['head']['label'])
r = requests.get(f'https://github.com/dashpay/dash/branches/pre_mergeable/{our_pr_label}...{get_label(this_pr_num)}')
if "These branches can be automatically merged." in r.text:
good.append(this_pr_num)
elif "Cant automatically merge" in r.text:
bad.append(this_pr_num)
else:
raise Exception("not mergeable or unmergable!")
print("Not conflicting PRs: ", good)
print("Conflicting PRs: ", bad)
if len(bad) > 0:
sys.exit(1)
def get_label(pr_num):
return requests.get(f'https://api.github.com/repos/dashpay/dash/pulls/{pr_num}').json()['head']['label']
if __name__ == "__main__":
main()

View File

@ -1,5 +1,7 @@
name: "Check Potential Conflicts"
on: pull_request_target
on:
- pull_request_target
- pull_request_review
permissions:
contents: read
@ -18,7 +20,9 @@ jobs:
main:
runs-on: ubuntu-latest
steps:
- name: check potential conflicts
uses: PastaPastaPasta/potential-conflicts-checker-action@0.1.1
- name: check for potential conflicts
uses: PastaPastaPasta/potential-conflicts-checker-action@0.1.9
with:
ghToken: "${{ secrets.GITHUB_TOKEN }}"
- name: validate potential conflicts
run: wget https://raw.githubusercontent.com/dashpay/dash/develop/.github/workflows/handle_potential_conflicts.py && pip3 install hjson && python3 handle_potential_conflicts.py "$conflicts"