66# For more info visit https://github.com/pulp/plugin_template
77
88import argparse
9- import json
109import re
1110import os
1211import textwrap
13- from collections import defaultdict
14- from pathlib import Path
1512
1613from git import Repo
17- from redminelib import Redmine
18- from redminelib .exceptions import ResourceAttrError
19-
20-
21- REDMINE_URL = "https://pulp.plan.io"
22- REDMINE_QUERY_URL = f"{ REDMINE_URL } /issues?set_filter=1&status_id=*&issue_id="
23-
24-
25- def validate_redmine_data (redmine_query_url , redmine_issues ):
26- """Validate redmine milestone."""
27- redmine = Redmine ("https://pulp.plan.io" )
28- project_set = set ()
29- stats = defaultdict (list )
30- milestone_url = "\n [noissue]"
31- milestone_id = None
32- for issue in redmine_issues :
33- redmine_issue = redmine .issue .get (int (issue ))
34-
35- project_name = redmine_issue .project .name
36- project_set .update ([project_name ])
37- stats [f"project_{ project_name .lower ().replace (' ' , '_' )} " ].append (issue )
38-
39- status = redmine_issue .status .name
40- if "CLOSE" not in status and status != "MODIFIED" :
41- stats ["status_not_modified" ].append (issue )
42-
43- try :
44- milestone = redmine_issue .fixed_version .name
45- milestone_id = redmine_issue .fixed_version .id
46- stats [f"milestone_{ milestone } " ].append (issue )
47- except ResourceAttrError :
48- stats ["without_milestone" ].append (issue )
49-
50- if milestone_id is not None :
51- milestone_url = f"Redmine Milestone: { REDMINE_URL } /versions/{ milestone_id } .json\n [noissue]"
52-
53- print (f"\n \n Redmine stats: { json .dumps (stats , indent = 2 )} " )
54- error_messages = []
55- if stats .get ("status_not_modified" ):
56- error_messages .append (f"One or more issues are not MODIFIED { stats ['status_not_modified' ]} " )
57- if stats .get ("without_milestone" ):
58- error_messages .append (
59- f"One or more issues are not associated with a milestone { stats ['without_milestone' ]} "
60- )
61- if len (project_set ) > 1 :
62- error_messages .append (f"Issues with different projects - { project_set } " )
63- if error_messages :
64- error_messages .append (f"Verify at { redmine_query_url } " )
65- raise RuntimeError ("\n " .join (error_messages ))
66-
67- return milestone_url
6814
6915
7016release_path = os .path .dirname (os .path .abspath (__file__ ))
@@ -81,17 +27,6 @@ def validate_redmine_data(redmine_query_url, redmine_issues):
8127release_version = version .replace (".dev" , "" )
8228
8329
84- issues_to_close = []
85- for filename in Path (f"{ plugin_path } /CHANGES" ).rglob ("*" ):
86- if filename .stem .isdigit ():
87- issue = filename .stem
88- issue_url = f"{ REDMINE_URL } /issues/{ issue } .json"
89- issues_to_close .append (issue )
90-
91- issues = "," .join (issues_to_close )
92- redmine_final_query = f"{ REDMINE_QUERY_URL } { issues } "
93- milestone_url = validate_redmine_data (redmine_final_query , issues_to_close )
94-
9530helper = textwrap .dedent (
9631 """\
9732 Start the release process.
@@ -165,10 +100,9 @@ def validate_redmine_data(redmine_query_url, redmine_issues):
165100git .add (f"{ plugin_path } /setup.py" )
166101git .add (f"{ plugin_path } /requirements.txt" )
167102git .add (f"{ plugin_path } /.bumpversion.cfg" )
168- git .commit (
169- "-m" ,
170- f"Release { release_version } \n \n Redmine Query: { redmine_final_query } \n { milestone_url } " ,
171- )
103+
104+ git .commit ("-m" , f"Release { release_version } " )
105+
172106
173107sha = repo .head .object .hexsha
174108short_sha = git .rev_parse (sha , short = 7 )
@@ -199,6 +133,6 @@ def validate_redmine_data(redmine_query_url, redmine_issues):
199133git .add (f"{ plugin_path } /.bumpversion.cfg" )
200134git .commit ("-m" , f"Bump to { new_dev_version } \n \n [noissue]" )
201135
202- print ( f" \n \n Redmine query of issues to close: \n { redmine_final_query } " )
136+
203137print (f"Release commit == { short_sha } " )
204138print (f"All changes were committed on branch: release_{ release_version } " )
0 commit comments