Skip to content

Commit

Permalink
Merge pull request #81 from AJAYK-01/main
Browse files Browse the repository at this point in the history
Fixes #68 and fixing Vibinex logo appearing beside Fork Urls in repositories list
  • Loading branch information
avikalpg authored Nov 18, 2023
2 parents 71ba114 + cb43fe5 commit 11fbf4e
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 14 deletions.
11 changes: 8 additions & 3 deletions manifest.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "Vibinex Code Review",
"version": "1.0.3",
"version": "1.0.4",
"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",
Expand Down Expand Up @@ -34,8 +34,13 @@
"scripts/main.css"
],
"js": [
"scripts/utilities.js", "scripts/api.js", "scripts/highlighting.js", "scripts/repoHandlers.js", "scripts/orchestrator.js", "scripts/init.js"
"scripts/utilities.js",
"scripts/api.js",
"scripts/highlighting.js",
"scripts/repoHandlers.js",
"scripts/orchestrator.js",
"scripts/init.js"
]
}
]
}
}
18 changes: 15 additions & 3 deletions scripts/orchestrator.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,12 @@
const orchestrator = async (tabUrl, websiteUrl, userId) => {
console.debug(`[vibinex-orchestrator] updated url: ${tabUrl}`);
const urlObj = tabUrl.split('?')[0].split('/');
const urlEnd = tabUrl.split('?')[1];
// for a possible case like https://github.com/AJAYK-01?tab=repositories&success=true
const searchParams = urlEnd !== undefined ? urlEnd.split('&') : [];

const url = `${websiteUrl}/api/extension/relevant`;

if (!userId && (urlObj[2] === 'github.com' || urlObj[2] === 'bitbucket.org')) {
console.warn(`[Vibinex] You are not logged in. Head to ${websiteUrl} to log in`);
// TODO: create a UI element on the screen with CTA to login to Vibinex
Expand Down Expand Up @@ -64,14 +69,21 @@ const orchestrator = async (tabUrl, websiteUrl, userId) => {
githubHunkHighlight(hunk_info_response);
}
}
// for showing all tracked repo
// for showing all tracked repo in organisation page
else if (
(urlObj[3] && urlObj[4] == undefined) ||
(urlObj[3] && urlObj[4] == undefined && !searchParams.includes('tab=repositories')) ||
(urlObj[3] == 'orgs' && urlObj[4] && urlObj[5] === 'repositories')) {
// for woking on this url https://github.com/Alokit-Innovations or https://github.com/orgs/Alokit-Innovations/repositories?type=all type
const orgName = (urlObj[3] === "orgs") ? urlObj[4] : urlObj[3];
const trackedRepos = await getTrackedRepos(orgName, userId, 'github');
updateTrackedReposInOrgGitHub(trackedRepos, websiteUrl);
updateTrackedReposInGitHub(trackedRepos, websiteUrl, 'org');
}
// for showing all tracked repo in user page
else if (urlObj[3] && !urlObj[4] && searchParams.includes('tab=repositories')) {
// for working on this url https://github.com/username?tab=repositories
const userName = urlObj[3]
const trackedRepos = await getTrackedRepos(userName, userId, 'github');
updateTrackedReposInGitHub(trackedRepos, websiteUrl, 'user')
}
}

Expand Down
18 changes: 10 additions & 8 deletions scripts/repoHandlers.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,20 +65,22 @@ function updateTrackedReposInBitbucketOrg(trackedRepos, websiteUrl) {
}

/**
* Updates the GitHub organization page to visually indicate which repositories are being tracked.
* Updates the GitHub organization or user page to visually indicate which repositories are being tracked.
*
* @param {Array} trackedRepos - List of tracked repositories.
* @param {string} websiteUrl - The URL of the website.
* @param {boolean} isOrg - Whether github organization or user.
*/
function updateTrackedReposInOrgGitHub(trackedRepos, websiteUrl) {
const allOrgRepo = document.getElementById('org-repositories');
const orgRepoUrl = Array.from(allOrgRepo.getElementsByTagName('a'));
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"]'));

orgRepoUrl.forEach((item) => {

repoUrl.forEach((item) => {
const link = item.getAttribute('href').split('/');
const orgRepoName = link[link.length - 1];
const repoName = link[link.length - 1];

if (trackedRepos.includes(orgRepoName)) {
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
Expand All @@ -92,7 +94,7 @@ function updateTrackedReposInOrgGitHub(trackedRepos, websiteUrl) {
img.style.height = '15px'

beforePsuedoElement.appendChild(img);
beforePsuedoElement.href = `${websiteUrl}/repo?repo_name=${orgRepoName}`;
beforePsuedoElement.href = `${websiteUrl}/repo?repo_name=${repoName}`;
beforePsuedoElement.target = '_blank';
beforePsuedoElement.style.display = 'inline-block';
beforePsuedoElement.style.marginRight = '2px';
Expand Down

0 comments on commit 11fbf4e

Please sign in to comment.