ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
release_notes.py
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file release_notes.py
1 from util import Spinner
2 import os
3 import re
4 import urllib.parse
5 import requests
6 import sys
7 
8 
9 def parse_version(name):
10  return re.match(r"v(\d\.\d\d\.\d\d)", name).group(1)
11 
12 
14  return os.getenv(
15  "RELEASE_NOTES_LABEL_GROUPS", "New Feature;Bug;Improvement;Infrastructure"
16  ).split(";")
17 
18 
19 def group_items(labels, items):
20  groups = {l: [] for l in labels}
21  groups["Uncategorized"] = []
22 
23  for item in items:
24  assigned = False
25  for label in item.labels:
26  if label in labels:
27  groups[label].append(item)
28  assigned = True
29  break
30  # is we get here, we didn't group this
31  if not assigned:
32  groups["Uncategorized"].append(item)
33  return groups
34 
35 
36 def collect_milestone(milestone):
37  label_groups = get_label_groups()
38  mrs = []
39  with Spinner(text=f"Loading merge requests associated with %{milestone.iid}", stream=sys.stderr):
40  for mr in milestone.merge_requests():
41  if mr.state == "merged":
42  mrs.append(mr)
43 
44  # need to get issues from merged MRs
45  with Spinner(text=f"Collecting issues from {len(mrs)} merged MRs", stream=sys.stderr):
46  issue_ids = []
47  issues = []
48  for mr in mrs:
49  for issue in mr.closes_issues():
50  if issue.id not in issue_ids:
51  issue_ids.append(issue.id)
52  issues.append(issue)
53 
54  issues_grouped = group_items(label_groups, issues)
55  mrs_grouped = group_items(label_groups, mrs)
56 
57  return mrs_grouped, issues_grouped
58 
59 
60 def make_release_notes(milestone, mrs_grouped, issues_grouped, badges=True, links=True):
61  if links: link = lambda title, url: f"[{title}]({url})"
62  else: link = lambda title, url: f"{title}"
63 
64  label_groups = get_label_groups()
65  # make the Markdown
66  md = ""
67  # md = f"# Release {tag.name}\n"
68  # md += f"Milestone: [%{milestone.title}]({milestone.web_url})\n"
69 
70  ms_badge = "https://badgen.net/badge/milestone/%s/green" % urllib.parse.quote(
71  f"%{milestone.title}"
72  )
73 
74 
75  badge = f"![](https://gitlab.cern.ch/acts/acts-core/badges/v{milestone.title}/coverage.svg)"
76  cov_url = f"https://acts.web.cern.ch/ACTS/coverage/v{milestone.title}/"
77 
78  if badges:
79  md += f"[![]({ms_badge})]({milestone.web_url})\n"
80  r = requests.get(cov_url)
81  if r.status_code == 200:
82  md += f"[{badge}]({cov_url})\n\n"
83  else:
84  md += f"[{badge}](#)\n\n"
85 
86  nmrs = sum([len(v) for v in mrs_grouped.values()])
87  nissues = sum([len(v) for v in issues_grouped.values()])
88 
89  if nmrs > 0:
90  md += f"### {nmrs} Merge Requests in this release:\n"
91  for g in label_groups + ["Uncategorized"]:
92  if len(mrs_grouped[g]) == 0:
93  continue
94  md += f"#### {g}\n"
95  for mr in mrs_grouped[g]:
96  l = link(f"!<span></span>{mr.iid} - {mr.title}", mr.web_url)
97  md += f"- {l}\n"
98  md += "\n"
99 
100  if nissues > 0:
101  md += f"### {nissues} issues addressed in this release:\n"
102  for g in label_groups + ["Uncategorized"]:
103  if len(issues_grouped[g]) == 0:
104  continue
105  md += f"#### {g}\n"
106  for issue in issues_grouped[g]:
107  l = link(f"#<span></span>{issue.iid} - {issue.title}", issue.web_url)
108  md += f"- {l}\n"
109  return md