forked from bearycool11/runner-images
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path.mergify.yml
121 lines (109 loc) · 3.52 KB
/
.mergify.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
commands_restrictions:
update:
conditions:
- or:
- sender-permission >= reader
- sender = {{author}}
rebase:
conditions:
- or:
- sender-permission >= reader
- sender = {{author}}
squash:
conditions:
- or:
- sender-permission >= reader
- sender = {{author}}
backport:
conditions:
- sender-permission >= reader
unqueue:
conditions:
- ""
- sender-permission >= reader
queue:
conditions:
- sender-permission >= reader
requeue:
conditions:
- sender-permission >= reader
import yaml
import os
import subprocess
# Path to your Mergify config file
MERGIFY_CONFIG_PATH = ".mergify.yml"
BACKUP_CONFIG_PATH = ".mergify.yml.bak"
def backup_mergify_config():
"""Backup the Mergify config."""
if not os.path.exists(MERGIFY_CONFIG_PATH):
print(f"Mergify config not found at {MERGIFY_CONFIG_PATH}")
return False
# Create a backup
with open(MERGIFY_CONFIG_PATH, "r") as original, open(BACKUP_CONFIG_PATH, "w") as backup:
backup.write(original.read())
print(f"Backup created: {BACKUP_CONFIG_PATH}")
return True
def comment_out_rules():
"""Comment out all rules in the Mergify config."""
with open(MERGIFY_CONFIG_PATH, "r") as file:
config = yaml.safe_load(file)
if "pull_request_rules" in config:
for rule in config["pull_request_rules"]:
rule["disabled"] = True # Disable all rules
print("All pull request rules disabled.")
# Save updated config
with open(MERGIFY_CONFIG_PATH, "w") as file:
yaml.dump(config, file, default_flow_style=False)
print(f"Updated config written to {MERGIFY_CONFIG_PATH}")
def push_changes():
"""Push changes to the Git repository."""
try:
subprocess.run(["git", "add", MERGIFY_CONFIG_PATH], check=True)
subprocess.run(["git", "commit", "-m", "Temporarily disable Mergify rules"], check=True)
subprocess.run(["git", "push"], check=True)
print("Changes pushed successfully.")
except subprocess.CalledProcessError as e:
print(f"Error during git operations: {e}")
restore_backup()
def restore_backup():
"""Restore the original Mergify config."""
if os.path.exists(BACKUP_CONFIG_PATH):
with open(BACKUP_CONFIG_PATH, "r") as backup, open(MERGIFY_CONFIG_PATH, "w") as original:
original.write(backup.read())
print("Backup restored.")
else:
print("Backup not found. Cannot restore.")
def main():
"""Main function to disable Mergify rules."""
if not backup_mergify_config():
return
try:
comment_out_rules()
push_changes()
except Exception as e:
print(f"An error occurred: {e}")
restore_backup()
if __name__ == "__main__":
main()
commands_restrictions:
update:
conditions:
- or:
- sender-permission: reader # Adjusted permission level
- sender: "{{author}}" # Allowed if sender is the author
rebase:
conditions:
- or:
- sender-permission: reader # Adjusted permission level
- sender: "{{author}}" # Allowed if sender is the author
squash:
conditions:
- or:
- sender-permission: reader # Adjusted permission level
- sender: "{{author}}" # Allowed if sender is the author
backport:
conditions:
- sender-permission: reader # Adjusted permission level
unqueue:
conditions:
- sender-permission: reader # Adjusted permission leve