py3: Switch almost all shebang lines to use `python3`.
This causes `upgrade-zulip-from-git`, as well as a no-option run of
`tools/build-release-tarball`, to produce a Zulip install running
Python 3, rather than Python 2. In particular this means that the
virtualenv we create, in which all application code runs, is Python 3.
One shebang line, on `zulip-ec2-configure-interfaces`, explicitly
keeps Python 2, and at least one external ops script, `wal-e`, also
still runs on Python 2. See discussion on the respective previous
commits that made those explicit. There may also be some other
third-party scripts we use, outside of this source tree and running
outside our virtualenv, that still run on Python 2.
2017-08-02 23:15:16 +02:00
|
|
|
#!/usr/bin/env python3
|
2017-01-30 10:24:18 +01:00
|
|
|
import argparse
|
2020-06-25 03:19:10 +02:00
|
|
|
import configparser
|
2017-01-30 10:24:18 +01:00
|
|
|
import os
|
2020-06-11 00:54:34 +02:00
|
|
|
import re
|
|
|
|
import sys
|
2024-07-12 02:30:23 +02:00
|
|
|
from typing import Any
|
2020-06-11 00:54:34 +02:00
|
|
|
|
|
|
|
import requests
|
2017-01-30 10:24:18 +01:00
|
|
|
|
2022-02-08 00:13:33 +01:00
|
|
|
# Scans zulip repository for issues that don't have any `area` labels.
|
2017-01-30 10:24:18 +01:00
|
|
|
# GitHub API token is required as GitHub limits unauthenticated
|
|
|
|
# requests to 60/hour. There is a good chance that this limit is
|
|
|
|
# bypassed in consecutive attempts.
|
2020-10-23 02:43:28 +02:00
|
|
|
# The API token can be generated here
|
2017-01-30 10:24:18 +01:00
|
|
|
# https://github.com/settings/tokens/new?description=Zulip%20Issue%20Label%20Checker
|
|
|
|
#
|
2020-10-23 02:43:28 +02:00
|
|
|
# Copy conf.ini-template to conf.ini and populate with your API token.
|
2017-01-30 10:24:18 +01:00
|
|
|
#
|
|
|
|
# usage: python check-issue-labels
|
|
|
|
# Pass --force as an argument to run without a token.
|
|
|
|
|
2021-02-12 08:19:30 +01:00
|
|
|
|
2020-06-25 03:19:10 +02:00
|
|
|
def get_config() -> configparser.ConfigParser:
|
|
|
|
config = configparser.ConfigParser()
|
2021-02-12 08:20:45 +01:00
|
|
|
config.read(os.path.join(os.path.dirname(os.path.abspath(__file__)), "conf.ini"))
|
2017-01-30 10:24:18 +01:00
|
|
|
return config
|
|
|
|
|
2021-02-12 08:19:30 +01:00
|
|
|
|
2024-07-12 02:30:17 +02:00
|
|
|
def area_labeled(issue: dict[str, Any]) -> bool:
|
2017-01-30 10:24:18 +01:00
|
|
|
for label in issue["labels"]:
|
|
|
|
label_name = str(label["name"])
|
|
|
|
if "area:" in label_name:
|
|
|
|
return True
|
|
|
|
return False
|
|
|
|
|
2021-02-12 08:19:30 +01:00
|
|
|
|
2024-07-12 02:30:17 +02:00
|
|
|
def is_issue(item: dict[str, Any]) -> bool:
|
2017-01-30 10:24:18 +01:00
|
|
|
return "issues" in item["html_url"]
|
|
|
|
|
2021-02-12 08:19:30 +01:00
|
|
|
|
2024-07-12 02:30:23 +02:00
|
|
|
def get_next_page_url(link_header: str) -> str | None:
|
2021-02-12 08:20:45 +01:00
|
|
|
matches = re.findall(r"\<(\S+)\>; rel=\"next\"", link_header)
|
2017-01-30 10:24:18 +01:00
|
|
|
try:
|
|
|
|
return matches[0]
|
|
|
|
except IndexError:
|
|
|
|
return None
|
|
|
|
|
2021-02-12 08:19:30 +01:00
|
|
|
|
python: Convert function type annotations to Python 3 style.
Generated by com2ann (slightly patched to avoid also converting
assignment type annotations, which require Python 3.6), followed by
some manual whitespace adjustment, and six fixes for runtime issues:
- def __init__(self, token: Token, parent: Optional[Node]) -> None:
+ def __init__(self, token: Token, parent: "Optional[Node]") -> None:
-def main(options: argparse.Namespace) -> NoReturn:
+def main(options: argparse.Namespace) -> "NoReturn":
-def fetch_request(url: str, callback: Any, **kwargs: Any) -> Generator[Callable[..., Any], Any, None]:
+def fetch_request(url: str, callback: Any, **kwargs: Any) -> "Generator[Callable[..., Any], Any, None]":
-def assert_server_running(server: subprocess.Popen[bytes], log_file: Optional[str]) -> None:
+def assert_server_running(server: "subprocess.Popen[bytes]", log_file: Optional[str]) -> None:
-def server_is_up(server: subprocess.Popen[bytes], log_file: Optional[str]) -> bool:
+def server_is_up(server: "subprocess.Popen[bytes]", log_file: Optional[str]) -> bool:
- method_kwarg_pairs: List[FuncKwargPair],
+ method_kwarg_pairs: "List[FuncKwargPair]",
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2020-04-19 03:48:37 +02:00
|
|
|
def check_issue_labels() -> None:
|
2017-01-30 10:24:18 +01:00
|
|
|
parser = argparse.ArgumentParser()
|
2021-02-12 08:20:45 +01:00
|
|
|
parser.add_argument("--force", action="store_true")
|
2017-01-30 10:24:18 +01:00
|
|
|
args = parser.parse_args()
|
|
|
|
|
|
|
|
if not args.force:
|
|
|
|
config = get_config()
|
|
|
|
try:
|
2021-02-12 08:20:45 +01:00
|
|
|
token = config.get("github", "api_token")
|
2020-06-25 03:19:10 +02:00
|
|
|
except configparser.Error:
|
2021-02-12 08:19:30 +01:00
|
|
|
print(
|
|
|
|
"Error fetching GitHub API token. Copy conf.ini-template to conf.ini and populate with "
|
|
|
|
"your API token. If you want to continue without using a token use --force."
|
|
|
|
)
|
2017-01-30 10:24:18 +01:00
|
|
|
sys.exit(1)
|
|
|
|
|
2024-07-12 02:30:23 +02:00
|
|
|
next_page_url: str | None = "https://api.github.com/repos/zulip/zulip/issues"
|
2024-07-12 02:30:17 +02:00
|
|
|
unlabeled_issue_urls: list[str] = []
|
2017-01-30 10:24:18 +01:00
|
|
|
while next_page_url:
|
|
|
|
try:
|
|
|
|
if args.force:
|
|
|
|
response = requests.get(next_page_url)
|
|
|
|
else:
|
2021-02-12 08:20:45 +01:00
|
|
|
response = requests.get(next_page_url, headers={"Authorization": f"token {token}"})
|
2017-01-30 10:24:18 +01:00
|
|
|
if response.status_code == 401:
|
|
|
|
sys.exit("Error. Please check the token.")
|
|
|
|
if response.status_code == 403:
|
2021-02-12 08:19:30 +01:00
|
|
|
sys.exit(
|
|
|
|
"403 Error. This is generally caused when API limit is exceeded. You use an API "
|
|
|
|
"token to overcome this limit."
|
|
|
|
)
|
2017-01-30 10:24:18 +01:00
|
|
|
except requests.exceptions.RequestException as e:
|
|
|
|
print(e)
|
|
|
|
sys.exit(1)
|
|
|
|
|
|
|
|
next_page_url = get_next_page_url(response.headers["Link"])
|
2023-07-31 22:52:35 +02:00
|
|
|
unlabeled_issue_urls.extend(
|
|
|
|
item["html_url"]
|
|
|
|
for item in response.json()
|
|
|
|
if is_issue(item) and not area_labeled(item)
|
|
|
|
)
|
2017-01-30 10:24:18 +01:00
|
|
|
|
|
|
|
if len(unlabeled_issue_urls):
|
|
|
|
print("The following issues don't have any area labels associated with it")
|
|
|
|
print("\n".join(unlabeled_issue_urls))
|
|
|
|
else:
|
|
|
|
print("No GitHub issues found with missing area labels.")
|
|
|
|
|
2021-02-12 08:19:30 +01:00
|
|
|
|
2021-02-12 08:20:45 +01:00
|
|
|
if __name__ == "__main__":
|
2017-01-30 10:24:18 +01:00
|
|
|
check_issue_labels()
|