From 2d65f27d80ebf5fe98d12a7c0ccc59709bb4952a Mon Sep 17 00:00:00 2001
From: Sergei Zharinov <zharinov@users.noreply.github.com>
Date: Sun, 12 Feb 2023 20:05:56 +0300
Subject: [PATCH] refactor(bazel): Simplify version extraction from GitHub url
 (#20361)

---
 lib/modules/manager/bazel/rules/http.ts | 23 +++++++++++------------
 1 file changed, 11 insertions(+), 12 deletions(-)

diff --git a/lib/modules/manager/bazel/rules/http.ts b/lib/modules/manager/bazel/rules/http.ts
index 7f773b97fa..9f1ba2b350 100644
--- a/lib/modules/manager/bazel/rules/http.ts
+++ b/lib/modules/manager/bazel/rules/http.ts
@@ -17,23 +17,22 @@ export function parseArchiveUrl(
   if (!url || url.host !== 'github.com' || !url.pathname) {
     return null;
   }
-  const path = url.pathname.split('/').slice(1);
-  const repo = path[0] + '/' + path[1];
+  const [p0, p1, p2, p3, p4, p5] = url.pathname.split('/').slice(1);
+  const repo = p0 + '/' + p1;
   let datasource = '';
   let currentValue: string | null = null;
-  if (path[2] === 'releases' && path[3] === 'download') {
+  if (p2 === 'releases' && p3 === 'download') {
+    // https://github.com/foo/bar/releases/download/1.2.3/bar-1.2.3.tar.gz
     datasource = GithubReleasesDatasource.id;
-    currentValue = path[4];
-  } else if (
-    path[2] === 'archive' &&
-    path[3] === 'refs' &&
-    path[4] === 'tags'
-  ) {
+    currentValue = p4;
+  } else if (p2 === 'archive' && p3 === 'refs' && p4 === 'tags') {
+    // https://github.com/foo/bar/archive/refs/tags/v1.2.3.tar.gz
     datasource = GithubTagsDatasource.id;
-    currentValue = path[5];
-  } else if (path[2] === 'archive') {
+    currentValue = p5;
+  } else if (p2 === 'archive') {
+    // https://github.com/foo/bar/archive/1.2.3.tar.gz
     datasource = GithubTagsDatasource.id;
-    currentValue = path[3];
+    currentValue = p3;
   }
 
   if (currentValue) {
-- 
GitLab