Skip to content

Commit

Permalink
need to have seperate field for enterprise token. might want to expan…
Browse files Browse the repository at this point in the history
…d this in the future to allow for an access token for each domain
  • Loading branch information
hipstersmoothie committed Apr 29, 2018
1 parent b3c196a commit 17926f1
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 8 deletions.
15 changes: 10 additions & 5 deletions src/content.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ const getCurrentUser = () => $(".js-menu-target img").attr("alt").slice(1) || ""
const isPrivate = () => $(".label-private").length > 0;
let statsScope = "repo";

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

function getContributor() {
let $contributor = $(".timeline-comment-wrapper .timeline-comment-header-text strong a");
Expand Down Expand Up @@ -333,11 +334,15 @@ function update({ contributor, repoPath, currentNum, user }) {
if (storageRes.prs || storageRes.issues) {
updateTextNodes(appendPRText(currentNum, storageRes));
} else {
getSyncStorage({ "access_token": null })
const token = isEnterprise ? "enterprise_access_token" : "access_token";
console.log(token)
getSyncStorage({ [token]: null })
.then((res) => {
const access_token = isEnterprise ? res.enterprise_access_token : res.access_token;

Promise.all([
contributorCount({ old: storageRes, user, access_token: res.access_token, type: "pr", contributor, repoPath}),
contributorCount({ old: storageRes, user, access_token: res.access_token, type: "issue", contributor, repoPath})
contributorCount({ old: storageRes, user, access_token, type: "pr", contributor, repoPath}),
contributorCount({ old: storageRes, user, access_token, type: "issue", contributor, repoPath})
])
.then(([prInfo, issueInfo]) => {
let repoInfo = Object.assign(prInfo, issueInfo);
Expand Down
2 changes: 2 additions & 0 deletions src/options.html
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ <h5>Github's Search API Rate Limit</h5>
</p>
<h1>Access Token</h1>
<input type="text" id="token-input" placeholder="Paste your access token here">
<h1>Enterprise Access Token</h1>
<input type="text" id="enterprise-token-input" placeholder="Paste your enterprise access token here">
<p id="feedback"></p>
</section>
<section>
Expand Down
13 changes: 10 additions & 3 deletions src/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,35 @@

document.addEventListener("DOMContentLoaded", () => {
const accessTokenInput = document.getElementById("token-input");
const enterpriseAccessTokenInput = document.getElementById("enterprise-token-input");
const oauthLink = document.getElementById("use-oauth");
const clearCacheLink = document.getElementById("clear-cache");
const showPrivateReposInput = document.getElementById("show-private-repos");

getSyncStorage({ "access_token": null, "_showPrivateRepos": null })
.then(({ access_token, _showPrivateRepos }) => {
getSyncStorage({ "access_token": null, "enterprise_access_token": null, "_showPrivateRepos": null })
.then(({ access_token, enterprise_access_token, _showPrivateRepos }) => {
if (access_token) accessTokenInput.value = access_token;
if (enterprise_access_token) enterpriseAccessTokenInput.value = enterprise_access_token;
if (_showPrivateRepos) showPrivateReposInput.checked = _showPrivateRepos;
});

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

enterpriseAccessTokenInput.addEventListener("change", () => {
setSyncStorage({ "enterprise_access_token": enterpriseAccessTokenInput.value });
});

oauthLink.addEventListener("click", () => {
getTokenFromOauth();
});

clearCacheLink.addEventListener("click", () => {
let temp = accessTokenInput.value;
let temp2 = enterpriseAccessTokenInput.value;
chrome.storage.sync.clear(() => {
setSyncStorage({ "access_token": temp });
setSyncStorage({ "access_token": temp, "enterprise_access_token": temp2 });
document.querySelector("#feedback").textContent = "Storage Cleared";
});
});
Expand Down

0 comments on commit 17926f1

Please sign in to comment.