2023-04-17 00:41:18 +02:00
|
|
|
|
#!/usr/bin/env python3
|
2024-10-04 22:06:43 +02:00
|
|
|
|
# Copyright (c) 2022-2024 The Dash Core developers
|
2023-01-12 22:32:07 +01:00
|
|
|
|
# Distributed under the MIT software license, see the accompanying
|
|
|
|
|
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
2023-04-17 00:41:18 +02:00
|
|
|
|
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
Usage:
|
|
|
|
|
$ ./handle_potential_conflicts.py <conflicts>
|
|
|
|
|
|
|
|
|
|
Where <conflicts> is a json string which looks like
|
|
|
|
|
{ pull_number: 26,
|
|
|
|
|
conflictPrs:
|
|
|
|
|
[ { number: 15,
|
|
|
|
|
files: [ 'testfile1', `testfile2` ],
|
|
|
|
|
conflicts: [ 'testfile1' ] },
|
|
|
|
|
...
|
|
|
|
|
]}
|
|
|
|
|
"""
|
|
|
|
|
|
2022-01-13 15:26:47 +01:00
|
|
|
|
import sys
|
|
|
|
|
import requests
|
|
|
|
|
|
|
|
|
|
# need to install via pip
|
|
|
|
|
import hjson
|
|
|
|
|
|
2024-09-05 10:49:09 +02:00
|
|
|
|
def get_pr_json(pr_num):
|
|
|
|
|
return requests.get(f'https://api.github.com/repos/dashpay/dash/pulls/{pr_num}').json()
|
2022-01-13 15:26:47 +01:00
|
|
|
|
|
|
|
|
|
def main():
|
2023-04-17 00:41:18 +02:00
|
|
|
|
if len(sys.argv) != 2:
|
|
|
|
|
print(f'Usage: {sys.argv[0]} <conflicts>', file=sys.stderr)
|
|
|
|
|
sys.exit(1)
|
|
|
|
|
|
2022-01-13 15:26:47 +01:00
|
|
|
|
input = sys.argv[1]
|
|
|
|
|
print(input)
|
|
|
|
|
j_input = hjson.loads(input)
|
|
|
|
|
print(j_input)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
our_pr_num = j_input['pull_number']
|
2024-09-05 10:49:09 +02:00
|
|
|
|
our_pr_label = get_pr_json(our_pr_num)['head']['label']
|
2022-01-13 15:26:47 +01:00
|
|
|
|
conflictPrs = j_input['conflictPrs']
|
|
|
|
|
|
|
|
|
|
good = []
|
|
|
|
|
bad = []
|
|
|
|
|
|
|
|
|
|
for conflict in conflictPrs:
|
2024-09-05 10:49:09 +02:00
|
|
|
|
conflict_pr_num = conflict['number']
|
|
|
|
|
print(conflict_pr_num)
|
2022-01-13 15:26:47 +01:00
|
|
|
|
|
2024-09-05 10:49:09 +02:00
|
|
|
|
conflict_pr_json = get_pr_json(conflict_pr_num)
|
|
|
|
|
conflict_pr_label = conflict_pr_json['head']['label']
|
|
|
|
|
print(conflict_pr_label)
|
2022-01-20 17:06:37 +01:00
|
|
|
|
|
2024-09-05 10:49:09 +02:00
|
|
|
|
if conflict_pr_json['mergeable_state'] == "dirty":
|
|
|
|
|
print(f'{conflict_pr_num} needs rebase. Skipping conflict check')
|
2022-01-20 17:06:37 +01:00
|
|
|
|
continue
|
|
|
|
|
|
2024-09-05 10:49:09 +02:00
|
|
|
|
if conflict_pr_json['draft']:
|
|
|
|
|
print(f'{conflict_pr_num} is a draft. Skipping conflict check')
|
2024-09-04 20:17:42 +02:00
|
|
|
|
continue
|
|
|
|
|
|
2024-09-05 10:49:09 +02:00
|
|
|
|
pre_mergeable = requests.get(f'https://github.com/dashpay/dash/branches/pre_mergeable/{our_pr_label}...{conflict_pr_label}')
|
|
|
|
|
if "These branches can be automatically merged." in pre_mergeable.text:
|
|
|
|
|
good.append(conflict_pr_num)
|
|
|
|
|
elif "Can’t automatically merge" in pre_mergeable.text:
|
|
|
|
|
bad.append(conflict_pr_num)
|
2022-01-13 15:26:47 +01:00
|
|
|
|
else:
|
|
|
|
|
raise Exception("not mergeable or unmergable!")
|
|
|
|
|
|
|
|
|
|
print("Not conflicting PRs: ", good)
|
|
|
|
|
|
|
|
|
|
print("Conflicting PRs: ", bad)
|
|
|
|
|
if len(bad) > 0:
|
|
|
|
|
sys.exit(1)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
|
main()
|