Skip to content

Commit

Permalink
Merge pull request #73 from martincostello/support-owner
Browse files Browse the repository at this point in the history
Support "owner" and "user" in search queries
  • Loading branch information
zkoppert authored Jul 25, 2023
2 parents 4298576 + b22d846 commit cf3dda2
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 37 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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. |
Expand Down
51 changes: 15 additions & 36 deletions issue_metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +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_organization(search_query: str) -> Union[str, None]: Get the organization
from the search query.
get_owner(search_query: str) -> Union[str, None]]:
Get the owner from the search query.
main(): Run the issue-metrics script.
"""

Expand Down Expand Up @@ -191,46 +189,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 "org:" in item or "owner:" in item or "user:" in item:
owner = item.split(":")[1]

return repo_owner, repo_name


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
return owner


def main():
Expand Down Expand Up @@ -261,13 +240,13 @@ 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)
organization = get_organization(search_query)
owner = get_owner(search_query)

if (owner is None or repo_name 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) or an organization (ie. org:organization)"
(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
Expand Down

0 comments on commit cf3dda2

Please sign in to comment.