public inbox for gentoo-commits@lists.gentoo.org
 help / color / mirror / Atom feed
From: "Arthur Zamarin" <arthurzam@gentoo.org>
To: gentoo-commits@lists.gentoo.org
Subject: [gentoo-commits] proj/pkgcore/pkgcheck:master commit in: src/pkgcheck/checks/, tests/checks/
Date: Sat, 21 Jan 2023 09:46:01 +0000 (UTC)	[thread overview]
Message-ID: <1674294257.7d50c226b79d158ed08e925369560727993fb0b7.arthurzam@gentoo> (raw)

commit:     7d50c226b79d158ed08e925369560727993fb0b7
Author:     Arthur Zamarin <arthurzam <AT> gentoo <DOT> org>
AuthorDate: Sat Jan 21 09:44:17 2023 +0000
Commit:     Arthur Zamarin <arthurzam <AT> gentoo <DOT> org>
CommitDate: Sat Jan 21 09:44:17 2023 +0000
URL:        https://gitweb.gentoo.org/proj/pkgcore/pkgcheck.git/commit/?id=7d50c226

SuspiciousSrcUriChange: fix false positive with mirrors

The original code for comparing for URL change was giving false
positives when the URI is mirror based, since an object was used to
compare. Pre-compute the URI string and use strings for comparison.
Also add a test for that failure.

Resolves: https://github.com/pkgcore/pkgcheck/issues/531
Signed-off-by: Arthur Zamarin <arthurzam <AT> gentoo.org>

 src/pkgcheck/checks/git.py | 26 ++++++++++++++------------
 tests/checks/test_git.py   |  6 ++++++
 2 files changed, 20 insertions(+), 12 deletions(-)

diff --git a/src/pkgcheck/checks/git.py b/src/pkgcheck/checks/git.py
index 764dfc5d..adc16874 100644
--- a/src/pkgcheck/checks/git.py
+++ b/src/pkgcheck/checks/git.py
@@ -186,16 +186,10 @@ class SrcUriChecksumChange(results.PackageResult, results.Error):
 class SuspiciousSrcUriChange(results.PackageResult, results.Warning):
     """Suspicious SRC_URI changing URI without distfile rename."""
 
-    def __init__(self, old_uri, new_uri, filename, **kwargs):
+    def __init__(self, old_uri: str, new_uri: str, filename: str, **kwargs):
         super().__init__(**kwargs)
-        if isinstance(old_uri, tuple):
-            self.old_uri = f"mirror://{old_uri[0].mirror_name}/{old_uri[1]}"
-        else:
-            self.old_uri = str(old_uri)
-        if isinstance(new_uri, tuple):
-            self.new_uri = f"mirror://{new_uri[0].mirror_name}/{new_uri[1]}"
-        else:
-            self.new_uri = str(new_uri)
+        self.old_uri = old_uri
+        self.new_uri = new_uri
         self.filename = filename
 
     @property
@@ -381,18 +375,26 @@ class GitPkgCommitsCheck(GentooRepoCheck, GitCommitsCheck):
             else:
                 yield MissingSlotmove(old_slot, new_slot, pkg=new_pkg)
 
+    @staticmethod
+    def _fetchable_str(fetch: fetchable) -> str:
+        uri = tuple(fetch.uri._uri_source)[0]
+        if isinstance(uri, tuple):
+            return f"mirror://{uri[0].mirror_name}/{uri[1]}"
+        else:
+            return str(uri)
+
     def src_uri_changes(self, pkgset):
         pkg = pkgset[0].unversioned_atom
 
         try:
             new_checksums = {
-                fetch.filename: (fetch.chksums, tuple(fetch.uri._uri_source))
+                fetch.filename: (fetch.chksums, self._fetchable_str(fetch))
                 for pkg in self.repo.match(pkg)
                 for fetch in iflatten_instance(pkg.fetchables, fetchable)
             }
 
             old_checksums = {
-                fetch.filename: (fetch.chksums, tuple(fetch.uri._uri_source))
+                fetch.filename: (fetch.chksums, self._fetchable_str(fetch))
                 for pkg in self.modified_repo(pkgset).match(pkg)
                 for fetch in iflatten_instance(pkg.fetchables, fetchable)
             }
@@ -406,7 +408,7 @@ class GitPkgCommitsCheck(GentooRepoCheck, GitCommitsCheck):
             if old_checksum != new_checksum:
                 yield SrcUriChecksumChange(filename, pkg=pkg)
             elif old_uri != new_uri:
-                yield SuspiciousSrcUriChange(old_uri[0], new_uri[0], filename, pkg=pkg)
+                yield SuspiciousSrcUriChange(old_uri, new_uri, filename, pkg=pkg)
 
     def feed(self, pkgset: list[git.GitPkgChange]):
         # Mapping of commit types to pkgs, available commit types can be seen

diff --git a/tests/checks/test_git.py b/tests/checks/test_git.py
index b69893d8..eed40e13 100644
--- a/tests/checks/test_git.py
+++ b/tests/checks/test_git.py
@@ -702,6 +702,12 @@ class TestGitPkgCommitsCheck(ReportTestCase):
         self.init_check()
         r = self.assertReport(self.check, self.source)
         assert r == git_mod.SuspiciousSrcUriChange(old_url, new_url, distfile[1], pkg=CP("cat/pkg"))
+        # revert change and check for no report with same mirror url
+        self.child_git_repo.run(["git", "reset", "--hard", "origin/main"])
+        self.child_repo.create_ebuild("cat/pkg-1", src_uri=old_url, eapi="8")
+        self.child_git_repo.add_all("cat/pkg: bump EAPI", signoff=True)
+        self.init_check()
+        self.assertNoReport(self.check, self.source)
 
 
 class TestGitEclassCommitsCheck(ReportTestCase):


             reply	other threads:[~2023-01-21  9:46 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-01-21  9:46 Arthur Zamarin [this message]
  -- strict thread matches above, loose matches on Subject: below --
2025-01-16 12:17 [gentoo-commits] proj/pkgcore/pkgcheck:master commit in: src/pkgcheck/checks/, tests/checks/ Arthur Zamarin
2024-03-07 16:06 Arthur Zamarin
2023-07-15  8:52 Arthur Zamarin
2023-03-11  7:14 Arthur Zamarin
2023-03-05 17:13 Arthur Zamarin
2023-03-04  5:59 Arthur Zamarin
2023-01-20 20:47 Arthur Zamarin
2022-11-26 11:47 Arthur Zamarin
2022-11-26 11:47 Arthur Zamarin
2022-10-28 13:34 Arthur Zamarin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1674294257.7d50c226b79d158ed08e925369560727993fb0b7.arthurzam@gentoo \
    --to=arthurzam@gentoo.org \
    --cc=gentoo-commits@lists.gentoo.org \
    --cc=gentoo-dev@lists.gentoo.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox