Skip to content

Commit

Permalink
general cleanup and linting fixes
Browse files Browse the repository at this point in the history
Signed-off-by: Zack Koppert <[email protected]>
  • Loading branch information
zkoppert committed Aug 2, 2023
1 parent 5b59baf commit f870625
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 7 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
15 changes: 11 additions & 4 deletions issue_metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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")

Expand All @@ -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.
Expand All @@ -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:
Expand Down Expand Up @@ -320,6 +325,7 @@ def main():
average_time_in_labels,
num_issues_open,
num_issues_closed,
search_query,
)
write_to_markdown(
issues_with_metrics,
Expand All @@ -330,6 +336,7 @@ def main():
num_issues_open,
num_issues_closed,
labels,
search_query,
)


Expand Down
2 changes: 1 addition & 1 deletion labels.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 3 additions & 1 deletion time_to_first_response.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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:
Expand Down

0 comments on commit f870625

Please sign in to comment.