From c6b031143bc16f9dae33470c3951e36565778bfb Mon Sep 17 00:00:00 2001 From: martincostello Date: Mon, 24 Jul 2023 16:42:04 +0100 Subject: [PATCH 1/4] Support just owner Add support for just `owner:` rather than needing `repo:`. --- issue_metrics.py | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/issue_metrics.py b/issue_metrics.py index 288eb47..08b5723 100644 --- a/issue_metrics.py +++ b/issue_metrics.py @@ -15,8 +15,8 @@ get_per_issue_metrics(issues: Union[List[dict], List[github3.issues.Issue]], discussions: bool = False) -> tuple[List, int, int]: Calculate the metrics for each issue in a list of GitHub issues. - get_repo_owner_and_name(search_query: str) -> tuple[Union[str, None], Union[str, None]]: - Get the repository owner and name from the search query. + get_owner(search_query: str) -> Union[str, None]]: + Get the owner from the search query. get_organization(search_query: str) -> Union[str, None]: Get the organization from the search query. main(): Run the issue-metrics script. @@ -191,26 +191,27 @@ def get_per_issue_metrics( return issues_with_metrics, num_issues_open, num_issues_closed -def get_repo_owner_and_name( +def get_owner( search_query: str, -) -> tuple[Union[str, None], Union[str, None]]: - """Get the repository owner and name from the search query. +) -> Union[str, None]: + """Get the owner from the search query. Args: search_query (str): The search query used to search for issues. Returns: - tuple[Union[str, None], Union[str, None]]: A tuple containing the repository owner and name. + Union[str, None]: The owner. """ search_query_split = search_query.split(" ") - repo_owner, repo_name = None, None + owner = None for item in search_query_split: if "repo:" in item and "/" in item: - repo_owner = item.split(":")[1].split("/")[0] - repo_name = item.split(":")[1].split("/")[1] + owner = item.split(":")[1].split("/")[0] + if "owner:" in item: + owner = item.split(":")[1] - return repo_owner, repo_name + return owner def get_organization(search_query: str) -> Union[str, None]: @@ -261,13 +262,14 @@ def main(): token = env_vars[1] # Get the repository owner and name from the search query - owner, repo_name = get_repo_owner_and_name(search_query) + owner = get_owner(search_query) organization = get_organization(search_query) - if (owner is None or repo_name is None) and organization is None: + if owner is None and organization is None: raise ValueError( "The search query must include a repository owner and name \ - (ie. repo:owner/repo) or an organization (ie. org:organization)" + (ie. repo:owner/repo), an organization (ie. org:organization) \ + or an owner (ie. owner:owner)" ) # Determine if there are label to measure From bacca7694b04ad12556563465ca66e4e760d8353 Mon Sep 17 00:00:00 2001 From: martincostello Date: Tue, 25 Jul 2023 11:43:06 +0100 Subject: [PATCH 2/4] Support user - Add support for just `user:`. - Remove the special case for `org:` and capture all four use cases in the same function. --- issue_metrics.py | 29 ++++------------------------- 1 file changed, 4 insertions(+), 25 deletions(-) diff --git a/issue_metrics.py b/issue_metrics.py index 08b5723..cf05648 100644 --- a/issue_metrics.py +++ b/issue_metrics.py @@ -208,32 +208,12 @@ def get_owner( for item in search_query_split: if "repo:" in item and "/" in item: owner = item.split(":")[1].split("/")[0] - if "owner:" in item: + if "org:" in item or "owner:" in item or "user:" in item: owner = item.split(":")[1] return owner -def get_organization(search_query: str) -> Union[str, None]: - """Get the organization from the search query. - - Args: - search_query (str): The search query used to search for issues. - - Returns: - Union[str, None]: The organization from the search query. - - """ - # Get the organization from the search query - search_query_split = search_query.split(" ") - organization = None - for item in search_query_split: - if "org:" in item: - organization = item.split(":")[1] - - return organization - - def main(): """Run the issue-metrics script. @@ -263,13 +243,12 @@ def main(): # Get the repository owner and name from the search query owner = get_owner(search_query) - organization = get_organization(search_query) - if owner is None and organization is None: + if owner is None: raise ValueError( "The search query must include a repository owner and name \ - (ie. repo:owner/repo), an organization (ie. org:organization) \ - or an owner (ie. owner:owner)" + (ie. repo:owner/repo), an organization (ie. org:organization), \ + a user (ie. user:login) or an owner (ie. owner:user-or-organization)" ) # Determine if there are label to measure From 2ea25d4918f689ccd3e8dc3dd6cc3ad9f331574c Mon Sep 17 00:00:00 2001 From: martincostello Date: Tue, 25 Jul 2023 11:44:38 +0100 Subject: [PATCH 3/4] Update docs Remove leftover function documentation. --- issue_metrics.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/issue_metrics.py b/issue_metrics.py index cf05648..03e8686 100644 --- a/issue_metrics.py +++ b/issue_metrics.py @@ -17,8 +17,6 @@ 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. - get_organization(search_query: str) -> Union[str, None]: Get the organization - from the search query. main(): Run the issue-metrics script. """ From b22d846115c18ea6f7e33f567b27e809af7eb817 Mon Sep 17 00:00:00 2001 From: Zack Koppert Date: Tue, 25 Jul 2023 08:48:59 -0700 Subject: [PATCH 4/4] docs: note requirements on search query in readme --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index fa18165..295f3c0 100644 --- a/README.md +++ b/README.md @@ -46,7 +46,7 @@ Below are the allowed configuration options: | field | required | default | description | |-----------------------|----------|---------|-------------| | `GH_TOKEN` | True | | The GitHub Token used to scan the repository. Must have read access to all repository you are interested in scanning. | -| `SEARCH_QUERY` | True | | The query by which you can filter issues/prs which must contain a `repo:` entry or an `org:` entry. For discussions, include `type:discussions` in the query. | +| `SEARCH_QUERY` | True | | The query by which you can filter issues/prs which must contain a `repo:`, `org:`, `owner:`, or a `user:` entry. For discussions, include `type:discussions` in the query. | | `LABELS_TO_MEASURE` | False | | A comma separated list of labels to measure how much time the label is applied. If not provided, no labels durations will be measured. Not compatible with discussions at this time. | | `HIDE_TIME_TO_FIRST_RESPONSE` | False | | If set to any value, the time to first response will not be displayed in the generated markdown file. | | `HIDE_TIME_TO_CLOSE` | False | | If set to any value, the time to close will not be displayed in the generated markdown file. |