ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
sync_releases.py
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file sync_releases.py
1 #!/usr/bin/env python3
2 
3 import os
4 import json
5 import re
6 import argparse
7 import contextlib
8 import sys
9 import math
10 
11 from util import def_arguments, Spinner, gitlab
12 from release_notes import (
13  collect_milestone,
14  make_release_notes,
15  get_label_groups,
16  parse_version,
17 )
18 
19 
20 def main():
21  p = argparse.ArgumentParser()
22  p = def_arguments(p, gl=True)
23 
24  p.add_argument("--dry-run", "-s", action="store_true")
25  p.add_argument("--verbose", "-v", action="store_true")
26 
27  print("Label groups:", ", ".join(get_label_groups()))
28 
29  args = p.parse_args()
30 
31  gl = gitlab(args)
32 
33  project = gl.projects.get("acts/acts-core")
34 
35  with Spinner(text="Loading tags"):
36  tags = project.tags.list(all=True)
37 
38  with Spinner(text="Loading milestones"):
39  milestones = project.milestones.list(all=True)
40  ms_map = {}
41  for ms in milestones:
42  ms_map[ms.title] = ms
43 
44  for tag in tags:
45  version = parse_version(tag.name)
46  if not version in ms_map:
47  print(f"No milestone found for tag f{tag.name} => skipping")
48  milestone = ms_map[version]
49  print(tag.name, milestone.title)
50 
51  mrs_grouped, issues_grouped = collect_milestone(milestone)
52 
53  if args.verbose:
54  print("Issues:", ", ".join([str(i.iid) for i in issues]))
55 
56  for g, issues in issues_grouped.items():
57  print(g, ", ".join([str(i.iid) for i in issues]))
58 
59  print("MRs:", ", ".join([str(mr.iid) for mr in mrs]))
60  for g, mrs in mrs_grouped.items():
61  print(g, ", ".join([str(mr.iid) for mr in mrs]))
62 
63  with Spinner(text="Assembling release notes"):
64  md = make_release_notes(milestone, mrs_grouped, issues_grouped)
65 
66  # print(md)
67  if not args.dry_run:
68  with Spinner(text=f"Saving release notes on {tag.name}"):
69  tag.set_release_description(md)
70 
71  # there should be a release now
72  with Spinner(f"Getting release for tag {tag.name}"):
73  rel = project.releases.get(tag.name)
74  if not args.dry_run:
75  with Spinner(f"Setting milestones on release {tag.name} to [{milestone.title}]"):
76  gl.http_put(f"/projects/{project.id}/releases/{tag.name}", post_data={"milestones": [milestone.title]})
77  # rel.milestones = [milestone.title]
78  # rel.save()
79  if args.verbose:
80  print("---")
81 
82 
83 
84 if "__main__" == __name__:
85  main()