From ef08699d77359c9e120ae2bdaf122172eb8ac059 Mon Sep 17 00:00:00 2001
From: Oleg Krivtsov <olegkrivtsov@gmail.com>
Date: Fri, 10 Sep 2021 12:08:31 +0700
Subject: [PATCH] Return null in case of ambiguous package name resolution in
 Repology (#11654)

---
 .../repology/__snapshots__/index.spec.ts.snap    | 15 +++++++++++++++
 lib/datasource/repology/index.spec.ts            | 16 ++++++++++++++++
 lib/datasource/repology/index.ts                 |  7 +++++++
 3 files changed, 38 insertions(+)

diff --git a/lib/datasource/repology/__snapshots__/index.spec.ts.snap b/lib/datasource/repology/__snapshots__/index.spec.ts.snap
index f31c48d616..d19ada2583 100644
--- a/lib/datasource/repology/__snapshots__/index.spec.ts.snap
+++ b/lib/datasource/repology/__snapshots__/index.spec.ts.snap
@@ -276,6 +276,21 @@ Array [
 ]
 `;
 
+exports[`datasource/repology/index getReleases returns null on Resolver ambiguous binary package 1`] = `
+Array [
+  Object {
+    "headers": Object {
+      "accept": "application/json",
+      "accept-encoding": "gzip, deflate, br",
+      "host": "repology.org",
+      "user-agent": "RenovateBot/0.0.0-semantic-release (https://github.com/renovatebot/renovate)",
+    },
+    "method": "GET",
+    "url": "https://repology.org/tools/project-by?repo=ubuntu_20_04&name_type=binname&target_page=api_v1_project&noautoresolve=on&name=git",
+  },
+]
+`;
+
 exports[`datasource/repology/index getReleases throws error on API request timeout 1`] = `
 Array [
   Object {
diff --git a/lib/datasource/repology/index.spec.ts b/lib/datasource/repology/index.spec.ts
index caaa3a0619..c7b7e13783 100644
--- a/lib/datasource/repology/index.spec.ts
+++ b/lib/datasource/repology/index.spec.ts
@@ -181,6 +181,22 @@ describe('datasource/repology/index', () => {
       expect(httpMock.getTrace()).toMatchSnapshot();
     });
 
+    it('returns null on Resolver ambiguous binary package', async () => {
+      mockResolverCall('ubuntu_20_04', 'git', 'binname', {
+        status: 300,
+        body: '[]',
+      });
+
+      expect(
+        await getPkgReleases({
+          datasource,
+          versioning,
+          depName: 'ubuntu_20_04/git',
+        })
+      ).toBeNull();
+      expect(httpMock.getTrace()).toMatchSnapshot();
+    });
+
     it('throws without repository and package name', async () => {
       await expect(
         getPkgReleases({
diff --git a/lib/datasource/repology/index.ts b/lib/datasource/repology/index.ts
index 53fb346682..d87f0069cb 100644
--- a/lib/datasource/repology/index.ts
+++ b/lib/datasource/repology/index.ts
@@ -152,7 +152,14 @@ async function queryPackage(
         // exit immediately if package found
         return pkg;
       }
+    } else if (err.statusCode === 300) {
+      logger.warn(
+        { repoName, pkgName },
+        'Ambiguous redirection from package name to project name in Repology. Skipping this package'
+      );
+      return null;
     }
+
     throw err;
   }
 
-- 
GitLab