-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcheck_cfbd_api_compatability.py
98 lines (78 loc) · 2.9 KB
/
check_cfbd_api_compatability.py
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
"""
# Creation Date: 10/06/2023 05:23 EDT
# Last Updated Date: 04/04/2024 05:10 PM EDT
# Author: Joseph Armstrong (armstrongjoseph08@gmail.com)
# File Name: check_cfbd_api_compatibility.py
# Purpose: Checks if the API Version that this package is designed for
is the same as the current version of the CFBD API
"""
import json
import requests
def check_cfbd_api_compatibility():
"""
Checks if the CFBD API version that `cfbd-json-py` is compatible with
is the current version of the CFBD API.
Parameters
----------
None.
Usage
----------
Use the `check_cfbd_api_script.py` python script.
Do not call this script outside of the `cfbd-json-py` GitHub repo.
Returns
----------
Nothing, unless there is a change in version for the CFBD API,
in which this function will raise an exception.
"""
with open("cfbd_api_version.json", "r") as f:
json_str = f.read()
json_data = json.loads(json_str)
cfbd_json_py_version = json_data["current_version"]
del json_str, json_data
cfbd_swagger_json_url = (
"https://raw.githubusercontent.com" + "/CFBD/cfb-api/main/swagger.json"
)
response = requests.get(cfbd_swagger_json_url)
if response.status_code == 200:
pass
elif response.status_code == 401:
raise ConnectionRefusedError(
"Could not connect. The connection was refused.\n" +
"HTTP Status Code 401."
)
else:
raise ConnectionError(
f"Could not connect.\nHTTP Status code {response.status_code}"
)
json_data = response.json()
cfbd_api_version = json_data["info"]["version"]
del response, json_data
print(
f"Package Compatibility Version:\t{cfbd_json_py_version}\n"
+ f"Current CFBD API Version:\t{cfbd_api_version}"
)
if cfbd_api_version == cfbd_json_py_version:
print("Version match confirmed. No need to raise an exception.")
else:
print(
"Version match unconfirmed. "
+ "Raising a `ValueError` exception to make it clear "
+ "that there is a version mismatch."
)
raise ValueError(
"There is a difference "
+ "between the current version of the CFBD API, "
+ "and the version of the CFBD API "
+ "this package is compatible with."
+ "\nIf you see this message, and an issue has not been raised, "
+ "create an issue with the following parameters:"
+ f"\nTitle: Package needs to be upgraded to {cfbd_api_version}"
+ "\nContent: The `cfbd-json-py` package is compatible "
+ f"with the {cfbd_json_py_version} version of the CFBD API, "
+ f"but the current version of the CFBD API is {cfbd_api_version}."
f"\nLabel: `enhancement`"
)
def main():
check_cfbd_api_compatibility()
if __name__ == "__main__":
main()