-
Notifications
You must be signed in to change notification settings - Fork 140
/
resolve_spec_url
executable file
·43 lines (30 loc) · 1.01 KB
/
resolve_spec_url
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#!/usr/bin/env python3
# Usage:
# ./resolve_latest_spec
# Prints the URL of the latest Linode OpenAPI spec on GitHub
import os
import sys
import requests
LINODE_DOCS_REPO = "linode/linode-api-docs"
def get_latest_tag():
headers = {}
token = os.getenv("GITHUB_TOKEN")
if token is not None:
headers["Authorization"] = f"Bearer {token}"
data = requests.get(
f"https://api.github.com/repos/{LINODE_DOCS_REPO}/releases/latest",
headers=headers,
)
if data.status_code != 200:
raise RuntimeError("Got error from GitHub API: {}".format(data.json()))
return data.json()["tag_name"]
if __name__ == "__main__":
if len(sys.argv) != 2:
print(f"Invalid number of arguments: {len(sys.argv)}", file=sys.stderr)
exit(1)
desired_version = sys.argv[1]
if desired_version.lower() == "latest":
desired_version = get_latest_tag()
print(
f"https://raw.githubusercontent.com/{LINODE_DOCS_REPO}/{desired_version}/openapi.yaml"
)