From 7236c9bf292a3d3a6254786296c4b679af3a6817 Mon Sep 17 00:00:00 2001
From: Anton Medvedev <amedvede@redhat.com>
Date: Nov 19 2024 14:43:03 +0000
Subject: [PATCH 1/2] fix: changes logic to show all archived releases as inactive regardless containing dead.package file


Signed-off-by: Anton Medvedev <amedvede@redhat.com>

---

diff --git a/pagure/themes/srcfpo/templates/repo_branches.html b/pagure/themes/srcfpo/templates/repo_branches.html
index 3cac451..e2206bf 100644
--- a/pagure/themes/srcfpo/templates/repo_branches.html
+++ b/pagure/themes/srcfpo/templates/repo_branches.html
@@ -140,15 +140,8 @@
 function disable_branches() {
   function checkForDeadPackage(branch, namespace, repo_name) {
     return new Promise((resolve, reject) => {
-      // Getting variable from config to find out type of link that should be used
-      let appUrl = "{{ config['APP_URL'] }}"
-
-      let branchUrl;
-      if (appUrl === "https://stg.pagure.io/") {
-        branchUrl = `https://src.stg.fedoraproject.org/${namespace}/${repo_name}/blob/${branch}/f/dead.package`;
-      } else {
-        branchUrl = `https://src.fedoraproject.org/${namespace}/${repo_name}/blob/${branch}/f/dead.package`;
-      }
+      // Construct the URL to check for dead.package
+      let branchUrl = `https://src.fedoraproject.org/${namespace}/${repo_name}/blob/${branch}/f/dead.package`;
       $.ajax({
         url: branchUrl,
         type: "HEAD",
@@ -166,19 +159,30 @@ function disable_branches() {
     });
   }
 
-  function checkForDeadPackagesInBranches(branches, namespace, repo_name) {
-    const promises = branches.map(branch => checkForDeadPackage(branch, namespace, repo_name));
-    Promise.all(promises).then(results => {
+  function checkForDeadPackagesInBranches(activeReleases, inactiveReleases, namespace, repo_name) {
+    const activeReleaseChecks = activeReleases.map(branch => checkForDeadPackage(branch, namespace, repo_name));
+
+    Promise.all(activeReleaseChecks).then(results => {
       let act_br = $('#active_branches');
       let inact_br = $('#inactive_branches');
+
+      // Check if active branch contains dead.pacakge
       results.forEach(result => {
+        let _it = $('#branch-' + result.branch);
         if (result.hasDeadPackage) {
-          console.log(_ns, _repo_name, result.branch);
-          let _it = $('#branch-' + result.branch);
           _it.addClass('disabled_branch');
           inact_br.append(_it);
+        } else {
+          act_br.append(_it);
         }
       });
+
+      // Automatically mark all inactiveReleases (branches) as inactive
+      inactiveReleases.forEach(branch => {
+        let _it = $('#branch-' + branch);
+        _it.addClass('disabled_branch');
+        inact_br.append(_it);
+      });
     });
   }
 
@@ -187,48 +191,66 @@ function disable_branches() {
       url: url,
       method: 'GET',
       dataType: 'json',
+    }).then(function(response) {
+      const totalReleases = response.total;
+      if (totalReleases > 0) {
+        const newUrl = `${url}&rows_per_page=${totalReleases}`;
+        return $.ajax({
+          url: newUrl,
+          method: 'GET',
+          dataType: 'json',
+        }).then(function(fullResponse) {
+          const releases = fullResponse.releases;
+          let tags = releases.map(release => release.branch);
+          return [...new Set(tags)];
+        });
+      } else {
+        return []
+      }
     });
   }
 
-  function getBranches() {
-    // Getting variable from config to find out type of link that should be used
-    let appUrl = "{{ config['APP_URL'] }}"
-
-    let request1, request2, request3;
-    if (appUrl === "https://stg.pagure.io/") {
-      request1 = fetchReleases('https://bodhi.stg.fedoraproject.org/list_releases/?state=current');
-      request2 = fetchReleases('https://bodhi.stg.fedoraproject.org/list_releases/?state=pending');
-      request3 = fetchReleases('https://bodhi.stg.fedoraproject.org/list_releases/?state=frozen');
-    } else {
-      request1 = fetchReleases('https://bodhi.fedoraproject.org/list_releases/?state=current');
-      request2 = fetchReleases('https://bodhi.fedoraproject.org/list_releases/?state=pending');
-      request3 = fetchReleases('https://bodhi.fedoraproject.org/list_releases/?state=frozen');
-    }
-
-    return Promise.all([request1, request2, request3]).then(function (responses) {
-      let currentReleases = responses[0].releases;
-      let pendingReleases = responses[1].releases;
-      let frozenReleases = responses[2].releases;
-
-      let mergedReleases = currentReleases.concat(pendingReleases).concat(frozenReleases);
-      let tags = mergedReleases.map(release => release.branch);
-
-      return [...new Set(tags)]; // Return the unique tags
-    }).catch(function (error) {
-      console.error('Error:', error);
+  function fetchMultipleTypeOfReleases(urls) {
+    const promises = urls.map(url => fetchReleases(url));
+    return Promise.all(promises).then(function(results) {
+      return results;
     });
   }
 
-
   const _ns = '{{ repo.namespace }}'
   const _repo_name = '{{ repo.name }}'
   console.log(_ns, _repo_name);
 
-  getBranches().then(branches => {
-    console.log(branches)
-    checkForDeadPackagesInBranches(branches, _ns, _repo_name);
-  }).catch(function (error) {
-    console.error("Error:", error);
+  let appUrl = "{{ config['APP_URL'] }}"
+  let urls;
+  if (appUrl === "https://stg.pagure.io/") {
+    urls = [
+      'https://bodhi.stg.fedoraproject.org/list_releases/?state=archived',
+      'https://bodhi.stg.fedoraproject.org/list_releases/?state=current',
+      'https://bodhi.stg.fedoraproject.org/list_releases/?state=pending',
+      'https://bodhi.stg.fedoraproject.org/list_releases/?state=frozen'
+    ]
+  } else {
+    urls = [
+      'https://bodhi.fedoraproject.org/list_releases/?state=archived',
+      'https://bodhi.fedoraproject.org/list_releases/?state=current',
+      'https://bodhi.fedoraproject.org/list_releases/?state=pending',
+      'https://bodhi.fedoraproject.org/list_releases/?state=frozen'
+    ]
+  }
+
+  fetchMultipleTypeOfReleases(urls).then(function(allReleases) {
+    const [archivedReleases, currentReleases,
+      pendingReleases, frozenReleases] = allReleases;
+
+    let mergedReleases = currentReleases.concat(pendingReleases).concat(frozenReleases);
+    const activeReleases = [...new Set(mergedReleases)];
+    const inactiveReleases = archivedReleases;
+
+    {#console.log('Active Releases:', activeReleases);#}
+    {#console.log('Inactive Releases:', inactiveReleases);#}
+
+    checkForDeadPackagesInBranches(activeReleases, inactiveReleases, _ns, _repo_name);
   });
 }
 

From 9c06db816a4cc1bedd155278078d5fc56244a72b Mon Sep 17 00:00:00 2001
From: Anton Medvedev <amedvede@redhat.com>
Date: Nov 19 2024 14:43:03 +0000
Subject: [PATCH 2/2] feat: changes in recognizing branch as innactive


Signed-off-by: Anton Medvedev <amedvede@redhat.com>

---

diff --git a/pagure/themes/srcfpo/templates/repo_branches.html b/pagure/themes/srcfpo/templates/repo_branches.html
index e2206bf..34961cd 100644
--- a/pagure/themes/srcfpo/templates/repo_branches.html
+++ b/pagure/themes/srcfpo/templates/repo_branches.html
@@ -159,8 +159,8 @@ function disable_branches() {
     });
   }
 
-  function checkForDeadPackagesInBranches(activeReleases, inactiveReleases, namespace, repo_name) {
-    const activeReleaseChecks = activeReleases.map(branch => checkForDeadPackage(branch, namespace, repo_name));
+  function checkForDeadPackagesInBranches(activeBranchesOnPackage, inactiveBrancesOnPackage, namespace, repo_name) {
+    const activeReleaseChecks = activeBranchesOnPackage.map(branch => checkForDeadPackage(branch, namespace, repo_name));
 
     Promise.all(activeReleaseChecks).then(results => {
       let act_br = $('#active_branches');
@@ -178,7 +178,7 @@ function disable_branches() {
       });
 
       // Automatically mark all inactiveReleases (branches) as inactive
-      inactiveReleases.forEach(branch => {
+      inactiveBrancesOnPackage.forEach(branch => {
         let _it = $('#branch-' + branch);
         _it.addClass('disabled_branch');
         inact_br.append(_it);
@@ -210,11 +210,14 @@ function disable_branches() {
     });
   }
 
-  function fetchMultipleTypeOfReleases(urls) {
-    const promises = urls.map(url => fetchReleases(url));
-    return Promise.all(promises).then(function(results) {
-      return results;
+  function getBranchNames() {
+    const branches = document.querySelectorAll('#active_branches .list-group-item');
+    const branchNames = [];
+    branches.forEach(branch => {
+        let branchName = branch.id.replace("branch-", "");
+        branchNames.push(branchName);
     });
+    return branchNames;
   }
 
   const _ns = '{{ repo.namespace }}'
@@ -222,36 +225,25 @@ function disable_branches() {
   console.log(_ns, _repo_name);
 
   let appUrl = "{{ config['APP_URL'] }}"
-  let urls;
+  let urlOfNonActiveReleases;
+
   if (appUrl === "https://stg.pagure.io/") {
-    urls = [
-      'https://bodhi.stg.fedoraproject.org/list_releases/?state=archived',
-      'https://bodhi.stg.fedoraproject.org/list_releases/?state=current',
-      'https://bodhi.stg.fedoraproject.org/list_releases/?state=pending',
-      'https://bodhi.stg.fedoraproject.org/list_releases/?state=frozen'
-    ]
+    urlOfNonActiveReleases = "https://bodhi.stg.fedoraproject.org/list_releases/?state=archived";
   } else {
-    urls = [
-      'https://bodhi.fedoraproject.org/list_releases/?state=archived',
-      'https://bodhi.fedoraproject.org/list_releases/?state=current',
-      'https://bodhi.fedoraproject.org/list_releases/?state=pending',
-      'https://bodhi.fedoraproject.org/list_releases/?state=frozen'
-    ]
+    urlOfNonActiveReleases = "https://bodhi.fedoraproject.org/list_releases/?state=archived";
   }
 
-  fetchMultipleTypeOfReleases(urls).then(function(allReleases) {
-    const [archivedReleases, currentReleases,
-      pendingReleases, frozenReleases] = allReleases;
-
-    let mergedReleases = currentReleases.concat(pendingReleases).concat(frozenReleases);
-    const activeReleases = [...new Set(mergedReleases)];
-    const inactiveReleases = archivedReleases;
+  fetchReleases(urls).then(inactiveReleases => {
+    let branchesOfPackage = getBranchNames();
+    let inactiveBrancesOnPackage = branchesOfPackage.filter(branch => inactiveReleases.includes(branch));
+    let activeBranchesOnPackage = branchesOfPackage.filter(branch => !inactiveReleases.includes(branch));
+    console.log(branchesOfPackage);
+    console.log(inactiveReleases);
+    console.log(nonActiveBrancesOnPackage);
+    console.log(activeBranchesOnPackage);
 
-    {#console.log('Active Releases:', activeReleases);#}
-    {#console.log('Inactive Releases:', inactiveReleases);#}
-
-    checkForDeadPackagesInBranches(activeReleases, inactiveReleases, _ns, _repo_name);
-  });
+    checkForDeadPackagesInBranches(activeBranchesOnPackage, inactiveBrancesOnPackage, _ns, _repo_name);
+  })
 }
 
 $(function() {

