Skip to content

Commit 8f20e93

Browse files
committed
Add detection for version update loops
1 parent 32d3833 commit 8f20e93

2 files changed

Lines changed: 32 additions & 3 deletions

File tree

lib/pyxis/github_client.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,14 @@ def octokit(instance = :release_tools)
2323
CLIENT_CONFIGS[instance][:octokit] ||= create_octokit(instance)
2424
end
2525

26+
def without_auto_pagination(octokit)
27+
current_auto_paginate = octokit.instance_variable_get(:@auto_paginate)
28+
octokit.instance_variable_set(:@auto_paginate, false)
29+
yield octokit
30+
ensure
31+
octokit.instance_variable_set(:@auto_paginate, current_auto_paginate)
32+
end
33+
2634
private
2735

2836
def create_octokit(instance)

lib/pyxis/managed_versioning/component_updater.rb

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,12 @@ def update_component_version(current_version, new_version)
6161
GithubClient.octokit.branch(Project::Reticulum.github_path, Project::Reticulum.default_branch).commit.sha
6262
)
6363

64+
update_title = "Update #{component.component_name} version to #{present_sha(new_version)}"
65+
6466
GithubClient.octokit.update_contents(
6567
Project::Reticulum.github_path,
6668
version_file,
67-
"Update #{component.component_name} version to #{present_sha(new_version)}",
69+
update_title,
6870
version_file_content.sha,
6971
new_version,
7072
branch: update_branch
@@ -76,7 +78,7 @@ def update_component_version(current_version, new_version)
7678
Project::Reticulum.github_path,
7779
Project::Reticulum.default_branch,
7880
update_branch,
79-
"Update #{component.component_name} version to #{present_sha(new_version)}",
81+
update_title,
8082
<<~DESCRIPTION
8183
Update #{component.component_name} to #{new_version_link} as part of managed versioning
8284
@@ -85,7 +87,16 @@ def update_component_version(current_version, new_version)
8587
)
8688
logger.info('Created pull request', pull_request_url: pr.html_url)
8789

88-
Pyxis::Services::AutoMergeService.new(Project::Reticulum, pr).execute
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
89100
end
90101

91102
def update_branch_exists?
@@ -124,6 +135,16 @@ def filter_for_passing_checks(commits)
124135
filtered_commits
125136
end
126137

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+
127148
def present_sha(sha)
128149
Presenter::CommitSha.new(sha).as_short
129150
end

0 commit comments

Comments
 (0)