-
-
Notifications
You must be signed in to change notification settings - Fork 456
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add set_active_docs.py to set what versions are visible
- Loading branch information
1 parent
579a668
commit 411a2ff
Showing
1 changed file
with
48 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import os | ||
import sys | ||
|
||
import packaging.version | ||
import requests | ||
|
||
current_version = packaging.version.parse(sys.stdin.readline().strip("v\n")) | ||
project = "praw" | ||
headers = {"Authorization": f"token {os.environ.get('READTHEDOCS_TOKEN')}"} | ||
|
||
response = requests.get( | ||
f"https://readthedocs.org/api/v3/projects/{project}/versions?active=true", | ||
headers=headers, | ||
) | ||
active_versions = response.json() | ||
versions = [ | ||
packaging.version.parse(slug["slug"].strip("v")) | ||
for slug in active_versions["results"] | ||
if not slug["hidden"] | ||
] | ||
|
||
aggregated_versions = {} | ||
for version in versions: | ||
aggregated_versions.setdefault(version.major, []) | ||
aggregated_versions[version.major].append(version) | ||
|
||
latest_major_versions = [ | ||
max(aggregated_versions[major]) for major in aggregated_versions | ||
] | ||
major_versions = [version.major for version in versions] | ||
is_new_major = major_versions.count(current_version.major) == 1 | ||
|
||
for version in versions: | ||
if (is_new_major and version not in latest_major_versions) or ( | ||
(version.major, version.minor) | ||
== ( | ||
current_version.major, | ||
current_version.minor, | ||
) | ||
and version.micro != current_version.micro | ||
): | ||
response = requests.patch( | ||
f"https://readthedocs.org/api/v3/projects/{project}/versions/v{version}/", | ||
json={"active": True, "hidden": True}, | ||
headers=headers, | ||
) | ||
if response.status_code == 204: | ||
print(f"Version {version!s} was hidden successfully.") |