Permalink
Browse files

feat(branches): get config from proper sha

  • Loading branch information...
jkuri committed Sep 10, 2017
1 parent df0884f commit 9e5dc03e8d8d088eaa8f6ee3a173b6b010e5062e
Showing with 28 additions and 2 deletions.
  1. +28 −1 src/api/config.ts
  2. +0 −1 src/api/process-manager.ts
@@ -109,12 +109,14 @@ export function getRemoteParsedConfig(repository: any): Promise<JobsAndEnv[]> {
return new Promise((resolve, reject) => {
let cloneUrl = repository.clone_url;
let branch = repository.branch;
let sha = repository.sha || null;
let pr = repository.pr || null;
let cloneDir = null;
let fileTree: string[];

createGitTmpDir()
.then(dir => cloneDir = dir)
.then(() => spawnGit(['clone', cloneUrl, '-b', branch, '--depth', '1', cloneDir]))
.then(() => checkoutShaOrPr(sha, pr, cloneDir))
.then(() => readGitDir(cloneDir))
.then(files => repository.file_tree = files)
.then(() => {
@@ -709,6 +711,31 @@ function spawnGit(args: string[]): Promise<void> {
});
}

function checkoutShaOrPr(sha: string, pr: number, dir: string): Promise<void> {
return new Promise((resolve, reject) => {
let fetch = null;
let checkout = null;
let gitDir = `--git-dir ${dir}/.git`;

if (pr) {
fetch = `${gitDir} fetch origin pull/${pr}/head:pr${pr}`;
checkout = `${gitDir} checkout pr${pr}`;
} else if (sha) {
fetch = `${gitDir} fetch --unshallow`;
checkout = `${gitDir} checkout ${sha} .`;
}

if (fetch && checkout) {
spawnGit(fetch.split(' '))
.then(() => spawnGit(checkout.split(' '))
.then(() => resolve())
.catch(err => reject(err)));
} else {
resolve();
}
});
}

function readAbstruseConfigFile(dirPath: string): Promise<any> {
return new Promise((resolve, reject) => {
readFile(dirPath + '/.abstruse.yml', (err, contents) => {
@@ -124,7 +124,6 @@ export function startBuild(data: any): Promise<any> {
})
.then(parsedConfig => config = parsedConfig)
.then(() => data.parsed_config = config)
.then(() => data = Object.assign(data, { branch: branch, pr: pr }))
.then(() => insertBuild(data))
.then(build => {
data = Object.assign(data, { build_id: build.id });

0 comments on commit 9e5dc03

Please sign in to comment.