Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix issue with wrong until in GitHub search #376

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 34 additions & 8 deletions did/plugins/github.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
# Identifier padding
PADDING = 3

# Number of issues to be fetched per page
# Number of GH items to be fetched per page
PER_PAGE = 100


Expand Down Expand Up @@ -78,6 +78,11 @@ def condition(key: str, names: str) -> list[str]:
condition("org", org) +
condition("repo", repo))

@staticmethod
def until(until):
"""Issue #362: until for GH should have - delta(day=1)"""
return until - 1

def search(self, query):
""" Perform GitHub query """
result = []
Expand Down Expand Up @@ -182,8 +187,11 @@ class IssuesCreated(Stats):

def fetch(self):
log.info("Searching for issues created by {0}".format(self.user))
user = self.user.login
since = self.options.since
until = GitHub.until(self.options.until)
query = "search/issues?q=author:{0}+created:{1}..{2}".format(
self.user.login, self.options.since, self.options.until)
user, since, until)
query += "+type:issue"
self.stats = [
Issue(issue, self.parent) for issue in self.parent.github.search(query)]
Expand All @@ -194,8 +202,11 @@ class IssuesClosed(Stats):

def fetch(self):
log.info("Searching for issues closed by {0}".format(self.user))
user = self.user.login
since = self.options.since
until = GitHub.until(self.options.until)
query = "search/issues?q=assignee:{0}+closed:{1}..{2}".format(
self.user.login, self.options.since, self.options.until)
user, since, until)
query += "+type:issue"
self.stats = [
Issue(issue, self.parent) for issue in self.parent.github.search(query)]
Expand All @@ -206,8 +217,11 @@ class IssueCommented(Stats):

def fetch(self):
log.info("Searching for issues commented on by {0}".format(self.user))
user = self.user.login
since = self.options.since
until = GitHub.until(self.options.until)
query = "search/issues?q=commenter:{0}+updated:{1}..{2}".format(
self.user.login, self.options.since, self.options.until)
user, since, until)
query += "+type:issue"
self.stats = [
Issue(issue, self.parent) for issue in self.parent.github.search(query)]
Expand All @@ -219,8 +233,11 @@ class PullRequestsCreated(Stats):
def fetch(self):
log.info("Searching for pull requests created by {0}".format(
self.user))
user = self.user.login
since = self.options.since
until = GitHub.until(self.options.until)
query = "search/issues?q=author:{0}+created:{1}..{2}".format(
self.user.login, self.options.since, self.options.until)
user, since, until)
query += "+type:pr"
self.stats = [
Issue(issue, self.parent) for issue in self.parent.github.search(query)]
Expand All @@ -232,8 +249,11 @@ class PullRequestsCommented(Stats):
def fetch(self):
log.info("Searching for pull requests commented on by {0}".format(
self.user))
user = self.user.login
since = self.options.since
until = GitHub.until(self.options.until)
query = "search/issues?q=commenter:{0}+updated:{1}..{2}".format(
self.user.login, self.options.since, self.options.until)
user, since, until)
query += "+type:pr"
self.stats = [
Issue(issue, self.parent) for issue in self.parent.github.search(query)]
Expand All @@ -245,8 +265,11 @@ class PullRequestsClosed(Stats):
def fetch(self):
log.info("Searching for pull requests closed by {0}".format(
self.user))
user = self.user.login
since = self.options.since
until = GitHub.until(self.options.until)
query = "search/issues?q=assignee:{0}+closed:{1}..{2}".format(
self.user.login, self.options.since, self.options.until)
user, since, until)
query += "+type:pr"
self.stats = [
Issue(issue, self.parent) for issue in self.parent.github.search(query)]
Expand All @@ -258,8 +281,11 @@ class PullRequestsReviewed(Stats):
def fetch(self):
log.info("Searching for pull requests reviewed by {0}".format(
self.user))
user = self.user.login
since = self.options.since
until = GitHub.until(self.options.until)
query = "search/issues?q=reviewed-by:{0}+-author:{0}+closed:{1}..{2}".format(
self.user.login, self.options.since, self.options.until)
user, since, until)
query += "+type:pr"
self.stats = [
Issue(issue, self.parent) for issue in self.parent.github.search(query)]
Expand Down
29 changes: 20 additions & 9 deletions tests/github/issues.sh
Original file line number Diff line number Diff line change
@@ -1,82 +1,93 @@
#!/bin/bash
. /usr/share/beakerlib/beakerlib.sh || exit 1

did="did --config"

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"
CHECK_UNTIL="--since 2022-10-01 --until 2022-10-26"

rlJournalStart

# Issues Created

rlPhaseStartTest "Issues Created"
rlRun -s "did --config ./config-default.ini --gh-issues-created $YEAR_2022"
rlRun -s "$did ./config-default.ini --gh-issues-created $YEAR_2022"
rlAssertGrep "Issues created on gh: 31$" $rlRun_LOG
rlAssertGrep "teemtee/tmt#1737 - Introduce a new step for cleanup tasks" $rlRun_LOG
rlAssertGrep "teemtee/fmf#149 - Checkout of the default branch fails" $rlRun_LOG
rlAssertGrep "packit/packit-service#1645 - Manually trigger internal jobs" $rlRun_LOG
rlPhaseEnd

rlPhaseStartTest "Issues Created (org:teemtee)"
rlRun -s "did --config ./config-org.ini --gh-issues-created $YEAR_2022"
rlRun -s "$did ./config-org.ini --gh-issues-created $YEAR_2022"
rlAssertGrep "Issues created on gh: 30$" $rlRun_LOG
rlAssertGrep "teemtee/tmt#1737 - Introduce a new step for cleanup tasks" $rlRun_LOG
rlAssertGrep "teemtee/fmf#149 - Checkout of the default branch fails" $rlRun_LOG
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"
rlRun -s "$did ./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"
rlRun -s "$did ./config-repo.ini --gh-issues-created $YEAR_2022"
rlAssertGrep "Issues created on gh: 2$" $rlRun_LOG
rlAssertNotGrep "teemtee/tmt#1737 - Introduce a new step for cleanup tasks" $rlRun_LOG
rlAssertGrep "teemtee/fmf#149 - Checkout of the default branch fails" $rlRun_LOG
rlAssertNotGrep "packit/packit-service#1645 - Manually trigger internal jobs" $rlRun_LOG
rlPhaseEnd

rlPhaseStartTest "Issues Created (user:psss)"
rlRun -s "did --config ./config-user.ini --gh-issues-created $YEAR_2021"
rlRun -s "$did ./config-user.ini --gh-issues-created $YEAR_2021"
rlAssertGrep "Issues created on gh: 1$" $rlRun_LOG
rlAssertGrep "psss/did#247 - Implement pagination for the GitHub plugin" $rlRun_LOG
rlAssertNotGrep "packit/packit#1386 - Allow to disable web access" $rlRun_LOG
rlAssertNotGrep "teemtee/tmt#910 - Shall we introduce a uuid for tests?" $rlRun_LOG
rlPhaseEnd

rlPhaseStartTest "Issues Created, check correct --until"
rlRun -s "$did ./config-default.ini --gh-issues-created $CHECK_UNTIL"
rlAssertGrep "Issues created on gh: 1$" $rlRun_LOG
rlAssertGrep "teemtee/tmt#1559 - Update the overview of essential classes$" $rlRun_LOG
rlAssertNotGrep 'teemtee/tmt#1648' $rlRun_LOG
rlAssertNotGrep 'teemtee/tmt#1650' $rlRun_LOG
rlPhaseEnd

# Issues Closed

rlPhaseStartTest "Issues Closed"
rlRun -s "did --config ./config-default.ini --gh-issues-closed $YEAR_2022"
rlRun -s "$did ./config-default.ini --gh-issues-closed $YEAR_2022"
rlAssertGrep "Issues closed on gh: 17$" $rlRun_LOG
rlAssertGrep "teemtee/fmf#014 - Define a way how to undefine an attribute" $rlRun_LOG
rlAssertGrep "teemtee/tmt#991 - Incompatible environment variable name" $rlRun_LOG
rlAssertGrep "psss/did#269 - Invalid plugin type 'google'" $rlRun_LOG
rlPhaseEnd

rlPhaseStartTest "Issues Closed (org:teemtee)"
rlRun -s "did --config ./config-org.ini --gh-issues-closed $YEAR_2022"
rlRun -s "$did ./config-org.ini --gh-issues-closed $YEAR_2022"
rlAssertGrep "Issues closed on gh: 15$" $rlRun_LOG
rlAssertGrep "teemtee/fmf#014 - Define a way how to undefine an attribute" $rlRun_LOG
rlAssertGrep "teemtee/tmt#991 - Incompatible environment variable name" $rlRun_LOG
rlAssertNotGrep "psss/did#269 - Invalid plugin type 'google'" $rlRun_LOG
rlPhaseEnd

rlPhaseStartTest "Issues Closed (repo:teemtee/fmf)"
rlRun -s "did --config ./config-repo.ini --gh-issues-closed $YEAR_2022"
rlRun -s "$did ./config-repo.ini --gh-issues-closed $YEAR_2022"
rlAssertGrep "Issues closed on gh: 3$" $rlRun_LOG
rlAssertGrep "teemtee/fmf#014 - Define a way how to undefine an attribute" $rlRun_LOG
rlAssertNotGrep "teemtee/tmt#991 - Incompatible environment variable name" $rlRun_LOG
rlAssertNotGrep "psss/did#269 - Invalid plugin type 'google'" $rlRun_LOG
rlPhaseEnd

rlPhaseStartTest "Issues Closed (user:psss)"
rlRun -s "did --config ./config-user.ini --gh-issues-closed $YEAR_2022"
rlRun -s "$did ./config-user.ini --gh-issues-closed $YEAR_2022"
rlAssertGrep "Issues closed on gh: 1$" $rlRun_LOG
rlAssertNotGrep "teemtee/fmf#014 - Define a way how to undefine an attribute" $rlRun_LOG
rlAssertNotGrep "teemtee/tmt#991 - Incompatible environment variable name" $rlRun_LOG
Expand Down
29 changes: 20 additions & 9 deletions tests/github/pulls.sh
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
#!/bin/bash
. /usr/share/beakerlib/beakerlib.sh || exit 1

did="did --config"

YEAR_2022="--since 2022-01-01 --until 2022-12-31"
YEAR_2021="--since 2021-01-01 --until 2021-12-31"
CHECK_UNTIL="--since 2022-10-01 --until 2022-10-26"

rlJournalStart

# Pull Requests Created

rlPhaseStartTest "Pull Requests Created"
rlRun -s "did --config ./config-default.ini --gh-pull-requests-created $YEAR_2022"
rlRun -s "$did ./config-default.ini --gh-pull-requests-created $YEAR_2022"
rlAssertGrep "Pull requests created on gh: 94$" $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
Expand All @@ -20,7 +23,7 @@ rlJournalStart
rlPhaseEnd

rlPhaseStartTest "Pull Requests Created (org:teemtee)"
rlRun -s "did --config ./config-org.ini --gh-pull-requests-created $YEAR_2022"
rlRun -s "$did ./config-org.ini --gh-pull-requests-created $YEAR_2022"
rlAssertGrep "Pull requests created on gh: 85$" $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
Expand All @@ -31,7 +34,7 @@ rlJournalStart
rlPhaseEnd

rlPhaseStartTest "Pull Requests Created (org:teemtee,packit)"
rlRun -s "did --config ./config-more.ini --gh-pull-requests-created $YEAR_2022"
rlRun -s "$did ./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
Expand All @@ -42,7 +45,7 @@ rlJournalStart
rlPhaseEnd

rlPhaseStartTest "Pull Requests Created (repo:teemtee/fmf)"
rlRun -s "did --config ./config-repo.ini --gh-pull-requests-created $YEAR_2022"
rlRun -s "$did ./config-repo.ini --gh-pull-requests-created $YEAR_2022"
rlAssertGrep "Pull requests created on gh: 7$" $rlRun_LOG
rlAssertNotGrep "teemtee/tmt#1750 - Include the new web link in verbose" $rlRun_LOG
rlAssertGrep "teemtee/fmf#170 - Implement a directive for disabling inheritance" $rlRun_LOG
Expand All @@ -53,7 +56,7 @@ rlJournalStart
rlPhaseEnd

rlPhaseStartTest "Pull Requests Created (user:psss)"
rlRun -s "did --config ./config-user.ini --gh-pull-requests-created $YEAR_2022"
rlRun -s "$did ./config-user.ini --gh-pull-requests-created $YEAR_2022"
rlAssertGrep "Pull requests created on gh: 7$" $rlRun_LOG
rlAssertNotGrep "teemtee/tmt#1750 - Include the new web link in verbose" $rlRun_LOG
rlAssertNotGrep "teemtee/fmf#170 - Implement a directive for disabling inheritance" $rlRun_LOG
Expand All @@ -63,10 +66,18 @@ rlJournalStart
rlAssertNotGrep "packit/packit.dev#399 - Update \`tmt\` examples" $rlRun_LOG
rlPhaseEnd

rlPhaseStartTest "Pull Requests Created, check correct --until"
rlRun -s "$did ./config-default.ini --gh-pull-requests-created $CHECK_UNTIL"
rlAssertGrep "Pull requests created on gh: 7$" $rlRun_LOG
rlAssertGrep 'teemtee/tmt#1642 - Move the hardware specification into a separate page$' $rlRun_LOG
rlAssertNotGrep 'teemtee/tmt#1645' $rlRun_LOG
rlAssertNotGrep 'teemtee/tmt#1644' $rlRun_LOG
rlPhaseEnd

# Pull Requests Closed

rlPhaseStartTest "Pull Requests Closed"
rlRun -s "did --config ./config-default.ini --gh-pull-requests-closed $YEAR_2022"
rlRun -s "$did ./config-default.ini --gh-pull-requests-closed $YEAR_2022"
rlAssertGrep "Pull requests closed on gh: 315$" $rlRun_LOG
rlAssertGrep "psss/did#272 - Koji plugin" $rlRun_LOG
rlAssertGrep "psss/python-nitrate#038 - Properly handle string" $rlRun_LOG
Expand All @@ -76,7 +87,7 @@ rlJournalStart
rlPhaseEnd

rlPhaseStartTest "Pull Requests Closed (org:teemtee)"
rlRun -s "did --config ./config-org.ini --gh-pull-requests-closed $YEAR_2022"
rlRun -s "$did ./config-org.ini --gh-pull-requests-closed $YEAR_2022"
rlAssertGrep "Pull requests closed on gh: 305$" $rlRun_LOG
rlAssertNotGrep "psss/did#272 - Koji plugin" $rlRun_LOG
rlAssertNotGrep "psss/python-nitrate#038 - Properly handle string" $rlRun_LOG
Expand All @@ -86,7 +97,7 @@ rlJournalStart
rlPhaseEnd

rlPhaseStartTest "Pull Requests Closed (repo:teemtee/fmf)"
rlRun -s "did --config ./config-repo.ini --gh-pull-requests-closed $YEAR_2022"
rlRun -s "$did ./config-repo.ini --gh-pull-requests-closed $YEAR_2022"
rlAssertGrep "Pull requests closed on gh: 13$" $rlRun_LOG
rlAssertNotGrep "psss/did#272 - Koji plugin" $rlRun_LOG
rlAssertNotGrep "psss/python-nitrate#038 - Properly handle string" $rlRun_LOG
Expand All @@ -96,7 +107,7 @@ rlJournalStart
rlPhaseEnd

rlPhaseStartTest "Pull Requests Closed (user:psss)"
rlRun -s "did --config ./config-user.ini --gh-pull-requests-closed $YEAR_2022"
rlRun -s "$did ./config-user.ini --gh-pull-requests-closed $YEAR_2022"
rlAssertGrep "Pull requests closed on gh: 10$" $rlRun_LOG
rlAssertGrep "psss/did#272 - Koji plugin" $rlRun_LOG
rlAssertGrep "psss/python-nitrate#038 - Properly handle string" $rlRun_LOG
Expand Down