-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFindLatestVer.py
115 lines (87 loc) · 3.3 KB
/
FindLatestVer.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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
import requests
import polars as pl
import os
pat = os.environ["TOKEN"]
if not pat:
raise RuntimeError("TOKEN env var is not set")
headers = {"Authorization": f"token {pat}",
"Accept": "application/vnd.github.v3+json",
}
def get_all_pages(url, params=None):
all_data = []
while True:
response = requests.get(url, params=params, headers = headers)
if response.status_code == 200:
data = response.json()
all_data.extend(data)
next_link = response.links.get("next", {}).get("url")
if not next_link:
break
url = next_link
else:
print(f"Error retrieving releases: {response.status_code}")
return None
return all_data
def get_release_versions(username, repo_name, per_page=100):
url = f"https://api.github.com/repos/{username}/{repo_name}/releases"
params = {"per_page": per_page} # Adjust per_page as needed
all_releases = get_all_pages(url, params)
if all_releases:
return [release["tag_name"] for release in all_releases]
else:
return None
def get_latest_release_version(username, repo_name):
url = f"https://api.github.com/repos/{username}/{repo_name}/releases/latest"
response = requests.get(url, headers=headers)
if response.status_code == 200:
data = response.json()
return data["tag_name"]
else:
print(f"Error retrieving releases: {response.status_code}")
return None
def versions(username, reponame):
latest_version, early_lat_ver, early_versions = None, None, None
latest_version = get_latest_release_version(username, reponame)
versions = get_release_versions(username, reponame)
print(latest_version)
print(versions)
if versions!= None:
early_versions = "absent" if versions[0] == latest_version else "present"
early_lat_ver = versions[0]
return latest_version, early_lat_ver, early_versions
df = pl.read_csv("data/GitHub_Release.csv")
df_new = df.filter(pl.col('version_pattern_match') == 'PatternMatchOnlyNum')
github_latest_vers = []
update_requires = []
ear_lat_versions = []
early_versionss = []
for row in df_new.rows():
username, reponame, winget_latest_ver = row[0], row[1], row[2]
github_latest_ver, ear_lat_version, early_versions = versions(username, reponame)
if ear_lat_version!= None:
if winget_latest_ver.lower() in ear_lat_version.lower():
update_require = "No"
elif github_latest_ver!= None:
if winget_latest_ver.lower() in github_latest_ver.lower():
update_require = "No"
else:
update_require = "Yes"
else:
update_require = "NA"
print(username)
print(reponame)
print(github_latest_ver)
print(winget_latest_ver)
print(update_require)
print()
github_latest_vers.append(github_latest_ver)
update_requires.append(update_require)
ear_lat_versions.append(ear_lat_version)
early_versionss.append(early_versions)
df_new = df_new.with_columns([
pl.Series(name="update_requires", values=update_requires),
pl.Series(name="github_latest_vers", values=github_latest_vers),
pl.Series(name="github_earliest_vers", values=ear_lat_versions),
pl.Series(name="IsEarliestVerReleases", values=early_versionss),
])
df_new.write_csv("data/GitHub_Releasess.csv")