|
| 1 | +# WARNING: DO NOT EDIT! |
| 2 | +# |
| 3 | +# This file was generated by plugin_template, and is managed by it. Please use |
| 4 | +# './plugin-template --travis pulp_python' to update this file. |
| 5 | +# |
| 6 | +# For more info visit https://github.com/pulp/plugin_template |
| 7 | + |
1 | 8 | import argparse |
| 9 | +import json |
2 | 10 | import os |
3 | 11 | import textwrap |
| 12 | +from collections import defaultdict |
| 13 | +from pathlib import Path |
4 | 14 |
|
5 | 15 | from git import Repo |
| 16 | +from redminelib import Redmine |
| 17 | + |
| 18 | + |
| 19 | +REDMINE_URL = "https://pulp.plan.io" |
| 20 | +REDMINE_QUERY_URL = f"{REDMINE_URL}/issues?set_filter=1&status_id=*&issue_id=" |
| 21 | + |
| 22 | + |
| 23 | +def validate_redmine_data(redmine_query_url, redmine_issues): |
| 24 | + """Validate redmine milestone.""" |
| 25 | + redmine = Redmine("https://pulp.plan.io") |
| 26 | + project_set = set() |
| 27 | + stats = defaultdict(list) |
| 28 | + milestone_url = "\n[noissue]" |
| 29 | + for issue in redmine_issues: |
| 30 | + redmine_issue = redmine.issue.get(int(issue)) |
| 31 | + |
| 32 | + project_name = redmine_issue.project.name |
| 33 | + project_set.update([project_name]) |
| 34 | + stats[f"project_{project_name.lower().replace(' ', '_')}"].append(issue) |
| 35 | + |
| 36 | + status = redmine_issue.status.name |
| 37 | + if "CLOSE" not in status and status != "MODIFIED": |
| 38 | + stats["status_not_modified"].append(issue) |
| 39 | + |
| 40 | + print(f"\n\nRedmine stats: {json.dumps(stats, indent=2)}") |
| 41 | + error_messages = [] |
| 42 | + if stats.get("status_not_modified"): |
| 43 | + error_messages.append(f"One or more issues are not MODIFIED {stats['status_not_modified']}") |
| 44 | + if stats.get("without_milestone"): |
| 45 | + error_messages.append( |
| 46 | + f"One or more issues are not associated with a milestone {stats['without_milestone']}" |
| 47 | + ) |
| 48 | + if len(project_set) > 1: |
| 49 | + error_messages.append(f"Issues with different projects - {project_set}") |
| 50 | + if error_messages: |
| 51 | + error_messages.append(f"Verify at {redmine_query_url}") |
| 52 | + raise RuntimeError("\n".join(error_messages)) |
| 53 | + |
| 54 | + return milestone_url |
6 | 55 |
|
7 | 56 |
|
8 | | -REDMINE_QUERY_URL = "https://pulp.plan.io/issues?set_filter=1&status_id=*&issue_id=" |
9 | 57 | release_path = os.path.dirname(os.path.abspath(__file__)) |
10 | 58 | plugin_path = release_path |
11 | 59 | if ".travis" in release_path: |
12 | 60 | plugin_path = os.path.dirname(release_path) |
13 | 61 |
|
14 | 62 | version = {} |
15 | | -with open(f"{plugin_path}/pulp_python/__init__.py") as fp: |
| 63 | +plugin_name = "pulp_python" |
| 64 | +with open(f"{plugin_path}/{plugin_name}/__init__.py") as fp: |
16 | 65 | version_line = [line for line in fp.readlines() if "__version__" in line][0] |
17 | 66 | exec(version_line, version) |
18 | 67 | release_version = version["__version__"].replace(".dev", "") |
19 | 68 |
|
20 | | -to_close = [] |
21 | | -for filename in os.listdir(f"{plugin_path}/CHANGES"): |
22 | | - if filename.split(".")[0].isdigit(): |
23 | | - to_close.append(filename.split(".")[0]) |
24 | | -issues = ",".join(to_close) |
| 69 | +issues_to_close = [] |
| 70 | +for filename in Path(f"{plugin_path}/CHANGES").rglob("*"): |
| 71 | + if filename.stem.isdigit(): |
| 72 | + issue = filename.stem |
| 73 | + issue_url = f"{REDMINE_URL}/issues/{issue}.json" |
| 74 | + issues_to_close.append(issue) |
| 75 | + |
| 76 | +issues = ",".join(issues_to_close) |
| 77 | +redmine_final_query = f"{REDMINE_QUERY_URL}{issues}" |
| 78 | +milestone_url = validate_redmine_data(redmine_final_query, issues_to_close) |
25 | 79 |
|
26 | 80 | helper = textwrap.dedent( |
27 | 81 | """\ |
|
89 | 143 |
|
90 | 144 | os.system("bump2version release --allow-dirty") |
91 | 145 |
|
92 | | -plugin_name = plugin_path.split("/")[-1] |
93 | 146 | git.add(f"{plugin_path}/{plugin_name}/__init__.py") |
94 | 147 | git.add(f"{plugin_path}/setup.py") |
95 | 148 | git.add(f"{plugin_path}/requirements.txt") |
96 | 149 | git.add(f"{plugin_path}/.bumpversion.cfg") |
97 | | -git.commit("-m", f"Releasing {release_version}\n\n[noissue]") |
| 150 | +git.commit( |
| 151 | + "-m", f"Releasing {release_version}\n\nRedmineQuery: {redmine_final_query}\n{milestone_url}" |
| 152 | +) |
98 | 153 |
|
99 | 154 | sha = repo.head.object.hexsha |
100 | 155 | short_sha = git.rev_parse(sha, short=7) |
101 | 156 |
|
102 | 157 | # Third commit: bump to .dev |
103 | 158 | with open(f"{plugin_path}/requirements.txt", "wt") as setup_file: |
104 | 159 | for line in setup_lines: |
105 | | - if "pulpcore" in line and "pulpcore" not in release_path: |
| 160 | + if "pulpcore" in line and "pulpcore" not in release_path and release_type != "patch": |
106 | 161 | line = f"pulpcore>={lower_pulpcore_version}\n" |
107 | 162 |
|
108 | 163 | setup_file.write(line) |
109 | 164 |
|
110 | 165 | os.system(f"bump2version {release_type} --allow-dirty") |
111 | 166 |
|
112 | 167 | version = {} |
113 | | -with open(f"{plugin_path}/pulp_python/__init__.py") as fp: |
| 168 | +with open(f"{plugin_path}/{plugin_name}/__init__.py") as fp: |
114 | 169 | version_line = [line for line in fp.readlines() if "__version__" in line][0] |
115 | 170 | exec(version_line, version) |
116 | 171 | new_dev_version = version["__version__"] |
|
122 | 177 | git.add(f"{plugin_path}/.bumpversion.cfg") |
123 | 178 | git.commit("-m", f"Bump to {new_dev_version}\n\n[noissue]") |
124 | 179 |
|
125 | | -print(f"\n\nRedmine query of issues to close:\n{REDMINE_QUERY_URL}{issues}") |
| 180 | +print(f"\n\nRedmine query of issues to close:\n{redmine_final_query}") |
126 | 181 | print(f"Release commit == {short_sha}") |
127 | 182 | print(f"All changes were committed on branch: release_{release_version}") |
0 commit comments