mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
Verify SHA in Shippable change detection.
This commit is contained in:
parent
273786d0bd
commit
5e9a2b8528
2 changed files with 18 additions and 3 deletions
|
@ -71,7 +71,7 @@ class ShippableChanges(object):
|
|||
self.paths = sorted(git.get_diff_names([self.branch]))
|
||||
else:
|
||||
merge_runs = self.get_merge_runs(self.project_id, self.branch)
|
||||
last_successful_commit = self.get_last_successful_commit(merge_runs)
|
||||
last_successful_commit = self.get_last_successful_commit(git, merge_runs)
|
||||
|
||||
if last_successful_commit:
|
||||
self.paths = sorted(git.get_diff_names([last_successful_commit, self.commit]))
|
||||
|
@ -96,8 +96,9 @@ class ShippableChanges(object):
|
|||
return response.json()
|
||||
|
||||
@staticmethod
|
||||
def get_last_successful_commit(merge_runs):
|
||||
def get_last_successful_commit(git, merge_runs):
|
||||
"""
|
||||
:type git: Git
|
||||
:type merge_runs: dict | list[dict]
|
||||
:rtype: str
|
||||
"""
|
||||
|
@ -114,7 +115,8 @@ class ShippableChanges(object):
|
|||
if commit_sha not in known_commits:
|
||||
known_commits.add(commit_sha)
|
||||
if merge_run['statusCode'] == 30:
|
||||
last_successful_commit = commit_sha
|
||||
if git.is_valid_ref(commit_sha):
|
||||
last_successful_commit = commit_sha
|
||||
|
||||
return last_successful_commit
|
||||
|
||||
|
|
|
@ -4,6 +4,7 @@ from __future__ import absolute_import, print_function
|
|||
|
||||
from lib.util import (
|
||||
CommonConfig,
|
||||
SubprocessError,
|
||||
run_command,
|
||||
)
|
||||
|
||||
|
@ -55,6 +56,18 @@ class Git(object):
|
|||
cmd = ['merge-base', '--fork-point', branch]
|
||||
return self.run_git(cmd).strip()
|
||||
|
||||
def is_valid_ref(self, ref):
|
||||
"""
|
||||
:type ref: str
|
||||
:rtype: bool
|
||||
"""
|
||||
cmd = ['show', ref]
|
||||
try:
|
||||
self.run_git(cmd)
|
||||
return True
|
||||
except SubprocessError:
|
||||
return False
|
||||
|
||||
def run_git_split(self, cmd, separator=None):
|
||||
"""
|
||||
:type cmd: list[str]
|
||||
|
|
Loading…
Reference in a new issue