Skip to content

Commit

Permalink
Merge pull request #58 from EnricoMi/branch-get-build-with-retried-jobs
Browse files Browse the repository at this point in the history
Allow to get builds with retried jobs
  • Loading branch information
pyasi committed Sep 15, 2020
2 parents d706ea4 + 039fa98 commit e57893d
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 3 deletions.
24 changes: 22 additions & 2 deletions pybuildkite/builds.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ def list_all(
meta_data=None,
branch=None,
commit=None,
include_retried_jobs=None,
page=0,
with_pagination=False,
):
Expand All @@ -91,6 +92,8 @@ def list_all(
:param meta_data: Filters the results by the given meta_data. Example: ?meta_data[some-key]=some-value
:param branch: Filters the results by the given branch or branches.
:param commit: Filters the results by the commit (only works for full sha, not for shortened ones).
:param include_retried_jobs: Include all retried job executions in each build’s jobs list if True.
Without this parameter, you'll see only the most recently run job for each step.
:param page: Int to determine which page to read from (See Pagination in README)
:param with_pagination: Bool to return a response with pagination attributes
:return: Returns a paginated list of all builds across all the user’s organizations and pipelines
Expand All @@ -106,6 +109,7 @@ def list_all(
"state": self.__get_build_states_query_param(states),
"branch": branch,
"commit": commit,
"include_retried_jobs": True if include_retried_jobs is True else None,
"page": page,
}
query_params.update(self.__process_meta_data(meta_data))
Expand All @@ -125,6 +129,7 @@ def list_all_for_org(
meta_data=None,
branch=None,
commit=None,
include_retried_jobs=None,
page=0,
with_pagination=False,
):
Expand All @@ -141,6 +146,8 @@ def list_all_for_org(
:param meta_data: Filters the results by the given meta_data.
:param branch: Filters the results by the given branch or branches.
:param commit: Filters the results by the commit (only works for full sha, not for shortened ones).
:param include_retried_jobs: Include all retried job executions in each build’s jobs list if True.
Without this parameter, you'll see only the most recently run job for each step.
:param page: Int to determine which page to read from (See Pagination in README)
:param with_pagination: Bool to return a response with pagination attributes
:return: Returns a paginated list of an organization’s builds across all of an organization’s pipelines.
Expand All @@ -157,6 +164,7 @@ def list_all_for_org(
"state": self.__get_build_states_query_param(states),
"branch": branch,
"commit": commit,
"include_retried_jobs": True if include_retried_jobs is True else None,
"page": page,
}
query_params.update(self.__process_meta_data(meta_data))
Expand All @@ -179,6 +187,7 @@ def list_all_for_pipeline(
meta_data=None,
branch=None,
commit=None,
include_retried_jobs=None,
page=0,
with_pagination=False,
):
Expand All @@ -196,6 +205,8 @@ def list_all_for_pipeline(
:param meta_data: Filters the results by the given meta_data.
:param branch: Filters the results by the given branch or branches.
:param commit: Filters the results by the commit (only works for full sha, not for shortened ones).
:param include_retried_jobs: Include all retried job executions in each build’s jobs list if True.
Without this parameter, you'll see only the most recently run job for each step.
:param page: Int to determine which page to read from (See Pagination in README)
:param with_pagination: Bool to return a response with pagination attributes
:return: Returns a paginated list of a pipeline’s builds.
Expand All @@ -212,6 +223,7 @@ def list_all_for_pipeline(
"state": self.__get_build_states_query_param(states),
"branch": branch,
"commit": commit,
"include_retried_jobs": True if include_retried_jobs is True else None,
"page": page,
}
query_params.update(self.__process_meta_data(meta_data))
Expand All @@ -222,17 +234,25 @@ def list_all_for_pipeline(
with_pagination=with_pagination,
)

def get_build_by_number(self, organization, pipeline, build_number):
def get_build_by_number(
self, organization, pipeline, build_number, include_retried_jobs=None
):
"""
Get build by build number
:param organization: Organization slug
:param pipeline: Pipeline slug
:param build_number: Build number
:param include_retried_jobs: Include all retried job executions in each build’s jobs list if True.
Without this parameter, you'll see only the most recently run job for each step.
:return: A build
"""
query_params = {
"include_retried_jobs": True if include_retried_jobs is True else None
}
return self.client.get(
self.path_for_build_number.format(organization, pipeline, build_number)
self.path_for_build_number.format(organization, pipeline, build_number),
query_params=query_params,
)

def create_build(
Expand Down
18 changes: 17 additions & 1 deletion tests/test_builds.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ def test_list_all_builds_single_build_state(fake_client):
"state": "state=running",
"branch": None,
"commit": None,
"include_retried_jobs": None,
"page": 0,
},
with_pagination=False,
Expand All @@ -42,6 +43,7 @@ def test_list_all_builds_multiple_build_states(fake_client):
"state": "state[]=running&state[]=finished",
"branch": None,
"commit": None,
"include_retried_jobs": None,
"page": 0,
},
with_pagination=False,
Expand Down Expand Up @@ -79,6 +81,7 @@ def test_list_all_builds_for_org(fake_client):
"state": None,
"branch": None,
"commit": None,
"include_retried_jobs": None,
"page": 0,
},
with_pagination=False,
Expand All @@ -98,6 +101,7 @@ def test_list_all_for_pipeline(fake_client):
"state": None,
"branch": None,
"commit": None,
"include_retried_jobs": None,
"page": 0,
},
with_pagination=False,
Expand All @@ -108,7 +112,19 @@ def test_get_build_by_number(fake_client):
builds = Builds(fake_client, "https://api.buildkite.com/v2/")
builds.get_build_by_number("org_slug", "pipeline_id", "build_number")
fake_client.get.assert_called_with(
builds.path_for_build_number.format("org_slug", "pipeline_id", "build_number")
builds.path_for_build_number.format("org_slug", "pipeline_id", "build_number"),
query_params={"include_retried_jobs": None},
)


def test_get_build_by_number_with_retried_jobs(fake_client):
builds = Builds(fake_client, "https://api.buildkite.com/v2/")
builds.get_build_by_number(
"org_slug", "pipeline_id", "build_number", include_retried_jobs=True
)
fake_client.get.assert_called_with(
builds.path_for_build_number.format("org_slug", "pipeline_id", "build_number"),
query_params={"include_retried_jobs": True},
)


Expand Down

0 comments on commit e57893d

Please sign in to comment.