Skip to content

Commit

Permalink
Support filtering multiple names as well
Browse files Browse the repository at this point in the history
  • Loading branch information
psss committed Oct 4, 2024
1 parent 417d29a commit 610ddb5
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 10 deletions.
24 changes: 15 additions & 9 deletions did/plugins/github.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@
org = <organization-name>
repo = <full-project-name>
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.
Expand Down Expand Up @@ -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 """
Expand Down
10 changes: 10 additions & 0 deletions tests/github/config-more.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[general]
email = "Petr Šplíchal" <[email protected]>

[gh]
type = github
url = https://api.github.com/
login = psss

# Limit to multiple organizations
org = teemtee,packit
11 changes: 10 additions & 1 deletion tests/github/issues.sh
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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
Expand Down
11 changes: 11 additions & 0 deletions tests/github/pulls.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 610ddb5

Please sign in to comment.