Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Added a way to retrieve repository names through the page #903

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions src/helpers/get-developer-info.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,20 @@ import $ from 'jquery';
import * as pageDetect from 'github-url-detection';

export function getDeveloperName() {
const developerNameByUrl = getDeveloperNameByUrl();
const developerNameByPage = getDeveloperNameByPage();
if (developerNameByUrl.toLowerCase() === developerNameByPage.toLowerCase()) {
return developerNameByPage;
}
return developerNameByUrl;
}

export function getDeveloperNameByPage() {
return $('.p-nickname.vcard-username.d-block').text().trim().split(' ')[0];
}
export function getDeveloperNameByUrl() {
return pageDetect.utils.getUsername()!;
}

export async function isDeveloperWithMeta() {
return pageDetect.isUserProfile() && (await metaStore.has(getDeveloperName()));
Expand Down
20 changes: 19 additions & 1 deletion src/helpers/get-repo-info.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,24 @@ import * as pageDetect from 'github-url-detection';
import elementReady from 'element-ready';

export function getRepoName() {
const repoNameByUrl = getRepoNameByUrl();
const repoNameByPage = getRepoNameByPage();
if (repoNameByUrl.toLowerCase() === repoNameByPage.toLowerCase()) {
return repoNameByPage;
}
return repoNameByUrl;
}

export function getRepoNameByPage() {
let repoName: string[] = [];
$('header span.AppHeader-context-item-label').map(function () {
repoName.push($(this).text().trim());
});
let repoFullName = repoName[0] + '/' + repoName[1];
return repoFullName;
}

export function getRepoNameByUrl() {
return pageDetect.utils.getRepositoryInfo(window.location)!.nameWithOwner;
}

Expand All @@ -29,5 +47,5 @@ export async function isPublicRepo() {
}

export async function isPublicRepoWithMeta() {
return (await isPublicRepo()) && (await metaStore.has(getRepoName()));
return (await isPublicRepo()) && ((await metaStore.has(getRepoName())) || (await metaStore.has(getRepoNameByPage())));
}
Loading