github / issue-metrics

Gather metrics on issues/prs/discussions such as time to first response, count of issues opened, closed, etc.

Home Page:https://github.blog/2023-07-19-metrics-for-issues-pull-requests-and-discussions/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

With org: or owner: in SEARCH_QUERY the action fails

albertosantini opened this issue · comments

Describe the bug

If in SEARCH_QUERY I use

repo:my_org/my_project ...

the action works correctly.

If I use

org:my_org ... or owner:my_owner ...

it fails as the repositories are not listed.
See screenshot of action log.

To Reproduce

Using org: or owner: and not repo: keys in the SEARCH_QUERY.

Expected behavior

The action is executed

Screenshots

image

Additional context

No response

The token seems ok to me.

image

@albertosantini Thank you for filing this issue. We will take a look at this as soon as possible. Please let us know if you'd like to try out a PR for this. We don't want to block an opportunity for others to contribute fixes. 🙇

I am not so proficient in Python.

The name of this test is misleading because there is not the repo in the query and, indeed, the repo is empty.

    def test_get_owner_and_repositories_with_repo_in_query(self):
        """Test get just owner."""
        result = get_owners_and_repositories("org:owner1")
        self.assertEqual(result[0].get("owner"), "owner1")
        self.assertIsNone(result[0].get("repository"))

Anyway the offending code is the following one:

    for item in owners_and_repositories:
        repos_and_owners_string += f"{item['owner']}/{item['repository']} "

And the test above needs to be improved to catch the case of the offending lines above.

Furthermore owners_and_repositories and the corresponding repos_and_owners_string are used only to display an error message when a github3 exception is raised, for instance:

f"The repository could not be found; Check the repository owner and names: '{repos_and_owners_string}"

I would change the logic in

def get_owners_and_repositories(
    search_query: str,
) -> List[dict]:

and not to return a List, but directly a string of owners and repositories.

Maybe the image of the log is cropped, but the error is KeyError: 'repository'.

So another approach is testing if there is any owner AND repository key in the dictionary, before concatenating the string from the List.

    for item in owners_and_repositories:
        repos_and_owners_string += f"{item['owner']}/{item['repository']} "

What about using a default value if the key doesn't exist (quick fix)?

repos_and_owners_string += f"{item['owner']}/{item.get('repository', '')} "

Thanks @jmeridth.

Tested. Ok.