Skip to content

Commit 807d847

Browse files
need to have seperate field for enterprise token. might want to expand this in the future to allow for an access token for each domain
1 parent b3c196a commit 807d847

File tree

3 files changed

+22
-8
lines changed

3 files changed

+22
-8
lines changed

src/content.js

+10-5
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,9 @@ const getCurrentUser = () => $(".js-menu-target img").attr("alt").slice(1) || ""
88
const isPrivate = () => $(".label-private").length > 0;
99
let statsScope = "repo";
1010

11-
const githubURLBase = window.location.hostname === 'github.com' ? 'api.github.com' : `${window.location.hostname}/api/v3`;
12-
const githubURL = `https://${githubURLBase}`
11+
const isEnterprise = window.location.hostname !== 'github.com';
12+
const githubURLBase = isEnterprise ? `${window.location.hostname}/api/v3` : 'api.github.com';
13+
const githubURL = `https://${githubURLBase}`;
1314

1415
function getContributor() {
1516
let $contributor = $(".timeline-comment-wrapper .timeline-comment-header-text strong a");
@@ -333,11 +334,15 @@ function update({ contributor, repoPath, currentNum, user }) {
333334
if (storageRes.prs || storageRes.issues) {
334335
updateTextNodes(appendPRText(currentNum, storageRes));
335336
} else {
336-
getSyncStorage({ "access_token": null })
337+
const token = isEnterprise ? "enterprise_access_token" : "access_token";
338+
339+
getSyncStorage({ [token]: null })
337340
.then((res) => {
341+
const access_token = isEnterprise ? res.enterprise_access_token : res.access_token;
342+
338343
Promise.all([
339-
contributorCount({ old: storageRes, user, access_token: res.access_token, type: "pr", contributor, repoPath}),
340-
contributorCount({ old: storageRes, user, access_token: res.access_token, type: "issue", contributor, repoPath})
344+
contributorCount({ old: storageRes, user, access_token, type: "pr", contributor, repoPath}),
345+
contributorCount({ old: storageRes, user, access_token, type: "issue", contributor, repoPath})
341346
])
342347
.then(([prInfo, issueInfo]) => {
343348
let repoInfo = Object.assign(prInfo, issueInfo);

src/options.html

+2
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ <h5>Github's Search API Rate Limit</h5>
4242
</p>
4343
<h1>Access Token</h1>
4444
<input type="text" id="token-input" placeholder="Paste your access token here">
45+
<h1>Enterprise Access Token</h1>
46+
<input type="text" id="enterprise-token-input" placeholder="Paste your enterprise access token here">
4547
<p id="feedback"></p>
4648
</section>
4749
<section>

src/options.js

+10-3
Original file line numberDiff line numberDiff line change
@@ -2,28 +2,35 @@
22

33
document.addEventListener("DOMContentLoaded", () => {
44
const accessTokenInput = document.getElementById("token-input");
5+
const enterpriseAccessTokenInput = document.getElementById("enterprise-token-input");
56
const oauthLink = document.getElementById("use-oauth");
67
const clearCacheLink = document.getElementById("clear-cache");
78
const showPrivateReposInput = document.getElementById("show-private-repos");
89

9-
getSyncStorage({ "access_token": null, "_showPrivateRepos": null })
10-
.then(({ access_token, _showPrivateRepos }) => {
10+
getSyncStorage({ "access_token": null, "enterprise_access_token": null, "_showPrivateRepos": null })
11+
.then(({ access_token, enterprise_access_token, _showPrivateRepos }) => {
1112
if (access_token) accessTokenInput.value = access_token;
13+
if (enterprise_access_token) enterpriseAccessTokenInput.value = enterprise_access_token;
1214
if (_showPrivateRepos) showPrivateReposInput.checked = _showPrivateRepos;
1315
});
1416

1517
accessTokenInput.addEventListener("change", () => {
1618
setSyncStorage({ "access_token": accessTokenInput.value });
1719
});
1820

21+
enterpriseAccessTokenInput.addEventListener("change", () => {
22+
setSyncStorage({ "enterprise_access_token": enterpriseAccessTokenInput.value });
23+
});
24+
1925
oauthLink.addEventListener("click", () => {
2026
getTokenFromOauth();
2127
});
2228

2329
clearCacheLink.addEventListener("click", () => {
2430
let temp = accessTokenInput.value;
31+
let temp2 = enterpriseAccessTokenInput.value;
2532
chrome.storage.sync.clear(() => {
26-
setSyncStorage({ "access_token": temp });
33+
setSyncStorage({ "access_token": temp, "enterprise_access_token": temp2 });
2734
document.querySelector("#feedback").textContent = "Storage Cleared";
2835
});
2936
});

0 commit comments

Comments
 (0)