Skip to content

Commit

Permalink
fix: the old isPublicRepo() fails in the new UI
Browse files Browse the repository at this point in the history
  • Loading branch information
tyn1998 committed Aug 17, 2023
1 parent bcf2c47 commit 1ffe41d
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 14 deletions.
15 changes: 5 additions & 10 deletions src/helpers/get-repo-info.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,11 @@ export function getRepoName() {

// check if the repository is public
export async function isPublicRepo() {
// another selector that also works
// const repoLabel = $('strong[itemprop="name"]').siblings('span.Label.Label--secondary').text();
await elementReady('#repository-container-header');
const repoLabel = $('#repository-container-header')
.find('span.Label.Label--secondary:first')
.text();
return (
pageDetect.isRepo() &&
(repoLabel === 'Public' || repoLabel === 'Public template')
);
const selector = 'meta[name="octolytics-dimension-repository_public"]';
await elementReady(selector);
// <meta name="octolytics-dimension-repository_public" content="true/false">
const isPublic = $(selector).attr('content') === 'true';
return pageDetect.isRepo() && isPublic;
}

export async function isPublicRepoWithMeta() {
Expand Down
5 changes: 3 additions & 2 deletions src/helpers/is-perceptor.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const isPerceptor = (): boolean =>
window.location.search.includes('?redirect=perceptor');
const isPerceptor = (): boolean => {
return window.location.search.includes('?redirect=perceptor');
};

export default isPerceptor;
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ import $ from 'jquery';

import features from '../../../../feature-manager';
import isPerceptor from '../../../../helpers/is-perceptor';
import { getRepoName } from '../../../../helpers/get-repo-info';
import {
getRepoName,
isPublicRepoWithMeta,
} from '../../../../helpers/get-repo-info';
import { getActivityDetails } from '../../../../api/repo';
import View from './view';
import DataNotFound from '../repo-networks/DataNotFound';
Expand Down Expand Up @@ -52,7 +55,7 @@ const restore = async () => {
};

features.add(featureId, {
asLongAs: [isPerceptor],
asLongAs: [isPerceptor, isPublicRepoWithMeta],
awaitDomReady: false,
init,
restore,
Expand Down

0 comments on commit 1ffe41d

Please sign in to comment.