-
Notifications
You must be signed in to change notification settings - Fork 6
/
pr_text.py
67 lines (52 loc) · 2.22 KB
/
pr_text.py
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
"""
Output autoupdate PR text
"""
import argparse
import yaml
parser = argparse.ArgumentParser()
parser.add_argument("--repo", help="Tool repo")
parser.add_argument("--log", help="Autoupdate log")
parser.add_argument("--shed", help="Location of .shed.yml file input.")
parser.add_argument("--out", help="Output file.")
args = parser.parse_args()
with open(args.log) as f:
lines = f.readlines()
for line in lines:
if "Updating" in line and "from version" in line:
words = line.split()
from_version = words[4]
to_version = words[6]
if from_version != to_version:
update = f"from version {from_version} to {to_version}"
break
else:
raise Exception(
f"`Updating ... from version` line not found in {args.log}:\n{''.join(lines)}"
)
text = []
text.append(
f"Hello! This is an automated update of the following tool: **{args.repo}**. I created this PR because I think the tool's main dependency is out of date, i.e. there is a newer version available through conda."
)
text.append(f"I have updated {args.repo} {update}.")
with open(args.shed) as f:
y = yaml.load(f, Loader=yaml.SafeLoader)
if y.get("homepage_url"):
url = y.get("homepage_url").strip("/")
if "github.com" in url:
if len(url.split("github.com")[1].split("/")) > 1:
url += "/releases"
text.append(f"**Project home page:** {url}")
if y.get("maintainers"):
text.append(
"**Maintainers:** " + ", ".join([f"@{m}" for m in y.get("maintainers")])
)
text.append(
"For any comments, queries or criticism about the bot, not related to the tool being updated in this PR, please create an issue [here](https://github.com/planemo-autoupdate/autoupdate/issues/new)."
)
# Add info on the strategy
text.append("\nIf you want to skip this change, close this PR without deleting the branch. It will be reopened if another change is detected.")
text.append("Any commit from another author than 'planemo-autoupdate' will prevent more auto-updates.")
text.append("To ignore manual changes and allow autoupdates, delete the branch.")
with open(args.out, "w") as f:
f.write("\n\n".join(text))
print(f"Updating {args.repo} {update}")