@@ -30,39 +30,7 @@ def execute
3030
3131 logger . info ( 'Updating component version' , current_version : current_version , new_version : new_version )
3232
33- unless Pyxis ::GlobalStatus . dry_run?
34- GithubClient . octokit . create_ref (
35- Project ::Reticulum . github_path ,
36- "refs/heads/#{ update_branch } " ,
37- GithubClient . octokit . branch ( Project ::Reticulum . github_path , Project ::Reticulum . default_branch ) . commit . sha
38- )
39-
40- GithubClient . octokit . update_contents (
41- Project ::Reticulum . github_path ,
42- version_file ,
43- "Update #{ component . component_name } version to #{ present_sha ( new_version ) } " ,
44- version_file_content . sha ,
45- new_version ,
46- branch : update_branch
47- )
48-
49- new_version_link = "[#{ present_sha ( new_version ) } ](https://github.com/#{ component . github_path } /commits/#{ new_version } )"
50-
51- pr = GithubClient . octokit . create_pull_request (
52- Project ::Reticulum . github_path ,
53- Project ::Reticulum . default_branch ,
54- update_branch ,
55- "Update #{ component . component_name } version to #{ present_sha ( new_version ) } " ,
56- <<~DESCRIPTION
57- Update #{ component . component_name } to #{ new_version_link } as part of managed versioning
58-
59- #{ Presenter ::CommitRange . new ( component , current_version , new_version ) . as_markdown }
60- DESCRIPTION
61- )
62- logger . info ( 'Created pull request' , pull_request_url : pr . html_url )
63-
64- Pyxis ::Services ::AutoMergeService . new ( Project ::Reticulum , pr ) . execute
65- end
33+ update_component_version ( current_version , new_version ) unless Pyxis ::GlobalStatus . dry_run?
6634
6735 logger . info ( 'Finished component updater' , current_version : current_version , new_version : new_version )
6836 end
@@ -86,6 +54,51 @@ def update_branch
8654
8755 private
8856
57+ def update_component_version ( current_version , new_version )
58+ GithubClient . octokit . create_ref (
59+ Project ::Reticulum . github_path ,
60+ "refs/heads/#{ update_branch } " ,
61+ GithubClient . octokit . branch ( Project ::Reticulum . github_path , Project ::Reticulum . default_branch ) . commit . sha
62+ )
63+
64+ update_title = "Update #{ component . component_name } version to #{ present_sha ( new_version ) } "
65+
66+ GithubClient . octokit . update_contents (
67+ Project ::Reticulum . github_path ,
68+ version_file ,
69+ update_title ,
70+ version_file_content . sha ,
71+ new_version ,
72+ branch : update_branch
73+ )
74+
75+ new_version_link = "[#{ present_sha ( new_version ) } ](https://github.com/#{ component . github_path } /commits/#{ new_version } )"
76+
77+ pr = GithubClient . octokit . create_pull_request (
78+ Project ::Reticulum . github_path ,
79+ Project ::Reticulum . default_branch ,
80+ update_branch ,
81+ update_title ,
82+ <<~DESCRIPTION
83+ Update #{ component . component_name } to #{ new_version_link } as part of managed versioning
84+
85+ #{ Presenter ::CommitRange . new ( component , current_version , new_version ) . as_markdown }
86+ DESCRIPTION
87+ )
88+ logger . info ( 'Created pull request' , pull_request_url : pr . html_url )
89+
90+ if version_update_loop? ( update_title )
91+ GithubClient . octokit . add_comment (
92+ Project ::Reticulum . github_path ,
93+ pr . number ,
94+ '@code0-tech/delivery This component had already been updated to this version in the past. ' \
95+ 'Please check why this component is getting updated to this version again.'
96+ )
97+ else
98+ Pyxis ::Services ::AutoMergeService . new ( Project ::Reticulum , pr ) . execute
99+ end
100+ end
101+
89102 def update_branch_exists?
90103 GithubClient . octokit . branch ( Project ::Reticulum . github_path , update_branch ) . name == update_branch
91104 rescue Octokit ::NotFound
@@ -122,6 +135,16 @@ def filter_for_passing_checks(commits)
122135 filtered_commits
123136 end
124137
138+ def version_update_loop? ( update_title )
139+ commits = GithubClient . without_auto_pagination ( GithubClient . octokit ) do |octokit |
140+ octokit . list_commits (
141+ Project ::Reticulum . github_path ,
142+ path : version_file
143+ )
144+ end
145+ commits . reverse . any? { |commit | commit . commit . message == update_title }
146+ end
147+
125148 def present_sha ( sha )
126149 Presenter ::CommitSha . new ( sha ) . as_short
127150 end
0 commit comments