Skip to content

Commit b9f173a

Browse files
pyasiPeter Yasi
andauthored
Ad quote_plus to branch params (#101)
* Add quote_plus * chore: bump version to 1.2.5 --------- Co-authored-by: Peter Yasi <peterya@zillowgroup.com>
1 parent bad3bd4 commit b9f173a

File tree

3 files changed

+25
-13
lines changed

3 files changed

+25
-13
lines changed

pybuildkite/builds.py

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import datetime
22
from enum import Enum
33
from typing import List
4+
import urllib.parse
45

56
from pybuildkite.client import Client
67
from pybuildkite.exceptions import (
@@ -81,7 +82,7 @@ def list_all(
8182
with_pagination=False,
8283
):
8384
"""
84-
Returns a paginated list of all builds across all the users organizations and pipelines. If using
85+
Returns a paginated list of all builds across all the user's organizations and pipelines. If using
8586
token-based authentication the list of builds will be for the authorized organizations only. Builds are
8687
listed in the order they were created (newest first).
8788
@@ -93,11 +94,11 @@ def list_all(
9394
:param meta_data: Filters the results by the given meta_data. Example: ?meta_data[some-key]=some-value
9495
:param branch: Filters the results by the given branch or branches.
9596
:param commit: Filters the results by the commit (only works for full sha, not for shortened ones).
96-
:param include_retried_jobs: Include all retried job executions in each builds jobs list if True.
97+
:param include_retried_jobs: Include all retried job executions in each build's jobs list if True.
9798
Without this parameter, you'll see only the most recently run job for each step.
9899
:param page: Int to determine which page to read from (See Pagination in README)
99100
:param with_pagination: Bool to return a response with pagination attributes
100-
:return: Returns a paginated list of all builds across all the users organizations and pipelines
101+
:return: Returns a paginated list of all builds across all the user's organizations and pipelines
101102
"""
102103
self.__validate_dates([created_from, created_to, finished_from])
103104
self.__are_valid_states(states)
@@ -135,7 +136,7 @@ def list_all_for_org(
135136
with_pagination=False,
136137
):
137138
"""
138-
Returns a paginated list of an organizations builds across all of an organizations pipelines. Builds are
139+
Returns a paginated list of an organization's builds across all of an organization's pipelines. Builds are
139140
listed in the order they were created (newest first).
140141
141142
:param organization: Organization slug
@@ -147,11 +148,11 @@ def list_all_for_org(
147148
:param meta_data: Filters the results by the given meta_data.
148149
:param branch: Filters the results by the given branch or branches.
149150
:param commit: Filters the results by the commit (only works for full sha, not for shortened ones).
150-
:param include_retried_jobs: Include all retried job executions in each builds jobs list if True.
151+
:param include_retried_jobs: Include all retried job executions in each build's jobs list if True.
151152
Without this parameter, you'll see only the most recently run job for each step.
152153
:param page: Int to determine which page to read from (See Pagination in README)
153154
:param with_pagination: Bool to return a response with pagination attributes
154-
:return: Returns a paginated list of an organizations builds across all of an organizations pipelines.
155+
:return: Returns a paginated list of an organization's builds across all of an organization's pipelines.
155156
"""
156157

157158
self.__validate_dates([created_from, created_to, finished_from])
@@ -193,7 +194,7 @@ def list_all_for_pipeline(
193194
with_pagination=False,
194195
):
195196
"""
196-
Returns a paginated list of a pipelines builds. Builds are listed in the order they were created (newest
197+
Returns a paginated list of a pipeline's builds. Builds are listed in the order they were created (newest
197198
first).
198199
199200
:param organization: Organization slug
@@ -206,11 +207,11 @@ def list_all_for_pipeline(
206207
:param meta_data: Filters the results by the given meta_data.
207208
:param branch: Filters the results by the given branch or branches.
208209
:param commit: Filters the results by the commit (only works for full sha, not for shortened ones).
209-
:param include_retried_jobs: Include all retried job executions in each builds jobs list if True.
210+
:param include_retried_jobs: Include all retried job executions in each build's jobs list if True.
210211
Without this parameter, you'll see only the most recently run job for each step.
211212
:param page: Int to determine which page to read from (See Pagination in README)
212213
:param with_pagination: Bool to return a response with pagination attributes
213-
:return: Returns a paginated list of a pipelines builds.
214+
:return: Returns a paginated list of a pipeline's builds.
214215
"""
215216

216217
self.__validate_dates([created_from, created_to, finished_from])
@@ -244,7 +245,7 @@ def get_build_by_number(
244245
:param organization: Organization slug
245246
:param pipeline: Pipeline slug
246247
:param build_number: Build number
247-
:param include_retried_jobs: Include all retried job executions in each builds jobs list if True.
248+
:param include_retried_jobs: Include all retried job executions in each build's jobs list if True.
248249
Without this parameter, you'll see only the most recently run job for each step.
249250
:return: A build
250251
"""
@@ -376,7 +377,9 @@ def __get_branches_query_param(branches):
376377
if isinstance(branches, List):
377378
param_string = ""
378379
for branch in branches:
379-
param_string += "branch[]={}&".format(branch)
380+
encoded_branch = urllib.parse.quote_plus(branch)
381+
param_string += f"branch[]={{}}&".format(encoded_branch)
380382
return param_string[:-1]
381383
else:
382-
return "branch=" + branches
384+
encoded_branch = urllib.parse.quote_plus(branches)
385+
return f"branch={{}}".format(encoded_branch)

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = "pybuildkite"
3-
version = "1.2.4"
3+
version = "1.2.5"
44
description = "Python wrapper for the Buildkite API"
55
readme = "README.md"
66
license = { file = "LICENSE" }

tests/test_builds.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,3 +236,12 @@ def test_single_branch(fake_client):
236236

237237
args = fake_client.get.call_args[0][1]
238238
assert args["branch"] == "branch=main"
239+
240+
241+
def test_branch_with_special_characters(fake_client):
242+
builds = Builds(fake_client, "https://api.buildkite.com/v2/")
243+
branch_name = "feature#123"
244+
builds.list_all_for_pipeline(organization="org", pipeline="pipe", branch=branch_name)
245+
args = fake_client.get.call_args[0][1]
246+
# '#' should be encoded as '%23'
247+
assert args["branch"] == "branch=feature%23123"

0 commit comments

Comments
 (0)