From 010a0c54629555950c43ec874647c4b319ec46c1 Mon Sep 17 00:00:00 2001 From: "Mikhail f. Shiryaev" Date: Tue, 26 Mar 2024 22:40:55 +0100 Subject: [PATCH 1/3] Fix issue with wrong `until` in GitHub search --- did/plugins/github.py | 42 ++++++++++++++++++++++++++++++++++-------- 1 file changed, 34 insertions(+), 8 deletions(-) diff --git a/did/plugins/github.py b/did/plugins/github.py index e269df1c..5d2525bc 100644 --- a/did/plugins/github.py +++ b/did/plugins/github.py @@ -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 @@ -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 = [] @@ -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)] @@ -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)] @@ -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)] @@ -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)] @@ -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)] @@ -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)] @@ -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)] From 145861ef47e72b2d8ea26c33c1c20f5862d8ac7e Mon Sep 17 00:00:00 2001 From: "Mikhail f. Shiryaev" Date: Wed, 9 Oct 2024 19:29:01 +0200 Subject: [PATCH 2/3] Use $did as `did --config` in tests --- tests/github/issues.sh | 20 +++++++++++--------- tests/github/pulls.sh | 20 +++++++++++--------- 2 files changed, 22 insertions(+), 18 deletions(-) diff --git a/tests/github/issues.sh b/tests/github/issues.sh index 7653d54b..59ed9a44 100755 --- a/tests/github/issues.sh +++ b/tests/github/issues.sh @@ -1,6 +1,8 @@ #!/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" @@ -10,7 +12,7 @@ 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 @@ -18,7 +20,7 @@ rlJournalStart 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 @@ -26,7 +28,7 @@ rlJournalStart 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 @@ -34,7 +36,7 @@ rlJournalStart 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 @@ -42,7 +44,7 @@ rlJournalStart 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 @@ -52,7 +54,7 @@ rlJournalStart # 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 @@ -60,7 +62,7 @@ rlJournalStart 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 @@ -68,7 +70,7 @@ rlJournalStart 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 @@ -76,7 +78,7 @@ rlJournalStart 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 diff --git a/tests/github/pulls.sh b/tests/github/pulls.sh index 2d984730..c5d047a6 100755 --- a/tests/github/pulls.sh +++ b/tests/github/pulls.sh @@ -1,6 +1,8 @@ #!/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" @@ -9,7 +11,7 @@ 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 @@ -20,7 +22,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 @@ -31,7 +33,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 @@ -42,7 +44,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 @@ -53,7 +55,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 @@ -66,7 +68,7 @@ rlJournalStart # 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 @@ -76,7 +78,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 @@ -86,7 +88,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 @@ -96,7 +98,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 From 6a1a32fbcc3bc0c8f459f82dc909a5e42d9d26e6 Mon Sep 17 00:00:00 2001 From: "Mikhail f. Shiryaev" Date: Wed, 9 Oct 2024 19:29:48 +0200 Subject: [PATCH 3/3] Add tests that break in master with wrong --until --- tests/github/issues.sh | 9 +++++++++ tests/github/pulls.sh | 9 +++++++++ 2 files changed, 18 insertions(+) diff --git a/tests/github/issues.sh b/tests/github/issues.sh index 59ed9a44..9432eda9 100755 --- a/tests/github/issues.sh +++ b/tests/github/issues.sh @@ -6,6 +6,7 @@ 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 @@ -51,6 +52,14 @@ rlJournalStart 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" diff --git a/tests/github/pulls.sh b/tests/github/pulls.sh index c5d047a6..33deb060 100755 --- a/tests/github/pulls.sh +++ b/tests/github/pulls.sh @@ -5,6 +5,7 @@ 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 @@ -65,6 +66,14 @@ 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"