Skip to content

Commit 016d48a

Browse files
author
Jacob Truman
committed
XENG-9362 Support github api without version
1 parent 618bd25 commit 016d48a

File tree

3 files changed

+22
-9
lines changed

3 files changed

+22
-9
lines changed

buildrunner/config/fetch/github.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,11 @@
1515
BuildRunnerProtocolError,
1616
)
1717

18+
def _clean_nones(items):
19+
return list(filter(None, items))
1820

19-
def v3_fetch_file(parsed_url, gh_config: GithubModel):
21+
22+
def _fetch_file(parsed_url, gh_config: GithubModel):
2023
"""
2124
Fetch files using Github v3 protocol.
2225
"""
@@ -30,12 +33,12 @@ def v3_fetch_file(parsed_url, gh_config: GithubModel):
3033

3134
auth = (username, gh_config.app_token)
3235
url = "/".join(
33-
(
36+
_clean_nones([
3437
endpoint,
3538
version,
3639
"users",
3740
username,
38-
)
41+
])
3942
)
4043
resp = requests.get(url, auth=auth, timeout=180)
4144
if resp.status_code != 200:
@@ -47,7 +50,7 @@ def v3_fetch_file(parsed_url, gh_config: GithubModel):
4750
raise ValueError('URL must begin with "/"')
4851

4952
fpath = parsed_url.path.split("/")
50-
ubuild = [endpoint, version, "repos", fpath[1], fpath[2], "contents"]
53+
ubuild = _clean_nones([endpoint, version, "repos", fpath[1], fpath[2], "contents"])
5154
ubuild.extend(fpath[3:])
5255
url = "/".join(ubuild)
5356
resp = requests.get(url, auth=auth, timeout=180)
@@ -97,9 +100,9 @@ def fetch_file(parsed_url, config: GlobalConfig):
97100
)
98101

99102
ver = nlcfg.version
100-
# NOTE: potentially the v3_fetch_file() works for other github API versions.
101-
if ver == "v3":
102-
contents = v3_fetch_file(parsed_url, nlcfg)
103+
# NOTE: potentially the _fetch_file() works for other github API versions.
104+
if ver == "v3" or ver is None:
105+
contents = _fetch_file(parsed_url, nlcfg)
103106
else:
104107
raise NotImplementedError(f"No version support for github API version {ver}")
105108

buildrunner/config/models.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030

3131
class GithubModel(BaseModel, extra="forbid"):
3232
endpoint: str
33-
version: str
33+
version: str = None
3434
username: str = os.getenv("USER", os.getenv("LOGNAME"))
3535
app_token: str = ""
3636

docs/fetching-files.rst

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ The ``github://`` facility requires the following configuration entries:
5757
github:
5858
LABEL:
5959
endpoint: 'https://HOSTNAME/API_PATH'
60-
version: 'VERSION'
60+
version: 'VERSION' // optional
6161
username: 'USERNAME'
6262
app_token: 'APP_TOKEN'
6363
@@ -72,6 +72,16 @@ The following is suggested for an entry to reference files for GitHub Enterprise
7272
username: 'USERNAME'
7373
app_token: 'APP_TOKEN'
7474
75+
The following is suggested for an entry to reference files for GitHub.com:
76+
77+
.. code:: yaml
78+
79+
github:
80+
github:
81+
endpoint: 'https://api.github.com'
82+
username: 'USERNAME'
83+
app_token: 'APP_TOKEN'
84+
7585
:username: The individual username used to access the Github Enterprise instance.
7686
:app_token: The user-specific application token generated by the user on Github for Buildrunner
7787
access. It is a 40 hex digit token.

0 commit comments

Comments
 (0)