From 610ddb5f3d53c3c91a614a3e4abcd2ce54790a5a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20=C5=A0pl=C3=ADchal?= Date: Fri, 4 Oct 2024 12:47:48 +0200 Subject: [PATCH] Support filtering multiple names as well --- did/plugins/github.py | 24 +++++++++++++++--------- tests/github/config-more.ini | 10 ++++++++++ tests/github/issues.sh | 11 ++++++++++- tests/github/pulls.sh | 11 +++++++++++ 4 files changed, 46 insertions(+), 10 deletions(-) create mode 100644 tests/github/config-more.ini diff --git a/did/plugins/github.py b/did/plugins/github.py index f5e35ce6..565e33bb 100644 --- a/did/plugins/github.py +++ b/did/plugins/github.py @@ -18,6 +18,11 @@ org = repo = +Multiple users, organization or repositories can be searched as +well. Use ``,`` as the separator, for example:: + + org = one,two,three + The authentication token is optional. However, unauthenticated queries are limited. For more details see `GitHub API`__ docs. Use ``login`` to override the default email address for searching. @@ -63,15 +68,16 @@ def __init__(self, url, token=None, user=None, org=None, repo=None): self.headers = {} # Prepare the org, user, repo filter - self.filter = "" - if user: - self.filter += f"+user:{user}" - if org: - self.filter += f"+org:{org}" - if repo: - self.filter += f"+repo:{repo}" - - self.token = token + def condition(key: str, names: str) -> list[str]: + """ Prepare one or more conditions for given key & names """ + if not names: + return [] + return [f"+{key}:{name}" for name in re.split(r"\s*,\s*", names)] + + self.filter = "".join( + condition("user", user) + + condition("org", org) + + condition("repo", repo)) def search(self, query): """ Perform GitHub query """ diff --git a/tests/github/config-more.ini b/tests/github/config-more.ini new file mode 100644 index 00000000..e1a8badb --- /dev/null +++ b/tests/github/config-more.ini @@ -0,0 +1,10 @@ +[general] +email = "Petr Šplíchal" + +[gh] +type = github +url = https://api.github.com/ +login = psss + +# Limit to multiple organizations +org = teemtee,packit diff --git a/tests/github/issues.sh b/tests/github/issues.sh index d336a46c..7653d54b 100755 --- a/tests/github/issues.sh +++ b/tests/github/issues.sh @@ -1,8 +1,9 @@ #!/bin/bash . /usr/share/beakerlib/beakerlib.sh || exit 1 -YEAR_2022="--since 2022-01-01 --until 2022-12-31" YEAR_2021="--since 2021-01-01 --until 2021-12-31" +YEAR_2022="--since 2022-01-01 --until 2022-12-31" +YEAR_2023="--since 2023-01-01 --until 2023-12-31" rlJournalStart @@ -24,6 +25,14 @@ rlJournalStart rlAssertNotGrep "packit/packit-service#1645 - Manually trigger internal jobs" $rlRun_LOG rlPhaseEnd + rlPhaseStartTest "Issues Created (org:teemtee,packit)" + rlRun -s "did --config ./config-more.ini --gh-issues-created $YEAR_2023" + rlAssertGrep "Issues created on gh: 33$" $rlRun_LOG + rlAssertGrep "teemtee/tmt#2493 - Implement retry functionality" $rlRun_LOG + rlAssertGrep "packit/packit#1989 - Mention branch name" $rlRun_LOG + rlAssertNotGrep "readthedocs/sphinx_rtd_theme#1525 - Left menu" $rlRun_LOG + rlPhaseEnd + rlPhaseStartTest "Issues Created (repo:teemtee/fmf)" rlRun -s "did --config ./config-repo.ini --gh-issues-created $YEAR_2022" rlAssertGrep "Issues created on gh: 2$" $rlRun_LOG diff --git a/tests/github/pulls.sh b/tests/github/pulls.sh index abb95734..2d984730 100755 --- a/tests/github/pulls.sh +++ b/tests/github/pulls.sh @@ -30,6 +30,17 @@ rlJournalStart rlAssertNotGrep "packit/packit.dev#399 - Update \`tmt\` examples" $rlRun_LOG rlPhaseEnd + rlPhaseStartTest "Pull Requests Created (org:teemtee,packit)" + rlRun -s "did --config ./config-more.ini --gh-pull-requests-created $YEAR_2022" + rlAssertGrep "Pull requests created on gh: 86$" $rlRun_LOG + rlAssertGrep "teemtee/tmt#1750 - Include the new web link in verbose" $rlRun_LOG + rlAssertGrep "teemtee/fmf#170 - Implement a directive for disabling inheritance" $rlRun_LOG + rlAssertGrep "teemtee/try#002 - Check logs for test with a hash sign in" $rlRun_LOG + rlAssertNotGrep "psss/did#275 - Speed up local testing" $rlRun_LOG + rlAssertNotGrep "psss/python-nitrate#039 - Enable basic sanity" $rlRun_LOG + rlAssertGrep "packit/packit.dev#399 - Update \`tmt\` examples" $rlRun_LOG + rlPhaseEnd + rlPhaseStartTest "Pull Requests Created (repo:teemtee/fmf)" rlRun -s "did --config ./config-repo.ini --gh-pull-requests-created $YEAR_2022" rlAssertGrep "Pull requests created on gh: 7$" $rlRun_LOG