From f8706256b97137d73bbd80d923e24404c8b0527a Mon Sep 17 00:00:00 2001 From: Zack Koppert Date: Wed, 2 Aug 2023 13:01:06 -0700 Subject: [PATCH] general cleanup and linting fixes Signed-off-by: Zack Koppert --- Makefile | 2 +- issue_metrics.py | 15 +++++++++++---- labels.py | 2 +- time_to_first_response.py | 4 +++- 4 files changed, 16 insertions(+), 7 deletions(-) diff --git a/Makefile b/Makefile index 3158f29..c1a51df 100644 --- a/Makefile +++ b/Makefile @@ -11,5 +11,5 @@ lint: # stop the build if there are Python syntax errors or undefined names flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics # exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide - flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics + flake8 . --count --exit-zero --max-complexity=15 --max-line-length=127 --statistics pylint --rcfile=.pylintrc --fail-under=9.0 *.py \ No newline at end of file diff --git a/issue_metrics.py b/issue_metrics.py index 370b777..0b4145e 100644 --- a/issue_metrics.py +++ b/issue_metrics.py @@ -13,7 +13,8 @@ Searches for issues in a GitHub repository that match the given search query. auth_to_github() -> github3.GitHub: Connect to GitHub API with token authentication. get_per_issue_metrics(issues: Union[List[dict], List[github3.issues.Issue]], - discussions: bool = False), labels: Union[List[str], None] = None, ignore_users: List[str] = [] -> tuple[List, int, int]: + discussions: bool = False), labels: Union[List[str], None] = None, + ignore_users: List[str] = [] -> tuple[List, int, int]: Calculate the metrics for each issue in a list of GitHub issues. get_owner(search_query: str) -> Union[str, None]]: Get the owner from the search query. @@ -123,10 +124,12 @@ def auth_to_github() -> github3.GitHub: if token := os.getenv("GH_TOKEN"): if not os.getenv("GITHUB_SERVER_URL"): github_connection = github3.login(token=token) - elif os.getenv("GITHUB_SERVER_URL") == 'https://github.com': + elif os.getenv("GITHUB_SERVER_URL") == "https://github.com": github_connection = github3.login(token=token) else: - github_connection = github3.GitHubEnterprise(os.getenv("GITHUB_SERVER_URL"),token=token) + github_connection = github3.GitHubEnterprise( + os.getenv("GITHUB_SERVER_URL"), token=token + ) else: raise ValueError("GH_TOKEN environment variable not set") @@ -137,7 +140,7 @@ def get_per_issue_metrics( issues: Union[List[dict], List[github3.search.IssueSearchResult]], # type: ignore discussions: bool = False, labels: Union[List[str], None] = None, - ignore_users: List[str] = [], + ignore_users: List[str] = None, ) -> tuple[List, int, int]: """ Calculate the metrics for each issue/pr/discussion in a list provided. @@ -159,6 +162,8 @@ def get_per_issue_metrics( issues_with_metrics = [] num_issues_open = 0 num_issues_closed = 0 + if ignore_users is None: + ignore_users = [] for issue in issues: if discussions: @@ -320,6 +325,7 @@ def main(): average_time_in_labels, num_issues_open, num_issues_closed, + search_query, ) write_to_markdown( issues_with_metrics, @@ -330,6 +336,7 @@ def main(): num_issues_open, num_issues_closed, labels, + search_query, ) diff --git a/labels.py b/labels.py index ad6fa7c..6af1d5b 100644 --- a/labels.py +++ b/labels.py @@ -29,7 +29,7 @@ def get_label_events( return label_events -def get_label_metrics(issue: github3.issues.Issue, labels: List[str]) -> dict: # type: ignore +def get_label_metrics(issue: github3.issues.Issue, labels: List[str]) -> dict: """ Calculate the time spent with the given labels on a given issue. diff --git a/time_to_first_response.py b/time_to_first_response.py index a5295ca..204b209 100644 --- a/time_to_first_response.py +++ b/time_to_first_response.py @@ -27,7 +27,7 @@ def measure_time_to_first_response( issue: Union[github3.issues.Issue, None], # type: ignore discussion: Union[dict, None], - ignore_users: List[str] = [], + ignore_users: List[str] = None, ) -> Union[timedelta, None]: """Measure the time to first response for a single issue or a discussion. @@ -44,6 +44,8 @@ def measure_time_to_first_response( first_comment_time = None earliest_response = None issue_time = None + if ignore_users is None: + ignore_users = [] # Get the first comment time if issue: