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(best-frontend): Allow retry for gitIntegration #76

Merged
merged 1 commit into from
Feb 7, 2018
Merged
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
19 changes: 16 additions & 3 deletions packages/best-frontend/server/api_v1.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,13 +112,26 @@ function addRoutes(router, store) {
return router;
}

async function getLatestsCommits(gitRepo, retried = false) {
const [owner, repo] = gitRepo.split('/');
try {
const { data } = await GIT_ORG_API.repos.getCommits({ owner, repo, per_page: size });
return data;
} catch(err) {
if (err.code === 401 && !retried) {
GIT_ORG_API = await getOrganizationInstallation(GIT_ORG);
return getLatestsCommits(gitRepo, true);
}
throw err;
}
}

async function getLastCommitStats(store, projectName, branch, size = 30) {
const gitRepo = PROJECTS[projectName];
let gitLastCommits = [];
if (GIT_ORG_API && gitRepo) {
const [owner, repo] = gitRepo.split('/');
const { data } = await GIT_ORG_API.repos.getCommits({ owner, repo, per_page: size });
gitLastCommits = data.map(c => c.sha.slice(0, 7));
const gitCommits = await getLatestsCommits(gitRepo);
gitLastCommits = gitCommits.map(c => c.sha.slice(0, 7));
}

const commits = await store.getCommits(projectName, branch);
Expand Down