Skip to content

Commit

Permalink
fix(best-frontend): Fix Retry for git authorization (#79)
Browse files Browse the repository at this point in the history
  • Loading branch information
diervo authored Feb 9, 2018
1 parent b9c3f71 commit 57b7c21
Show file tree
Hide file tree
Showing 8 changed files with 26 additions and 16 deletions.
3 changes: 2 additions & 1 deletion .eslintignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/packages/*/build/
/packages/*/coverage/
/packages/*/node_modules/
/packages/best-frontend/
/packages/best-frontend/public/
/packages/best-frontend/server/store-mocks
22 changes: 14 additions & 8 deletions packages/best-frontend/server/api_v1.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,34 +115,40 @@ function addRoutes(router, store) {
async function getLatestsCommits(gitRepo, size, retried = false) {
const [owner, repo] = gitRepo.split('/');
try {
console.log('[GIT] getCommits() >> FETCH');
const { data } = await GIT_ORG_API.repos.getCommits({ owner, repo, per_page: size });
return data;
} catch(err) {
console.log('[GIT] getCommits() >> RETRY');
if (err.code === 401 && !retried) {
GIT_ORG_API = await getOrganizationInstallation(GIT_ORG);
return getLatestsCommits(gitRepo, true);
return getLatestsCommits(gitRepo, size, true);
}
console.log('[GIT] getCommits() >> ERROR');
throw err;
}
}

async function getLastCommitStats(store, projectName, branch, size = 30) {
const gitRepo = PROJECTS[projectName];
let gitLastCommits = [];

if (GIT_ORG_API && gitRepo) {
const gitCommits = await getLatestsCommits(gitRepo, size);
gitLastCommits = gitCommits.map(c => c.sha.slice(0, 7));
}

const commits = await store.getCommits(projectName, branch);
const lastCommits = gitLastCommits.length ? gitLastCommits.reverse().filter((i) => commits.indexOf(i) !== -1 ) : commits.slice(0, size);
return gitLastCommits;

// const commits = await store.getCommits(projectName, branch);
// const lastCommits = gitLastCommits.length ? gitLastCommits.reverse().filter((i) => commits.indexOf(i) !== -1 ) : commits.slice(0, size);

const lastCommitBenchmarks = await Promise.all(lastCommits.map(async (commit) => {
let benchmarks = await memoizedGetBenchPerCommit(projectName, commit);
return { commit, benchmarks };
}));
// const lastCommitBenchmarks = await Promise.all(lastCommits.map(async (commit) => {
// let benchmarks = await memoizedGetBenchPerCommit(projectName, commit);
// return { commit, benchmarks };
// }));

return lastCommitBenchmarks;
// return lastCommitBenchmarks;
}

exports.addRoutes = addRoutes;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,6 @@ export default class LightningMenuItem extends Element {
this.classList.add("slds-dropdown__item");
}

get i18n() {
return Labels;
}

get role() {
return this.checked == null ? "menuitem" : "menuitemcheckbox";
}
Expand Down
2 changes: 2 additions & 0 deletions packages/best-frontend/src/modules/one/app/utils.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint no-shadow: ["error", { "allow": ["state"] }] */
function buildSeparator(label) {
return {
label,
Expand Down Expand Up @@ -65,6 +66,7 @@ export function initializeState(state, serverState) {
const { action, stats, projects, branches, selectedProject, selectedBranch} = serverState;
const navItems = projects.map(p => buildNavItem(p));
state.projects = projects;
// eslint-disable-next-line no-return-assign, no-sequences
state.branches = projects.reduce((r, p) => (r[p] = ['master'], r), {});
projects.reduce((state, p) => {
state.branches[p].forEach((b) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ export function normalizeForComparison(benchmarks, finalBenchmarkName) {
let benchName;
const benchmark = {};
while ((benchName = benchNameParts.shift())) {
// eslint-disable-next-line no-loop-func
const benchmarkNode = benchmarks.find(b => b.benchmarkName === benchName || b.name === benchName);

if (benchmarkNode.environment) {
Expand Down
3 changes: 3 additions & 0 deletions packages/best-frontend/src/modules/one/page-project/plots.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/* global Plotly */

let PLOTS = [];

function buildPlottyLayout({ title }) {
Expand Down Expand Up @@ -73,6 +75,7 @@ window.onresize = function() {
if (!debounceResize) {
debounceResize = true;
setTimeout(() => {
// eslint-disable-next-line lwc/no-raf
window.requestAnimationFrame(() => {
PLOTS.forEach((plot) => {
Plotly.Plots.resize(plot);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,8 @@ export function handleKeyDownOnMenuTrigger(event, menuInterface) {
// XXX: This won't work if the menu is lazy loaded and
// takes while to load the items (e.g. if loading from
// the server
// eslint-disable-next-line raptor/no-raf

// eslint-disable-next-line lwc/no-raf
window.requestAnimationFrame(() => {
let focusOnIndex = 0;
if (event.keyCode === keyCodes.up) {
Expand Down Expand Up @@ -160,7 +161,7 @@ export function handleKeyDownOnMenuTrigger(event, menuInterface) {
} else if (!isVisible) {
break;
}
// eslint-disable-next-line raptor/no-raf
// eslint-disable-next-line lwc/no-raf
window.requestAnimationFrame(() => {
moveFocusToTypedCharacters(event, menuInterface);
});
Expand Down
2 changes: 1 addition & 1 deletion packages/best-github-integration/src/git-app.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const APP_CERT = GIT_APP_CERT_PATH ? fs.readFileSync(expandTilde(GIT_APP_CERT_PA
function generateJwt(id, cert) {
const payload = {
iat: Math.floor(new Date() / 1000), // Issued at time
exp: Math.floor(new Date() / 1000) + 60, // JWT expiration time
exp: Math.floor(new Date() / 1000) - 1, // JWT expiration time
iss: id, // Integration's GitHub id
};

Expand Down

0 comments on commit 57b7c21

Please sign in to comment.