From 611484dc47b80d54d47dd75b665decf22a3d1860 Mon Sep 17 00:00:00 2001 From: Muskan Paliwal Date: Tue, 20 Feb 2024 13:01:34 +0530 Subject: [PATCH 01/14] fixed chrome-extension styling to wokr with new github ui --- scripts/repoHandlers.js | 62 ++++++++++++++++++++++------------------- 1 file changed, 33 insertions(+), 29 deletions(-) diff --git a/scripts/repoHandlers.js b/scripts/repoHandlers.js index 72e3834..c02e447 100644 --- a/scripts/repoHandlers.js +++ b/scripts/repoHandlers.js @@ -72,40 +72,44 @@ function updateTrackedReposInBitbucketOrg(trackedRepos, websiteUrl) { * @param {boolean} isOrg - Whether github organization or user. */ function updateTrackedReposInGitHub(trackedRepos, websiteUrl, ownerType) { - const allRepo = ownerType == 'org' ? document.getElementById('org-repositories') : document.getElementById('user-repositories-list'); - const repoUrl = Array.from(allRepo.querySelectorAll('a[itemprop="name codeRepository"]')); + const repoList = ownerType == 'org' ? document.querySelectorAll('[data-testid="list-view-items"] > li') : document.querySelectorAll('[data-filterable-for="your-repos-filter"] > li'); + console.log("repoList: ", repoList) + + repoList.forEach((repoItem) => { + const repoLink = ownerType == 'org' ? repoItem.querySelector('[data-testid="listitem-title-link"]') : repoItem.querySelector('a[itemprop="name codeRepository"]'); + console.log("repoLink: ", repoLink); + if (!repoLink) return; + const repoUrl = repoLink.getAttribute('href'); + const repoName = repoUrl.split('/').pop(); - repoUrl.forEach((item) => { - const link = item.getAttribute('href').split('/'); - const repoName = link[link.length - 1]; + if (trackedRepos.includes(repoName)) { + let trackLogo = repoItem.querySelector('.trackLogo'); + if (trackLogo) { + trackLogo.remove(); + } - if (trackedRepos.includes(repoName)) { - const checkElement = item.getElementsByClassName('trackLogo')[0]; - if (checkElement) { - // TODO: Ideally, we should only need to add the element when there is none present - checkElement.remove(); - } - const img = document.createElement("img"); - img.setAttribute('class', 'trackLogo'); - const beforePsuedoElement = document.createElement('a'); - img.src = `${websiteUrl}/favicon.ico`; - img.style.width = '15px' - img.style.height = '15px' + const img = document.createElement("img"); + img.classList.add('trackLogo'); + img.src = `${websiteUrl}/favicon.ico`; + img.style.width = '15px'; + img.style.height = '15px'; - beforePsuedoElement.appendChild(img); - beforePsuedoElement.href = `${websiteUrl}/repo?repo_name=${repoName}`; - beforePsuedoElement.target = '_blank'; - beforePsuedoElement.style.display = 'inline-block'; - beforePsuedoElement.style.marginRight = '2px'; - beforePsuedoElement.style.color = 'white'; - beforePsuedoElement.style.borderRadius = '2px'; - beforePsuedoElement.style.fontSize = '15px'; - beforePsuedoElement.style.textDecoration = 'none'; + const link = document.createElement('a'); + link.href = `${websiteUrl}/repo?repo_name=${repoName}`; + link.target = '_blank'; + link.style.display ='inline-flex'; + link.style.marginRight ='6px'; + link.style.color = 'white'; + link.style.borderRadius = '2px'; + link.style.fontSize = '15px'; + link.style.textDecoration = 'none'; + link.style.alignItems ='center'; - item.insertBefore(beforePsuedoElement, item.firstChild); - } - }) + link.appendChild(img); + repoLink.parentNode.insertBefore(link, repoLink); + } + }); } /** From a441e78828e7e7550481da1db9036af256588908 Mon Sep 17 00:00:00 2001 From: Muskan Paliwal Date: Tue, 20 Feb 2024 13:09:08 +0530 Subject: [PATCH 02/14] removed logs --- scripts/repoHandlers.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/scripts/repoHandlers.js b/scripts/repoHandlers.js index c02e447..3a9fc9a 100644 --- a/scripts/repoHandlers.js +++ b/scripts/repoHandlers.js @@ -73,11 +73,9 @@ function updateTrackedReposInBitbucketOrg(trackedRepos, websiteUrl) { */ function updateTrackedReposInGitHub(trackedRepos, websiteUrl, ownerType) { const repoList = ownerType == 'org' ? document.querySelectorAll('[data-testid="list-view-items"] > li') : document.querySelectorAll('[data-filterable-for="your-repos-filter"] > li'); - console.log("repoList: ", repoList) repoList.forEach((repoItem) => { const repoLink = ownerType == 'org' ? repoItem.querySelector('[data-testid="listitem-title-link"]') : repoItem.querySelector('a[itemprop="name codeRepository"]'); - console.log("repoLink: ", repoLink); if (!repoLink) return; const repoUrl = repoLink.getAttribute('href'); From 13164ec2614b71dd0141a90d3993825e4e88af56 Mon Sep 17 00:00:00 2001 From: Muskan Paliwal Date: Wed, 21 Feb 2024 12:19:11 +0530 Subject: [PATCH 03/14] made the code compatible with older ui too --- scripts/repoHandlers.js | 67 +++++++++++++++++++++++++++-------------- 1 file changed, 44 insertions(+), 23 deletions(-) diff --git a/scripts/repoHandlers.js b/scripts/repoHandlers.js index 3a9fc9a..38a06b8 100644 --- a/scripts/repoHandlers.js +++ b/scripts/repoHandlers.js @@ -71,20 +71,40 @@ function updateTrackedReposInBitbucketOrg(trackedRepos, websiteUrl) { * @param {string} websiteUrl - The URL of the website. * @param {boolean} isOrg - Whether github organization or user. */ -function updateTrackedReposInGitHub(trackedRepos, websiteUrl, ownerType) { - const repoList = ownerType == 'org' ? document.querySelectorAll('[data-testid="list-view-items"] > li') : document.querySelectorAll('[data-filterable-for="your-repos-filter"] > li'); - - repoList.forEach((repoItem) => { - const repoLink = ownerType == 'org' ? repoItem.querySelector('[data-testid="listitem-title-link"]') : repoItem.querySelector('a[itemprop="name codeRepository"]'); - if (!repoLink) return; - const repoUrl = repoLink.getAttribute('href'); - const repoName = repoUrl.split('/').pop(); +function updateTrackedReposInGitHub(trackedRepos, websiteUrl, ownerType) { + let repoList; + let newUI = false; + + // Check if selectors for new UI exist + if (document.querySelector('[data-testid="list-view-items"]')) { + repoList = ownerType === 'org' ? document.querySelectorAll('[data-testid="list-view-items"] > li') : document.querySelectorAll('[data-filterable-for="your-repos-filter"] > li'); + newUI = true; + console.log("repos: ", repoList); + } else { + const allRepo = ownerType === 'org' ? document.getElementById('org-repositories') : document.getElementById('user-repositories-list'); + repoList = Array.from(allRepo.querySelectorAll('a[itemprop="name codeRepository"]')); + } + console.log("repoList: ", repoList); + repoList.forEach(repoItem => { + let repoUrl; + let repoLink + if (newUI){ + repoLink = ownerType == 'org' ? repoItem.querySelector('[data-testid="listitem-title-link"]') : repoItem.querySelector('a[itemprop="name codeRepository"]'); + if (!repoLink) return; + repoUrl = repoLink.getAttribute('href'); + console.log("repoUrl: ", repoUrl); + } else { + repoUrl = repoItem.getAttribute('href') + } + const repoName = repoUrl.split('/').pop(); + console.log("repoName: ", repoName); + if (trackedRepos.includes(repoName)) { - let trackLogo = repoItem.querySelector('.trackLogo'); - if (trackLogo) { - trackLogo.remove(); + const checkElement = repoItem.querySelector('.trackLogo'); + if (checkElement) { + checkElement.remove(); } const img = document.createElement("img"); @@ -93,19 +113,20 @@ function updateTrackedReposInGitHub(trackedRepos, websiteUrl, ownerType) { img.style.width = '15px'; img.style.height = '15px'; - const link = document.createElement('a'); - link.href = `${websiteUrl}/repo?repo_name=${repoName}`; - link.target = '_blank'; - link.style.display ='inline-flex'; - link.style.marginRight ='6px'; - link.style.color = 'white'; - link.style.borderRadius = '2px'; - link.style.fontSize = '15px'; - link.style.textDecoration = 'none'; - link.style.alignItems ='center'; + const linkElement = document.createElement('a'); + linkElement.appendChild(img); + linkElement.href = `${websiteUrl}/repo?repo_name=${repoName}`; + linkElement.target = '_blank'; + + newUI ? linkElement.style.display ='inline-flex' : linkElement.style.display='inline-block' + linkElement.style.marginRight ='2px'; + linkElement.style.color = 'white'; + linkElement.style.borderRadius = '2px'; + linkElement.style.fontSize = '15px'; + linkElement.style.textDecoration = 'none'; + linkElement.style.alignItems ='center'; - link.appendChild(img); - repoLink.parentNode.insertBefore(link, repoLink); + newUI ? repoLink.parentNode.insertBefore(linkElement, repoLink) : repoItem.insertBefore(linkElement, repoItem.firstChild); } }); } From 2991ad977c7395a5fe92ff77c4b6d9bf8bfe07d3 Mon Sep 17 00:00:00 2001 From: Muskan Paliwal Date: Wed, 21 Feb 2024 13:26:07 +0530 Subject: [PATCH 04/14] changed margin right for logo --- scripts/repoHandlers.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/repoHandlers.js b/scripts/repoHandlers.js index 1beff6b..c73a4eb 100644 --- a/scripts/repoHandlers.js +++ b/scripts/repoHandlers.js @@ -119,7 +119,7 @@ function updateTrackedReposInGitHub(trackedRepos, websiteUrl, ownerType) { linkElement.target = '_blank'; newUI ? linkElement.style.display ='inline-flex' : linkElement.style.display='inline-block' - linkElement.style.marginRight ='2px'; + linkElement.style.marginRight ='6px'; linkElement.style.color = 'white'; linkElement.style.borderRadius = '2px'; linkElement.style.fontSize = '15px'; From 16c74f0a8fd7c8dbb8be7caa2682944f539d8f07 Mon Sep 17 00:00:00 2001 From: Muskan Paliwal Date: Wed, 21 Feb 2024 13:27:16 +0530 Subject: [PATCH 05/14] version update --- manifest.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/manifest.json b/manifest.json index 9d18e77..a255b6e 100644 --- a/manifest.json +++ b/manifest.json @@ -1,6 +1,6 @@ { "name": "Vibinex Code Review", - "version": "1.0.6", + "version": "1.1.0", "manifest_version": 3, "description": "Personalization and context for pull requests on GitHub & Bitbucket", "key": "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAsRm6EaBdHDBxVjt9o9WKeL9EDdz1X+knDAU5uoZaRsXTmWjslhJN9DhSd7/Ys4aJOSN+s+5/HnIHcKV63P4GYaUM5FhETHEWORHlwIgjcV/1h6wD6bNbvXi06gtiygE+yMrCzzD93/Z+41XrwMElYiW2U5owNpat2Yfq4p9FDX1uBJUKsRIMp6LbRQla4vAzH/HMUtHWmeuUsmPVzcq1b6uB1QmuJqIQ1GrntIHw3UBWUlqRZ5OtxI1DCP3knglvqz26WT5Pc4GBDNlcI9+3F0vhwqwHqrdyjZpIKZ7iaQzcrovOqUKuXs1J3hDtXq8WoJELIqfIisY7rhAvq6b8jQIDAQAB", From 853ffa6c9a210518794d04b8f5952b6f7e2b9761 Mon Sep 17 00:00:00 2001 From: Muskan Paliwal Date: Wed, 21 Feb 2024 13:30:34 +0530 Subject: [PATCH 06/14] removed logs --- scripts/repoHandlers.js | 3 --- 1 file changed, 3 deletions(-) diff --git a/scripts/repoHandlers.js b/scripts/repoHandlers.js index c73a4eb..96da2ab 100644 --- a/scripts/repoHandlers.js +++ b/scripts/repoHandlers.js @@ -81,12 +81,10 @@ function updateTrackedReposInGitHub(trackedRepos, websiteUrl, ownerType) { if (document.querySelector('[data-testid="list-view-items"]')) { repoList = ownerType === 'org' ? document.querySelectorAll('[data-testid="list-view-items"] > li') : document.querySelectorAll('[data-filterable-for="your-repos-filter"] > li'); newUI = true; - console.log("repos: ", repoList); } else { const allRepo = ownerType === 'org' ? document.getElementById('org-repositories') : document.getElementById('user-repositories-list'); repoList = Array.from(allRepo.querySelectorAll('a[itemprop="name codeRepository"]')); } - console.log("repoList: ", repoList); repoList.forEach(repoItem => { let repoUrl; let repoLink @@ -99,7 +97,6 @@ function updateTrackedReposInGitHub(trackedRepos, websiteUrl, ownerType) { repoUrl = repoItem.getAttribute('href') } const repoName = repoUrl.split('/').pop(); - console.log("repoName: ", repoName); if (trackedRepos.includes(repoName)) { const checkElement = repoItem.querySelector('.trackLogo'); From d2fe565edf3a21dbecb72121e1f8f4a7bcb8e837 Mon Sep 17 00:00:00 2001 From: Muskan Paliwal Date: Wed, 21 Feb 2024 13:41:25 +0530 Subject: [PATCH 07/14] addressed PR comments --- scripts/repoHandlers.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/repoHandlers.js b/scripts/repoHandlers.js index 96da2ab..7929eb2 100644 --- a/scripts/repoHandlers.js +++ b/scripts/repoHandlers.js @@ -115,7 +115,7 @@ function updateTrackedReposInGitHub(trackedRepos, websiteUrl, ownerType) { linkElement.href = `${websiteUrl}/repo?repo_name=${repoName}`; linkElement.target = '_blank'; - newUI ? linkElement.style.display ='inline-flex' : linkElement.style.display='inline-block' + linkElement.style.display = newUI ? 'inline-flex' : 'inline-block'; linkElement.style.marginRight ='6px'; linkElement.style.color = 'white'; linkElement.style.borderRadius = '2px'; From cf09a083d4c08516287019ed2df6563befcd3e6f Mon Sep 17 00:00:00 2001 From: Muskan Paliwal Date: Wed, 21 Feb 2024 13:45:35 +0530 Subject: [PATCH 08/14] removed new lines --- scripts/repoHandlers.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/scripts/repoHandlers.js b/scripts/repoHandlers.js index 7929eb2..72edccb 100644 --- a/scripts/repoHandlers.js +++ b/scripts/repoHandlers.js @@ -71,8 +71,6 @@ function updateTrackedReposInBitbucketOrg(trackedRepos, websiteUrl) { * @param {string} websiteUrl - The URL of the website. * @param {boolean} isOrg - Whether github organization or user. */ - - function updateTrackedReposInGitHub(trackedRepos, websiteUrl, ownerType) { let repoList; let newUI = false; From 512358170f244d29f828f881410d2eda77721461 Mon Sep 17 00:00:00 2001 From: Muskan Paliwal Date: Wed, 21 Feb 2024 13:46:44 +0530 Subject: [PATCH 09/14] removed another log --- scripts/repoHandlers.js | 1 - 1 file changed, 1 deletion(-) diff --git a/scripts/repoHandlers.js b/scripts/repoHandlers.js index 72edccb..00fda9b 100644 --- a/scripts/repoHandlers.js +++ b/scripts/repoHandlers.js @@ -90,7 +90,6 @@ function updateTrackedReposInGitHub(trackedRepos, websiteUrl, ownerType) { repoLink = ownerType == 'org' ? repoItem.querySelector('[data-testid="listitem-title-link"]') : repoItem.querySelector('a[itemprop="name codeRepository"]'); if (!repoLink) return; repoUrl = repoLink.getAttribute('href'); - console.log("repoUrl: ", repoUrl); } else { repoUrl = repoItem.getAttribute('href') } From 603d1b9b9c28d61f736f5779a51f3cbe3475b901 Mon Sep 17 00:00:00 2001 From: Muskan Paliwal Date: Wed, 21 Feb 2024 14:35:04 +0530 Subject: [PATCH 10/14] code modularisation and enhanced code-readability --- scripts/repoHandlers.js | 106 +++++++++++++++++++++++----------------- 1 file changed, 60 insertions(+), 46 deletions(-) diff --git a/scripts/repoHandlers.js b/scripts/repoHandlers.js index 00fda9b..a826df7 100644 --- a/scripts/repoHandlers.js +++ b/scripts/repoHandlers.js @@ -64,6 +64,35 @@ function updateTrackedReposInBitbucketOrg(trackedRepos, websiteUrl) { }); } +/** + * Extracts all the repoUrls elements from github's new ui + * + * @param {String} ownerType - Type of page whether it's an org page or user's page. + * @returns {Array} - The array of repoUrl. + */ +function githubNewUIRepoUrls(ownerType) { + const repoList = ownerType === 'org' ? document.querySelectorAll('[data-testid="list-view-items"] > li') : document.querySelectorAll('[data-filterable-for="your-repos-filter"] > li'); + let repoUrls = []; + repoList.forEach(repoItem => { + let repoLink = ownerType == 'org' ? repoItem.querySelector('[data-testid="listitem-title-link"]') : repoItem.querySelector('a[itemprop="name codeRepository"]'); + if (!repoLink) return; + repoUrls.push(repoLink); + }); + return repoUrls; +} + +/** + * Extracts all the repoUrls elements from github's old ui + * + * @param {String} ownerType - Type of page whether it's an org page or user page. + * @returns {Array} - The array of repoUrl. + */ +function githubOldUIRepoUrls(ownerType) { + const allRepo = ownerType === 'org' ? document.getElementById('org-repositories') : document.getElementById('user-repositories-list'); + const repoUrls = Array.from(allRepo.querySelectorAll('a[itemprop="name codeRepository"]')); + return repoUrls; +} + /** * Updates the GitHub organization or user page to visually indicate which repositories are being tracked. * @@ -72,57 +101,42 @@ function updateTrackedReposInBitbucketOrg(trackedRepos, websiteUrl) { * @param {boolean} isOrg - Whether github organization or user. */ function updateTrackedReposInGitHub(trackedRepos, websiteUrl, ownerType) { - let repoList; - let newUI = false; - - // Check if selectors for new UI exist - if (document.querySelector('[data-testid="list-view-items"]')) { - repoList = ownerType === 'org' ? document.querySelectorAll('[data-testid="list-view-items"] > li') : document.querySelectorAll('[data-filterable-for="your-repos-filter"] > li'); - newUI = true; - } else { - const allRepo = ownerType === 'org' ? document.getElementById('org-repositories') : document.getElementById('user-repositories-list'); - repoList = Array.from(allRepo.querySelectorAll('a[itemprop="name codeRepository"]')); - } - repoList.forEach(repoItem => { - let repoUrl; - let repoLink - if (newUI){ - repoLink = ownerType == 'org' ? repoItem.querySelector('[data-testid="listitem-title-link"]') : repoItem.querySelector('a[itemprop="name codeRepository"]'); - if (!repoLink) return; - repoUrl = repoLink.getAttribute('href'); - } else { - repoUrl = repoItem.getAttribute('href') - } - const repoName = repoUrl.split('/').pop(); + // Check if selectors for new UI exist + const newUI = document.querySelector('[data-testid="list-view-items"]') ? true : false + const repoUrls = newUI ? githubNewUIRepoUrls(ownerType) : githubOldUIRepoUrls(ownerType); + repoUrls.forEach(repoItem => { + const repoLink = repoItem.getAttribute('href'); + const repoName = repoLink.split('/').pop(); - if (trackedRepos.includes(repoName)) { - const checkElement = repoItem.querySelector('.trackLogo'); - if (checkElement) { - checkElement.remove(); - } + if (trackedRepos.includes(repoName)) { + const checkElement = repoItem.querySelector('.trackLogo'); + if (checkElement) { + // TODO: Ideally, we should only need to add the element when there is none present + checkElement.remove(); + } - const img = document.createElement("img"); - img.classList.add('trackLogo'); - img.src = `${websiteUrl}/favicon.ico`; - img.style.width = '15px'; - img.style.height = '15px'; + const img = document.createElement("img"); + img.classList.add('trackLogo'); + img.src = `${websiteUrl}/favicon.ico`; + img.style.width = '15px'; + img.style.height = '15px'; - const linkElement = document.createElement('a'); - linkElement.appendChild(img); - linkElement.href = `${websiteUrl}/repo?repo_name=${repoName}`; - linkElement.target = '_blank'; + const vibinexLogoElement = document.createElement('a'); + vibinexLogoElement.appendChild(img); + vibinexLogoElement.href = `${websiteUrl}/repo?repo_name=${repoName}`; + vibinexLogoElement.target = '_blank'; - linkElement.style.display = newUI ? 'inline-flex' : 'inline-block'; - linkElement.style.marginRight ='6px'; - linkElement.style.color = 'white'; - linkElement.style.borderRadius = '2px'; - linkElement.style.fontSize = '15px'; - linkElement.style.textDecoration = 'none'; - linkElement.style.alignItems ='center'; + vibinexLogoElement.style.display = newUI ? 'inline-flex' : 'inline-block'; + vibinexLogoElement.style.marginRight ='6px'; + vibinexLogoElement.style.color = 'white'; + vibinexLogoElement.style.borderRadius = '2px'; + vibinexLogoElement.style.fontSize = '15px'; + vibinexLogoElement.style.textDecoration = 'none'; + vibinexLogoElement.style.alignItems ='center'; - newUI ? repoLink.parentNode.insertBefore(linkElement, repoLink) : repoItem.insertBefore(linkElement, repoItem.firstChild); - } - }); + newUI ? repoItem.parentNode.insertBefore(vibinexLogoElement, repoItem) : repoItem.insertBefore(vibinexLogoElement, repoItem.firstChild); + } + }); } /** From be4f0499342b73fda4114120c4fbae7c727283c5 Mon Sep 17 00:00:00 2001 From: Muskan Paliwal Date: Wed, 21 Feb 2024 14:36:39 +0530 Subject: [PATCH 11/14] indentation fixes --- scripts/repoHandlers.js | 180 ++++++++++++++++++++-------------------- 1 file changed, 90 insertions(+), 90 deletions(-) diff --git a/scripts/repoHandlers.js b/scripts/repoHandlers.js index a826df7..88df415 100644 --- a/scripts/repoHandlers.js +++ b/scripts/repoHandlers.js @@ -7,24 +7,24 @@ * @returns {Array} - List of tracked repositories. */ async function getTrackedRepos(orgName, userId, repoHost) { - const { websiteUrl } = await chrome.storage.local.get(["websiteUrl"]); - let body = {}; - let url = '' - switch (repoHost) { - case 'github': - body = { org: orgName, userId: userId, provider: 'github' } - url = `${websiteUrl}/api/extension/setup`; - break; - case 'bitbucket': - body = { org: orgName, userId: userId, provider: 'bitbucket' } - url = `${websiteUrl}/api/extension/setup`; - break; - default: - console.warn(`[getTrackedRepos] Invalid repoHost provided: ${repoHost}`); - break; - } - const trackedRepos = await apiCallOnprem(url, body); - return trackedRepos['repos']; + const { websiteUrl } = await chrome.storage.local.get(["websiteUrl"]); + let body = {}; + let url = '' + switch (repoHost) { + case 'github': + body = { org: orgName, userId: userId, provider: 'github' } + url = `${websiteUrl}/api/extension/setup`; + break; + case 'bitbucket': + body = { org: orgName, userId: userId, provider: 'bitbucket' } + url = `${websiteUrl}/api/extension/setup`; + break; + default: + console.warn(`[getTrackedRepos] Invalid repoHost provided: ${repoHost}`); + break; + } + const trackedRepos = await apiCallOnprem(url, body); + return trackedRepos['repos']; } /** @@ -34,34 +34,34 @@ async function getTrackedRepos(orgName, userId, repoHost) { * @param {string} websiteUrl - The URL of the website. */ function updateTrackedReposInBitbucketOrg(trackedRepos, websiteUrl) { - const tbody = document.querySelector('tbody'); - const trs = tbody.querySelectorAll('td'); + const tbody = document.querySelector('tbody'); + const trs = tbody.querySelectorAll('td'); - trs.forEach((item) => { - const text = Array.from(item.getElementsByTagName('a')); - if (text.length >= 2 && trackedRepos.includes(text[1].innerHTML)) { - const img = document.createElement("img"); - img.setAttribute('class', 'trackLogo'); - const beforePsuedoElement = document.createElement('a'); - img.src = `${websiteUrl}/favicon.ico`; - img.style.width = '15px' - img.style.height = '15px' - img.style.marginBottom = '-3px' - img.style.marginRight = '3px' + trs.forEach((item) => { + const text = Array.from(item.getElementsByTagName('a')); + if (text.length >= 2 && trackedRepos.includes(text[1].innerHTML)) { + const img = document.createElement("img"); + img.setAttribute('class', 'trackLogo'); + const beforePsuedoElement = document.createElement('a'); + img.src = `${websiteUrl}/favicon.ico`; + img.style.width = '15px' + img.style.height = '15px' + img.style.marginBottom = '-3px' + img.style.marginRight = '3px' - beforePsuedoElement.appendChild(img); - beforePsuedoElement.href = `${websiteUrl}/repo?repo_name=${text[1].innerHTML}`; - beforePsuedoElement.target = '_blank'; - beforePsuedoElement.style.display = 'inline-block'; - beforePsuedoElement.style.marginRight = '2px'; - beforePsuedoElement.style.color = 'white'; - beforePsuedoElement.style.borderRadius = '2px'; - beforePsuedoElement.style.fontSize = '15px'; - beforePsuedoElement.style.textDecoration = 'none'; - text[1].insertBefore(beforePsuedoElement, text[1].firstChild) - } + beforePsuedoElement.appendChild(img); + beforePsuedoElement.href = `${websiteUrl}/repo?repo_name=${text[1].innerHTML}`; + beforePsuedoElement.target = '_blank'; + beforePsuedoElement.style.display = 'inline-block'; + beforePsuedoElement.style.marginRight = '2px'; + beforePsuedoElement.style.color = 'white'; + beforePsuedoElement.style.borderRadius = '2px'; + beforePsuedoElement.style.fontSize = '15px'; + beforePsuedoElement.style.textDecoration = 'none'; + text[1].insertBefore(beforePsuedoElement, text[1].firstChild) + } - }); + }); } /** @@ -71,14 +71,14 @@ function updateTrackedReposInBitbucketOrg(trackedRepos, websiteUrl) { * @returns {Array} - The array of repoUrl. */ function githubNewUIRepoUrls(ownerType) { - const repoList = ownerType === 'org' ? document.querySelectorAll('[data-testid="list-view-items"] > li') : document.querySelectorAll('[data-filterable-for="your-repos-filter"] > li'); - let repoUrls = []; - repoList.forEach(repoItem => { - let repoLink = ownerType == 'org' ? repoItem.querySelector('[data-testid="listitem-title-link"]') : repoItem.querySelector('a[itemprop="name codeRepository"]'); - if (!repoLink) return; - repoUrls.push(repoLink); - }); - return repoUrls; + const repoList = ownerType === 'org' ? document.querySelectorAll('[data-testid="list-view-items"] > li') : document.querySelectorAll('[data-filterable-for="your-repos-filter"] > li'); + let repoUrls = []; + repoList.forEach(repoItem => { + let repoLink = ownerType == 'org' ? repoItem.querySelector('[data-testid="listitem-title-link"]') : repoItem.querySelector('a[itemprop="name codeRepository"]'); + if (!repoLink) return; + repoUrls.push(repoLink); + }); + return repoUrls; } /** @@ -88,9 +88,9 @@ function githubNewUIRepoUrls(ownerType) { * @returns {Array} - The array of repoUrl. */ function githubOldUIRepoUrls(ownerType) { - const allRepo = ownerType === 'org' ? document.getElementById('org-repositories') : document.getElementById('user-repositories-list'); - const repoUrls = Array.from(allRepo.querySelectorAll('a[itemprop="name codeRepository"]')); - return repoUrls; + const allRepo = ownerType === 'org' ? document.getElementById('org-repositories') : document.getElementById('user-repositories-list'); + const repoUrls = Array.from(allRepo.querySelectorAll('a[itemprop="name codeRepository"]')); + return repoUrls; } /** @@ -101,42 +101,42 @@ function githubOldUIRepoUrls(ownerType) { * @param {boolean} isOrg - Whether github organization or user. */ function updateTrackedReposInGitHub(trackedRepos, websiteUrl, ownerType) { - // Check if selectors for new UI exist - const newUI = document.querySelector('[data-testid="list-view-items"]') ? true : false - const repoUrls = newUI ? githubNewUIRepoUrls(ownerType) : githubOldUIRepoUrls(ownerType); - repoUrls.forEach(repoItem => { - const repoLink = repoItem.getAttribute('href'); - const repoName = repoLink.split('/').pop(); - - if (trackedRepos.includes(repoName)) { - const checkElement = repoItem.querySelector('.trackLogo'); - if (checkElement) { - // TODO: Ideally, we should only need to add the element when there is none present - checkElement.remove(); - } + // Check if selectors for new UI exist + const newUI = document.querySelector('[data-testid="list-view-items"]') ? true : false + const repoUrls = newUI ? githubNewUIRepoUrls(ownerType) : githubOldUIRepoUrls(ownerType); + repoUrls.forEach(repoItem => { + const repoLink = repoItem.getAttribute('href'); + const repoName = repoLink.split('/').pop(); + + if (trackedRepos.includes(repoName)) { + const checkElement = repoItem.querySelector('.trackLogo'); + if (checkElement) { + // TODO: Ideally, we should only need to add the element when there is none present + checkElement.remove(); + } - const img = document.createElement("img"); - img.classList.add('trackLogo'); - img.src = `${websiteUrl}/favicon.ico`; - img.style.width = '15px'; - img.style.height = '15px'; + const img = document.createElement("img"); + img.classList.add('trackLogo'); + img.src = `${websiteUrl}/favicon.ico`; + img.style.width = '15px'; + img.style.height = '15px'; - const vibinexLogoElement = document.createElement('a'); - vibinexLogoElement.appendChild(img); - vibinexLogoElement.href = `${websiteUrl}/repo?repo_name=${repoName}`; - vibinexLogoElement.target = '_blank'; + const vibinexLogoElement = document.createElement('a'); + vibinexLogoElement.appendChild(img); + vibinexLogoElement.href = `${websiteUrl}/repo?repo_name=${repoName}`; + vibinexLogoElement.target = '_blank'; - vibinexLogoElement.style.display = newUI ? 'inline-flex' : 'inline-block'; - vibinexLogoElement.style.marginRight ='6px'; - vibinexLogoElement.style.color = 'white'; - vibinexLogoElement.style.borderRadius = '2px'; - vibinexLogoElement.style.fontSize = '15px'; - vibinexLogoElement.style.textDecoration = 'none'; - vibinexLogoElement.style.alignItems ='center'; + vibinexLogoElement.style.display = newUI ? 'inline-flex' : 'inline-block'; + vibinexLogoElement.style.marginRight ='6px'; + vibinexLogoElement.style.color = 'white'; + vibinexLogoElement.style.borderRadius = '2px'; + vibinexLogoElement.style.fontSize = '15px'; + vibinexLogoElement.style.textDecoration = 'none'; + vibinexLogoElement.style.alignItems ='center'; - newUI ? repoItem.parentNode.insertBefore(vibinexLogoElement, repoItem) : repoItem.insertBefore(vibinexLogoElement, repoItem.firstChild); - } - }); + newUI ? repoItem.parentNode.insertBefore(vibinexLogoElement, repoItem) : repoItem.insertBefore(vibinexLogoElement, repoItem.firstChild); + } + }); } /** @@ -149,8 +149,8 @@ function updateTrackedReposInGitHub(trackedRepos, websiteUrl, ownerType) { * @param {string} repoHost - The hosting platform ('github' or 'bitbucket'). */ async function showFloatingActionButton(orgName, orgRepo, userId, websiteUrl, repoHost) { - const trackedRepoList = await getTrackedRepos(orgName, userId, repoHost); - if (!trackedRepoList.includes(orgRepo)) { - createElement("add", websiteUrl); - } + const trackedRepoList = await getTrackedRepos(orgName, userId, repoHost); + if (!trackedRepoList.includes(orgRepo)) { + createElement("add", websiteUrl); + } } \ No newline at end of file From 1481febb129d802e87bc2fc52b0004a6a275c4a5 Mon Sep 17 00:00:00 2001 From: Muskan Paliwal Date: Wed, 21 Feb 2024 14:37:55 +0530 Subject: [PATCH 12/14] remove the indentation fixes --- scripts/repoHandlers.js | 180 ++++++++++++++++++++-------------------- 1 file changed, 90 insertions(+), 90 deletions(-) diff --git a/scripts/repoHandlers.js b/scripts/repoHandlers.js index 88df415..a826df7 100644 --- a/scripts/repoHandlers.js +++ b/scripts/repoHandlers.js @@ -7,24 +7,24 @@ * @returns {Array} - List of tracked repositories. */ async function getTrackedRepos(orgName, userId, repoHost) { - const { websiteUrl } = await chrome.storage.local.get(["websiteUrl"]); - let body = {}; - let url = '' - switch (repoHost) { - case 'github': - body = { org: orgName, userId: userId, provider: 'github' } - url = `${websiteUrl}/api/extension/setup`; - break; - case 'bitbucket': - body = { org: orgName, userId: userId, provider: 'bitbucket' } - url = `${websiteUrl}/api/extension/setup`; - break; - default: - console.warn(`[getTrackedRepos] Invalid repoHost provided: ${repoHost}`); - break; - } - const trackedRepos = await apiCallOnprem(url, body); - return trackedRepos['repos']; + const { websiteUrl } = await chrome.storage.local.get(["websiteUrl"]); + let body = {}; + let url = '' + switch (repoHost) { + case 'github': + body = { org: orgName, userId: userId, provider: 'github' } + url = `${websiteUrl}/api/extension/setup`; + break; + case 'bitbucket': + body = { org: orgName, userId: userId, provider: 'bitbucket' } + url = `${websiteUrl}/api/extension/setup`; + break; + default: + console.warn(`[getTrackedRepos] Invalid repoHost provided: ${repoHost}`); + break; + } + const trackedRepos = await apiCallOnprem(url, body); + return trackedRepos['repos']; } /** @@ -34,34 +34,34 @@ async function getTrackedRepos(orgName, userId, repoHost) { * @param {string} websiteUrl - The URL of the website. */ function updateTrackedReposInBitbucketOrg(trackedRepos, websiteUrl) { - const tbody = document.querySelector('tbody'); - const trs = tbody.querySelectorAll('td'); + const tbody = document.querySelector('tbody'); + const trs = tbody.querySelectorAll('td'); - trs.forEach((item) => { - const text = Array.from(item.getElementsByTagName('a')); - if (text.length >= 2 && trackedRepos.includes(text[1].innerHTML)) { - const img = document.createElement("img"); - img.setAttribute('class', 'trackLogo'); - const beforePsuedoElement = document.createElement('a'); - img.src = `${websiteUrl}/favicon.ico`; - img.style.width = '15px' - img.style.height = '15px' - img.style.marginBottom = '-3px' - img.style.marginRight = '3px' + trs.forEach((item) => { + const text = Array.from(item.getElementsByTagName('a')); + if (text.length >= 2 && trackedRepos.includes(text[1].innerHTML)) { + const img = document.createElement("img"); + img.setAttribute('class', 'trackLogo'); + const beforePsuedoElement = document.createElement('a'); + img.src = `${websiteUrl}/favicon.ico`; + img.style.width = '15px' + img.style.height = '15px' + img.style.marginBottom = '-3px' + img.style.marginRight = '3px' - beforePsuedoElement.appendChild(img); - beforePsuedoElement.href = `${websiteUrl}/repo?repo_name=${text[1].innerHTML}`; - beforePsuedoElement.target = '_blank'; - beforePsuedoElement.style.display = 'inline-block'; - beforePsuedoElement.style.marginRight = '2px'; - beforePsuedoElement.style.color = 'white'; - beforePsuedoElement.style.borderRadius = '2px'; - beforePsuedoElement.style.fontSize = '15px'; - beforePsuedoElement.style.textDecoration = 'none'; - text[1].insertBefore(beforePsuedoElement, text[1].firstChild) - } + beforePsuedoElement.appendChild(img); + beforePsuedoElement.href = `${websiteUrl}/repo?repo_name=${text[1].innerHTML}`; + beforePsuedoElement.target = '_blank'; + beforePsuedoElement.style.display = 'inline-block'; + beforePsuedoElement.style.marginRight = '2px'; + beforePsuedoElement.style.color = 'white'; + beforePsuedoElement.style.borderRadius = '2px'; + beforePsuedoElement.style.fontSize = '15px'; + beforePsuedoElement.style.textDecoration = 'none'; + text[1].insertBefore(beforePsuedoElement, text[1].firstChild) + } - }); + }); } /** @@ -71,14 +71,14 @@ function updateTrackedReposInBitbucketOrg(trackedRepos, websiteUrl) { * @returns {Array} - The array of repoUrl. */ function githubNewUIRepoUrls(ownerType) { - const repoList = ownerType === 'org' ? document.querySelectorAll('[data-testid="list-view-items"] > li') : document.querySelectorAll('[data-filterable-for="your-repos-filter"] > li'); - let repoUrls = []; - repoList.forEach(repoItem => { - let repoLink = ownerType == 'org' ? repoItem.querySelector('[data-testid="listitem-title-link"]') : repoItem.querySelector('a[itemprop="name codeRepository"]'); - if (!repoLink) return; - repoUrls.push(repoLink); - }); - return repoUrls; + const repoList = ownerType === 'org' ? document.querySelectorAll('[data-testid="list-view-items"] > li') : document.querySelectorAll('[data-filterable-for="your-repos-filter"] > li'); + let repoUrls = []; + repoList.forEach(repoItem => { + let repoLink = ownerType == 'org' ? repoItem.querySelector('[data-testid="listitem-title-link"]') : repoItem.querySelector('a[itemprop="name codeRepository"]'); + if (!repoLink) return; + repoUrls.push(repoLink); + }); + return repoUrls; } /** @@ -88,9 +88,9 @@ function githubNewUIRepoUrls(ownerType) { * @returns {Array} - The array of repoUrl. */ function githubOldUIRepoUrls(ownerType) { - const allRepo = ownerType === 'org' ? document.getElementById('org-repositories') : document.getElementById('user-repositories-list'); - const repoUrls = Array.from(allRepo.querySelectorAll('a[itemprop="name codeRepository"]')); - return repoUrls; + const allRepo = ownerType === 'org' ? document.getElementById('org-repositories') : document.getElementById('user-repositories-list'); + const repoUrls = Array.from(allRepo.querySelectorAll('a[itemprop="name codeRepository"]')); + return repoUrls; } /** @@ -101,42 +101,42 @@ function githubOldUIRepoUrls(ownerType) { * @param {boolean} isOrg - Whether github organization or user. */ function updateTrackedReposInGitHub(trackedRepos, websiteUrl, ownerType) { - // Check if selectors for new UI exist - const newUI = document.querySelector('[data-testid="list-view-items"]') ? true : false - const repoUrls = newUI ? githubNewUIRepoUrls(ownerType) : githubOldUIRepoUrls(ownerType); - repoUrls.forEach(repoItem => { - const repoLink = repoItem.getAttribute('href'); - const repoName = repoLink.split('/').pop(); - - if (trackedRepos.includes(repoName)) { - const checkElement = repoItem.querySelector('.trackLogo'); - if (checkElement) { - // TODO: Ideally, we should only need to add the element when there is none present - checkElement.remove(); - } + // Check if selectors for new UI exist + const newUI = document.querySelector('[data-testid="list-view-items"]') ? true : false + const repoUrls = newUI ? githubNewUIRepoUrls(ownerType) : githubOldUIRepoUrls(ownerType); + repoUrls.forEach(repoItem => { + const repoLink = repoItem.getAttribute('href'); + const repoName = repoLink.split('/').pop(); + + if (trackedRepos.includes(repoName)) { + const checkElement = repoItem.querySelector('.trackLogo'); + if (checkElement) { + // TODO: Ideally, we should only need to add the element when there is none present + checkElement.remove(); + } - const img = document.createElement("img"); - img.classList.add('trackLogo'); - img.src = `${websiteUrl}/favicon.ico`; - img.style.width = '15px'; - img.style.height = '15px'; + const img = document.createElement("img"); + img.classList.add('trackLogo'); + img.src = `${websiteUrl}/favicon.ico`; + img.style.width = '15px'; + img.style.height = '15px'; - const vibinexLogoElement = document.createElement('a'); - vibinexLogoElement.appendChild(img); - vibinexLogoElement.href = `${websiteUrl}/repo?repo_name=${repoName}`; - vibinexLogoElement.target = '_blank'; + const vibinexLogoElement = document.createElement('a'); + vibinexLogoElement.appendChild(img); + vibinexLogoElement.href = `${websiteUrl}/repo?repo_name=${repoName}`; + vibinexLogoElement.target = '_blank'; - vibinexLogoElement.style.display = newUI ? 'inline-flex' : 'inline-block'; - vibinexLogoElement.style.marginRight ='6px'; - vibinexLogoElement.style.color = 'white'; - vibinexLogoElement.style.borderRadius = '2px'; - vibinexLogoElement.style.fontSize = '15px'; - vibinexLogoElement.style.textDecoration = 'none'; - vibinexLogoElement.style.alignItems ='center'; + vibinexLogoElement.style.display = newUI ? 'inline-flex' : 'inline-block'; + vibinexLogoElement.style.marginRight ='6px'; + vibinexLogoElement.style.color = 'white'; + vibinexLogoElement.style.borderRadius = '2px'; + vibinexLogoElement.style.fontSize = '15px'; + vibinexLogoElement.style.textDecoration = 'none'; + vibinexLogoElement.style.alignItems ='center'; - newUI ? repoItem.parentNode.insertBefore(vibinexLogoElement, repoItem) : repoItem.insertBefore(vibinexLogoElement, repoItem.firstChild); - } - }); + newUI ? repoItem.parentNode.insertBefore(vibinexLogoElement, repoItem) : repoItem.insertBefore(vibinexLogoElement, repoItem.firstChild); + } + }); } /** @@ -149,8 +149,8 @@ function updateTrackedReposInGitHub(trackedRepos, websiteUrl, ownerType) { * @param {string} repoHost - The hosting platform ('github' or 'bitbucket'). */ async function showFloatingActionButton(orgName, orgRepo, userId, websiteUrl, repoHost) { - const trackedRepoList = await getTrackedRepos(orgName, userId, repoHost); - if (!trackedRepoList.includes(orgRepo)) { - createElement("add", websiteUrl); - } + const trackedRepoList = await getTrackedRepos(orgName, userId, repoHost); + if (!trackedRepoList.includes(orgRepo)) { + createElement("add", websiteUrl); + } } \ No newline at end of file From 4da69d189ebd375605ede201508c6440b28773f1 Mon Sep 17 00:00:00 2001 From: Muskan Paliwal Date: Thu, 22 Feb 2024 13:08:50 +0530 Subject: [PATCH 13/14] better function names `getRepoTitleElementsFromGithubNewReposUI` --- scripts/repoHandlers.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/scripts/repoHandlers.js b/scripts/repoHandlers.js index a826df7..8369de3 100644 --- a/scripts/repoHandlers.js +++ b/scripts/repoHandlers.js @@ -65,12 +65,12 @@ function updateTrackedReposInBitbucketOrg(trackedRepos, websiteUrl) { } /** - * Extracts all the repoUrls elements from github's new ui + * Extracts all the repo title elements from github's new repo ui * * @param {String} ownerType - Type of page whether it's an org page or user's page. * @returns {Array} - The array of repoUrl. */ -function githubNewUIRepoUrls(ownerType) { +function getRepoTitleElementsFromGithubNewReposUI(ownerType) { const repoList = ownerType === 'org' ? document.querySelectorAll('[data-testid="list-view-items"] > li') : document.querySelectorAll('[data-filterable-for="your-repos-filter"] > li'); let repoUrls = []; repoList.forEach(repoItem => { @@ -82,12 +82,12 @@ function githubNewUIRepoUrls(ownerType) { } /** - * Extracts all the repoUrls elements from github's old ui + * Extracts all the repo title elements from github's old repo ui * * @param {String} ownerType - Type of page whether it's an org page or user page. * @returns {Array} - The array of repoUrl. */ -function githubOldUIRepoUrls(ownerType) { +function getRepoTitleElementsFromGithubOldRepoUl(ownerType) { const allRepo = ownerType === 'org' ? document.getElementById('org-repositories') : document.getElementById('user-repositories-list'); const repoUrls = Array.from(allRepo.querySelectorAll('a[itemprop="name codeRepository"]')); return repoUrls; @@ -103,7 +103,7 @@ function githubOldUIRepoUrls(ownerType) { function updateTrackedReposInGitHub(trackedRepos, websiteUrl, ownerType) { // Check if selectors for new UI exist const newUI = document.querySelector('[data-testid="list-view-items"]') ? true : false - const repoUrls = newUI ? githubNewUIRepoUrls(ownerType) : githubOldUIRepoUrls(ownerType); + const repoUrls = newUI ? getRepoTitleElementsFromGithubNewReposUI(ownerType) : getRepoTitleElementsFromGithubOldRepoUl(ownerType); repoUrls.forEach(repoItem => { const repoLink = repoItem.getAttribute('href'); const repoName = repoLink.split('/').pop(); From 94b5954d00cdec26682c4cf0d559fff0daaa6734 Mon Sep 17 00:00:00 2001 From: Muskan Paliwal Date: Thu, 22 Feb 2024 13:32:20 +0530 Subject: [PATCH 14/14] minor edits --- scripts/repoHandlers.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/scripts/repoHandlers.js b/scripts/repoHandlers.js index 8369de3..811914e 100644 --- a/scripts/repoHandlers.js +++ b/scripts/repoHandlers.js @@ -68,7 +68,7 @@ function updateTrackedReposInBitbucketOrg(trackedRepos, websiteUrl) { * Extracts all the repo title elements from github's new repo ui * * @param {String} ownerType - Type of page whether it's an org page or user's page. - * @returns {Array} - The array of repoUrl. + * @returns {Array} - The array of repo title elements. */ function getRepoTitleElementsFromGithubNewReposUI(ownerType) { const repoList = ownerType === 'org' ? document.querySelectorAll('[data-testid="list-view-items"] > li') : document.querySelectorAll('[data-filterable-for="your-repos-filter"] > li'); @@ -85,7 +85,7 @@ function getRepoTitleElementsFromGithubNewReposUI(ownerType) { * Extracts all the repo title elements from github's old repo ui * * @param {String} ownerType - Type of page whether it's an org page or user page. - * @returns {Array} - The array of repoUrl. + * @returns {Array} - The array of repo title elements. */ function getRepoTitleElementsFromGithubOldRepoUl(ownerType) { const allRepo = ownerType === 'org' ? document.getElementById('org-repositories') : document.getElementById('user-repositories-list'); @@ -127,12 +127,12 @@ function updateTrackedReposInGitHub(trackedRepos, websiteUrl, ownerType) { vibinexLogoElement.target = '_blank'; vibinexLogoElement.style.display = newUI ? 'inline-flex' : 'inline-block'; - vibinexLogoElement.style.marginRight ='6px'; + vibinexLogoElement.style.marginRight = newUI ? '6px' : '2px'; vibinexLogoElement.style.color = 'white'; vibinexLogoElement.style.borderRadius = '2px'; vibinexLogoElement.style.fontSize = '15px'; vibinexLogoElement.style.textDecoration = 'none'; - vibinexLogoElement.style.alignItems ='center'; + vibinexLogoElement.style.alignItems = 'center'; newUI ? repoItem.parentNode.insertBefore(vibinexLogoElement, repoItem) : repoItem.insertBefore(vibinexLogoElement, repoItem.firstChild); }