Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix release notes links. Add diff link #366

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions adabot/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# SPDX-FileCopyrightText: 2023 Tim Cocks
#
# SPDX-License-Identifier: MIT

"""AdaBot is a friendly helper bot that works across the web to make people's
lives better."""

REQUESTS_TIMEOUT = 30
16 changes: 11 additions & 5 deletions adabot/arduino_libraries.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

import requests

from adabot import github_requests as gh_reqs
from adabot import github_requests as gh_reqs, REQUESTS_TIMEOUT

logger = logging.getLogger(__name__)
ch = logging.StreamHandler(stream=sys.stdout)
Expand Down Expand Up @@ -86,7 +86,8 @@ def is_arduino_library(repo):
+ repo["name"]
+ "/"
+ repo["default_branch"]
+ "/library.properties"
+ "/library.properties",
timeout=REQUESTS_TIMEOUT,
)
return lib_prop_file.ok

Expand Down Expand Up @@ -116,7 +117,8 @@ def validate_library_properties(repo):
+ repo["name"]
+ "/"
+ repo["default_branch"]
+ "/library.properties"
+ "/library.properties",
timeout=REQUESTS_TIMEOUT,
)
if not lib_prop_file.ok:
# print("{} skipped".format(repo["name"]))
Expand Down Expand Up @@ -193,7 +195,8 @@ def validate_actions(repo):
+ repo["name"]
+ "/"
+ repo["default_branch"]
+ "/.github/workflows/githubci.yml"
+ "/.github/workflows/githubci.yml",
timeout=REQUESTS_TIMEOUT,
)
return repo_has_actions.ok

Expand Down Expand Up @@ -309,7 +312,10 @@ def main(verbosity=1, output_file=None): # pylint: disable=missing-function-doc
logger.setLevel("CRITICAL")

try:
reply = requests.get("http://downloads.arduino.cc/libraries/library_index.json")
reply = requests.get(
"http://downloads.arduino.cc/libraries/library_index.json",
timeout=REQUESTS_TIMEOUT,
)
if not reply.ok:
logging.error(
"Could not fetch http://downloads.arduino.cc/libraries/library_index.json"
Expand Down
4 changes: 2 additions & 2 deletions adabot/circuitpython_library_download_stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
from google.cloud import bigquery
import google.oauth2.service_account

from adabot import github_requests as gh_reqs
from adabot import github_requests as gh_reqs, REQUESTS_TIMEOUT
from adabot.lib import common_funcs

# Setup ArgumentParser
Expand Down Expand Up @@ -60,7 +60,7 @@
def retrieve_piwheels_stats():
"""Get data dump of piwheels download stats"""
stats = {}
response = requests.get(PIWHEELS_PACKAGES_URL)
response = requests.get(PIWHEELS_PACKAGES_URL, timeout=REQUESTS_TIMEOUT)
if response.ok:
packages = response.json()
stats = {
Expand Down
49 changes: 33 additions & 16 deletions adabot/circuitpython_library_release.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,32 +46,32 @@ def make_release(new_tag, logger, test_run=False):
)


def create_release_notes(pypi_name):
def create_release_notes(shorthand_name, changes_url):
"""
render the release notes into a md file.
"""
# pylint: disable=line-too-long
RELEASE_NOTES_TEMPLATE = """To use in CircuitPython, simply install the [Adafruit CircuitPython Bundle](https://circuitpython.org/libraries).
RELEASE_NOTES_TEMPLATE = """Changes: {{ changes_url }}

To use in CPython, `pip3 install {{ pypi_name }}`.
To use in CircuitPython, simply install the [Adafruit CircuitPython Bundle](https://circuitpython.org/libraries).

Read the [docs](https://circuitpython.readthedocs.io/projects/{{ pypi_name }}/en/latest/) for info on how to use it."""
To use in CPython, `pip3 install adafruit-circuitpython-{{ shorthand_name }}`.

Read the [docs](https://circuitpython.readthedocs.io/projects/{{ shorthand_name }}/en/latest/) for info on how to use it."""

release_notes_template = Template(RELEASE_NOTES_TEMPLATE)

_rendered_template_text = release_notes_template.render(pypi_name=pypi_name)
_rendered_template_text = release_notes_template.render(
shorthand_name=shorthand_name, changes_url=changes_url
)

with open("release_notes.md", "w") as f:
f.write(_rendered_template_text)


if __name__ == "__main__":
create_release_notes("testrepo")


def get_pypi_name():
def get_shorthand_name():
"""
return the shorthand pypi project name
return the shorthand project name used for pypi, docs, etc.
"""
data = toml.load("pyproject.toml")

Expand Down Expand Up @@ -149,7 +149,7 @@ def get_release_info():
}


def get_compare_url(tag_name):
def get_compare_url(tag_name, compare_to_tag_name="main"):
"""
Get the URL to the GitHub compare page for the latest release compared
to current main.
Expand All @@ -161,7 +161,9 @@ def get_compare_url(tag_name):
if not remote_url.startswith("https"):
return "Sorry, Unknown Remotes"

compare_url = remote_url.replace(".git", f"/compare/{tag_name}...main")
compare_url = remote_url.replace(
".git", f"/compare/{tag_name}...{compare_to_tag_name}"
)
return compare_url


Expand Down Expand Up @@ -210,19 +212,34 @@ def menu_prompt(release_info):
logging.info(
"Making a new release with tag: %s", release_info["new_tag_patch"]
)
create_release_notes(get_pypi_name())
create_release_notes(
get_shorthand_name(),
get_compare_url(
release_info["current_tag"], release_info["new_tag_patch"]
),
)
make_release(release_info["new_tag_patch"], logging)
elif choice == "2":
logging.info(
"Making a new release with tag: %s", release_info["new_tag_minor"]
)
create_release_notes(get_pypi_name())
create_release_notes(
get_shorthand_name(),
get_compare_url(
release_info["current_tag"], release_info["new_tag_minor"]
),
)
make_release(release_info["new_tag_minor"], logging)
elif choice == "3":
logging.info(
"Making a new release with tag: %s", release_info["new_tag_major"]
)
create_release_notes(get_pypi_name())
create_release_notes(
get_shorthand_name(),
get_compare_url(
release_info["current_tag"], release_info["new_tag_major"]
),
)
make_release(release_info["new_tag_major"], logging)
elif choice == "4":
logging.info("Skipping release.")
Expand Down
6 changes: 4 additions & 2 deletions adabot/lib/assign_hacktober_label.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import datetime
import requests

from adabot import github_requests as gh_reqs
from adabot import github_requests as gh_reqs, REQUESTS_TIMEOUT
from adabot.lib import common_funcs

cli_args = argparse.ArgumentParser(description="Hacktoberfest Label Assigner")
Expand Down Expand Up @@ -73,7 +73,9 @@ def get_open_issues(repo):
)

if response.links.get("next"):
response = requests.get(response.links["next"]["url"])
response = requests.get(
response.links["next"]["url"], timeout=REQUESTS_TIMEOUT
)
else:
break

Expand Down
28 changes: 16 additions & 12 deletions adabot/lib/circuitpython_library_validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import parse

import github as pygithub
from adabot import github_requests as gh_reqs
from adabot import github_requests as gh_reqs, REQUESTS_TIMEOUT
from adabot.lib import common_funcs
from adabot.lib import assign_hacktober_label as hacktober

Expand Down Expand Up @@ -231,7 +231,7 @@ def rtd_yml_base(self):
"%20if%20cookiecutter.sphinx_docs%20in%20%5B'y'%2C%20'yes'%5D%20%25"
"%7D.readthedocs.yaml%7B%25%20endif%20%25%7D"
)
rtd_yml = requests.get(rtd_yml_dl_url)
rtd_yml = requests.get(rtd_yml_dl_url, timeout=REQUESTS_TIMEOUT)
if rtd_yml.ok:
try:
self._rtd_yaml_base = yaml.safe_load(rtd_yml.text)
Expand All @@ -255,7 +255,7 @@ def pcc_versions(self):
"circuitpython/main/%7B%7B%20cookiecutter.__dirname%20%7D%7D/.pre-"
"commit-config.yaml"
)
pcc_yml = requests.get(pcc_yml_dl_url)
pcc_yml = requests.get(pcc_yml_dl_url, timeout=REQUESTS_TIMEOUT)
if pcc_yml.ok:
try:
pcc_yaml_base = yaml.safe_load(pcc_yml.text)
Expand Down Expand Up @@ -464,7 +464,7 @@ def _filter_file_diffs(filenames):
def _validate_readme(self, download_url):
# We use requests because file contents are hosted by
# githubusercontent.com, not the API domain.
contents = requests.get(download_url, timeout=30)
contents = requests.get(download_url, timeout=REQUESTS_TIMEOUT)
if not contents.ok:
return [ERROR_README_DOWNLOAD_FAILED]

Expand Down Expand Up @@ -510,7 +510,7 @@ def _validate_py_for_u_modules(self, download_url):
"""
# We use requests because file contents are hosted by
# githubusercontent.com, not the API domain.
contents = requests.get(download_url, timeout=30)
contents = requests.get(download_url, timeout=REQUESTS_TIMEOUT)
if not contents.ok:
return [ERROR_PYFILE_DOWNLOAD_FAILED]

Expand Down Expand Up @@ -548,7 +548,7 @@ def _validate_actions_build_yml(self, actions_build_info):
"""

download_url = actions_build_info["download_url"]
contents = requests.get(download_url, timeout=30)
contents = requests.get(download_url, timeout=REQUESTS_TIMEOUT)
if not contents.ok:
return [ERROR_PYFILE_DOWNLOAD_FAILED]

Expand All @@ -558,7 +558,7 @@ def _validate_actions_build_yml(self, actions_build_info):

def _validate_pre_commit_config_yaml(self, file_info):
download_url = file_info["download_url"]
contents = requests.get(download_url, timeout=30)
contents = requests.get(download_url, timeout=REQUESTS_TIMEOUT)
if not contents.ok:
return [ERROR_PYFILE_DOWNLOAD_FAILED]

Expand Down Expand Up @@ -595,15 +595,15 @@ def _validate_pre_commit_config_yaml(self, file_info):
def _validate_pyproject_toml(self, file_info):
"""Check pyproject.toml for pypi compatibility"""
download_url = file_info["download_url"]
contents = requests.get(download_url, timeout=30)
contents = requests.get(download_url, timeout=REQUESTS_TIMEOUT)
if not contents.ok:
return [ERROR_TOMLFILE_DOWNLOAD_FAILED]
return []

def _validate_requirements_txt(self, repo, file_info, check_blinka=True):
"""Check requirements.txt for pypi compatibility"""
download_url = file_info["download_url"]
contents = requests.get(download_url, timeout=30)
contents = requests.get(download_url, timeout=REQUESTS_TIMEOUT)
if not contents.ok:
return [ERROR_PYFILE_DOWNLOAD_FAILED]

Expand Down Expand Up @@ -718,7 +718,9 @@ def validate_contents(self, repo):
if ".readthedocs.yaml" in files:
filename = ".readthedocs.yaml"
file_info = content_list[files.index(filename)]
rtd_contents = requests.get(file_info["download_url"])
rtd_contents = requests.get(
file_info["download_url"], timeout=REQUESTS_TIMEOUT
)
if rtd_contents.ok:
try:
rtd_yml = yaml.safe_load(rtd_contents.text)
Expand All @@ -736,7 +738,9 @@ def validate_contents(self, repo):
if len(self._pcc_versions) or self.pcc_versions != "":
filename = ".pre-commit-config.yaml"
file_info = content_list[files.index(filename)]
pcc_contents = requests.get(file_info["download_url"])
pcc_contents = requests.get(
file_info["download_url"], timeout=REQUESTS_TIMEOUT
)
if pcc_contents.ok:
try:
pcc_yml = yaml.safe_load(pcc_contents.text)
Expand Down Expand Up @@ -938,7 +942,7 @@ def validate_readthedocs(self, repo):
url = f"https://readthedocs.org/api/v3/projects/{rtd_slug}/builds/"
rtd_token = os.environ["RTD_TOKEN"]
headers = {"Authorization": f"token {rtd_token}"}
response = requests.get(url, headers=headers)
response = requests.get(url, headers=headers, timeout=REQUESTS_TIMEOUT)
json_response = response.json()

error_message = json_response.get("detail")
Expand Down
4 changes: 3 additions & 1 deletion adabot/pypi_requests.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@

import requests

from adabot import REQUESTS_TIMEOUT


def _fix_url(url):
if url.startswith("/"):
Expand All @@ -18,4 +20,4 @@ def _fix_url(url):

def get(url, **kwargs):
"""Process a GET request from pypi.org"""
return requests.get(_fix_url(url), timeout=30, **kwargs)
return requests.get(_fix_url(url), timeout=REQUESTS_TIMEOUT, **kwargs)
4 changes: 3 additions & 1 deletion tools/docs_status.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,12 @@
import requests
from github.Repository import Repository
from github.ContentFile import ContentFile

from iterate_libraries import (
iter_remote_bundle_with_func,
RemoteLibFunc_IterResult,
)
from adabot import REQUESTS_TIMEOUT


def check_docs_status(
Expand Down Expand Up @@ -64,7 +66,7 @@ def check_docs_status(
# GET the latest documentation build runs
url = f"https://readthedocs.org/api/v3/projects/{rtd_slug}/builds/"
headers = {"Authorization": f"token {rtd_token}"}
response = requests.get(url, headers=headers)
response = requests.get(url, headers=headers, timeout=REQUESTS_TIMEOUT)
json_response: dict[str, Any] = response.json()

# Return the results of the latest run
Expand Down
5 changes: 3 additions & 2 deletions tools/file_compare.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import requests
from requests.structures import CaseInsensitiveDict

from adabot import REQUESTS_TIMEOUT
from adabot.lib.common_funcs import list_repos


Expand Down Expand Up @@ -54,9 +55,9 @@ def compare(git_file: str, token: Optional[str] = None) -> list:
headers = CaseInsensitiveDict()
headers["Authorization"] = f"token {token}"

resp = requests.get(url, headers=headers)
resp = requests.get(url, headers=headers, timeout=REQUESTS_TIMEOUT)
else:
resp = requests.get(url)
resp = requests.get(url, timeout=REQUESTS_TIMEOUT)

if resp.status_code != 200:
print(name)
Expand Down
5 changes: 4 additions & 1 deletion tools/find_text.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

import requests

from adabot import REQUESTS_TIMEOUT
from adabot.lib.common_funcs import list_repos

argumentList = sys.argv[1:]
Expand Down Expand Up @@ -129,7 +130,9 @@ def prettyprint(info, results):

for repo in all_repos:
INFO = "getting {} for: {}".format(FILE, repo["name"])
response = requests.get(URL_TEMPLATE.format(repo["name"], FILE))
response = requests.get(
URL_TEMPLATE.format(repo["name"], FILE), timeout=REQUESTS_TIMEOUT
)
result = []
if response.status_code == 404:
RESULTS["file_not_found"].append(repo["html_url"])
Expand Down