Skip to content

Commit

Permalink
Fix previous build is an upstream build
Browse files Browse the repository at this point in the history
  • Loading branch information
Leow, Max committed Aug 16, 2022
1 parent fa92a37 commit 7971d93
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 15 deletions.
33 changes: 21 additions & 12 deletions duck_jenkins/_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ def pull_upstream(
break
json_file = files[0]
else:
logging.info("No upstream build: %s %s", project_name, build_number)
logging.info("No upstream build in file: %s", json_file)
break

def pull_previous(
Expand All @@ -114,6 +114,8 @@ def pull_previous(
"""
previous_build = build_number - 1
counter = 1
previous_builds = []

while True:
if previous_build == 0:
break
Expand All @@ -124,25 +126,32 @@ def pull_previous(
artifact=artifact
)

if files[2] and not overwrite: # when file exist prior pull
if files[2] and not overwrite:
logging.info('Build exist exiting: %s', previous_build)
break
if not files[0]:

if files[0]:
previous_builds.append(previous_build)
else:
trial -= 1
logging.info('Build exist with remaining trial: %s', trial)
logging.info('Build missing with remaining trial: %s, build: %s', trial, previous_build)
if trial == 0:
break
elif upstream:

previous_build -= 1
counter += 1
if size < counter:
break

if upstream:
for b in previous_builds:
self.pull_upstream(
project_name=project_name,
build_number=previous_build,
build_number=b,
overwrite=overwrite,
artifact=artifact,
recursive=True
)
previous_build -= 1
counter += 1
if size < counter:
break

@classmethod
async def _pull_artifact(
Expand Down Expand Up @@ -290,8 +299,8 @@ def pull(
:return pulled json file, pulled artifact file, is build exist prior pull
"""
json_file = get_json_file(self.data_directory, self.domain_name, project_name, build_number)
logging.info('Overwrite: %s', overwrite)
logging.info('Json file exist: %s, %s, %s', os.path.exists(json_file), project_name, build_number)
logging.info('Json file exist: %s, %s, %s, Overwrite: %s',
os.path.exists(json_file), project_name, build_number, overwrite)

return JenkinsData._pull(
domain_name=self.domain_name,
Expand Down
2 changes: 1 addition & 1 deletion duck_jenkins/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def upstream_lookup(json_file: str):
"""
jpath = '$.actions[?(@._class=="hudson.model.CauseAction")].causes'
causes = json_lookup(json_file, jpath)
logging.info(causes)
logging.debug(causes)
if causes:
return causes[-1]
return None
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

setuptools.setup(
name="duck-jenkins",
version="0.0.20",
version="0.0.21",
install_requires=[
"duckdb",
"pandas",
Expand Down
2 changes: 1 addition & 1 deletion tests/test_jenkins.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ def test_pull_without_recursive_upstream(jenkins_data):

@responses.activate
@pytest.mark.parametrize("trial", [2, 3, 5])
def test_pull_previous_build_trial(jenkins_data, trial):
def test_pull_previous_build_trial_when_not_exist(jenkins_data, trial):
for i in range(trial):
responses.add(
responses.GET,
Expand Down

0 comments on commit 7971d93

Please sign in to comment.