17
17
SER_VER_ID_PROPERTY_PTN = SER_VER_ID_PROPERTY .replace ('.' , r'\.' )
18
18
SER_VER_ID_PATTERN = re .compile (
19
19
'<' + SER_VER_ID_PROPERTY_PTN + r'>\s*(.*)\s*</' + SER_VER_ID_PROPERTY_PTN + '>' )
20
+ OTP_GITHUB_PULLREQUEST_URL = "https://github.com/opentripplanner/OpenTripPlanner/pull/"
20
21
STATE_FILE = '.custom_release_resume_state.json'
21
22
SUMMARY_FILE = '.custom_release_summary.md'
22
23
@@ -100,8 +101,7 @@ def description_w_labels(self):
100
101
return f'{ self .description ()} { self .labels } '
101
102
102
103
def description_link (self ):
103
- url = f"https://github.com/opentripplanner/OpenTripPlanner/pull/{ self .number } "
104
- return f"[{ self .description ()} ]({ url } ) { self .labels } " .replace ("'" , "`" )
104
+ return f"[{ self .description ()} ]({ OTP_GITHUB_PULLREQUEST_URL } { self .number } ) { self .labels } " .replace ("'" , "`" )
105
105
106
106
# The execution state of the script + the CLI arguments
107
107
class ScriptState :
@@ -116,15 +116,15 @@ def __init__(self):
116
116
self .gotoStep = False
117
117
self .step = None
118
118
119
- def next_version_tag (self ):
120
- return f'v{ self .next_version } '
121
-
122
119
def latest_version_tag (self ):
123
120
return f'v{ self .latest_version } '
124
121
125
122
def latest_version_git_hash (self ):
126
123
return git_commit_hash (self .latest_version_tag ())
127
124
125
+ def next_version_tag (self ):
126
+ return f'v{ self .next_version } '
127
+
128
128
def next_version_description (self ):
129
129
return f'Version { self .next_version } ({ self .next_ser_ver_id } )'
130
130
@@ -207,6 +207,7 @@ def setup_and_verify():
207
207
resolve_version_number ()
208
208
resolve_next_version ()
209
209
read_pull_request_info_from_github ()
210
+ check_if_prs_exist_in_latest_release ()
210
211
resolve_next_ser_ver_id ()
211
212
print_setup ()
212
213
@@ -328,7 +329,11 @@ def print_summary():
328
329
print (f"These PRs are tagged with { config .include_prs_label } .\n " , file = f )
329
330
for pr in pullRequests :
330
331
print (f" - { pr .link ()} " , file = f )
331
- p = execute ("./script/changelog-diff.py" , state .latest_version_tag (), state .next_version_tag ())
332
+ p = execute (
333
+ "./script/changelog-diff.py" ,
334
+ state .latest_version_tag (),
335
+ state .next_version_tag ()
336
+ )
332
337
print (p .stdout , file = f )
333
338
334
339
@@ -506,25 +511,35 @@ def read_pull_request_info_from_github():
506
511
# Example response
507
512
# {"data":{"repository":{"pullRequests":{"nodes":[{"number":2222,"labels":{"nodes":[{"name":"bump serialization id"},{"name":"Entur Test"}]}}]}}}}
508
513
json_doc = json .loads (result .stdout )
514
+ defined_labels = [LBL_BUMP_SER_VER_ID .lower (), config .include_prs_label .lower ()]
515
+
509
516
for node in json_doc ['data' ]['repository' ]['pullRequests' ]['nodes' ]:
510
517
pr = PullRequest ()
511
518
pr .number = node ['number' ]
512
519
pr .title = node ['title' ]
513
520
pr .commitHash = node ['headRefOid' ]
514
521
labels = node ['labels' ]['nodes' ]
515
522
# GitHub labels are not case-sensitive, hence using 'lower()'
516
- include_prs_label_lc = config .include_prs_label .lower ()
517
523
for label in labels :
518
524
lbl_name = label ['name' ]
519
525
lbl_name_lc = lbl_name .lower ()
520
- if include_prs_label_lc == lbl_name_lc :
521
- pr .labels .append (lbl_name )
522
- if LBL_BUMP_SER_VER_ID == lbl_name_lc :
526
+ if lbl_name_lc in defined_labels :
523
527
pr .labels .append (lbl_name )
524
- state .prs_bump_ser_ver_id = True
525
528
pullRequests .append (pr )
526
529
527
530
531
+ def check_if_prs_exist_in_latest_release ():
532
+ info (f'Check if one of the PRs labeled with { LBL_BUMP_SER_VER_ID } does not exist in the '
533
+ f'latest release. If so, bump the ser.ver.id ...' )
534
+ latest_release_hash = state .latest_version_git_hash ()
535
+
536
+ for pr in pullRequests :
537
+ if pr .serLabelSet and not git_is_commit_ancestor (pr .commitHash , latest_release_hash ):
538
+ info (f' - The top commit does not exist in the latest release. Bumping ser.ver.id. ({ pr .description ()} )' )
539
+ state .prs_bump_ser_ver_id = True
540
+ return
541
+
542
+
528
543
# The script will resolve what the next serialization version id (SID) should be. This is a complex task.
529
544
# Here is an overview:
530
545
# 1. If the --serVerId option exist, then the latest SID is bumped and used.
@@ -658,18 +673,6 @@ def delete_script_state():
658
673
## Utility functions ##
659
674
## ------------------------------------------------------------------------------------ ##
660
675
661
- # Get the full git hash for a qualified branch name, tag or hash
662
- def git_commit_hash (ref ):
663
- if re .compile (r'[0-9a-f]{40}' ).match (ref ):
664
- return ref
665
- output = execute ('git' , 'show-ref' , ref ).stdout
666
- return output .split ()[0 ]
667
-
668
-
669
- # Create a tag name used in git for a given version
670
- def git_tag (version ):
671
- return f'v{ version } '
672
-
673
676
674
677
def bump_release_ser_ver_id (latest_id ):
675
678
# The id format can be either 'A-00053' or 'AA-0053'
@@ -711,6 +714,19 @@ def run_maven_test():
711
714
mvn ('clean' , '-PprettierSkip' , 'test' )
712
715
713
716
717
+ # Get the full git hash for a qualified branch name, tag or hash
718
+ def git_commit_hash (ref ):
719
+ if re .compile (r'[0-9a-f]{40}' ).match (ref ):
720
+ return ref
721
+ output = execute ('git' , 'show-ref' , ref ).stdout
722
+ return output .split ()[0 ]
723
+
724
+
725
+ def git_is_commit_ancestor (childCommit : str , parentCommit : str ):
726
+ p = subprocess .run ("git" , "merge-base" "--is-ancestor" , childCommit , parentCommit , timeout = 5 )
727
+ return p .returncode == 0
728
+
729
+
714
730
def git (* cmd , error_msg = None ):
715
731
return execute ('git' , * cmd , error_msg = error_msg )
716
732
0 commit comments