Permalink
Browse files

feat(tags): show git tag data

  • Loading branch information...
jkuri committed Aug 20, 2017
1 parent 496ae9b commit 9e1466849bbe86f78ebc37ecc894f139365fe7b3
@@ -113,6 +113,7 @@ export function startBuild(data: any): Promise<any> {
insertBuildRun(data)
.then(() => {
if (repository.access_token) {
const config: any = getConfig();
const name = data.data.repository.full_name;
const gitUrl = `https://api.github.com/repos/${name}/statuses/${sha}`;
const abstruseUrl = `${config.url}/build/${build.id}`;
@@ -164,10 +165,10 @@ export function startBuild(data: any): Promise<any> {
}).catch(err => logger.error(err));
});
}, Promise.resolve());
});
}).catch(err => logger.error(err));
});
});
});
});
}).catch(err => logger.error(err));
}

export function startJob(buildId: number, jobId: number): Promise<void> {
@@ -200,8 +201,8 @@ export function startJob(buildId: number, jobId: number): Promise<void> {
data: 'jobStarted'
});
});
});
});
}).catch(err => logger.error(err));
}).catch(err => logger.error(err));
}

export function stopJob(jobId: number): Promise<void> {
@@ -239,10 +240,9 @@ export function stopJob(jobId: number): Promise<void> {

processes = processes.filter(proc => proc.job_id !== jobId);
jobProcesses.next(processes);
})
.catch(err => logger.error(err));
}).catch(err => logger.error(err));
}
});
}).catch(err => logger.error(err));
}

function queueJob(buildId: number, jobId: number, sshAndVnc = false): Promise<void> {
@@ -276,8 +276,7 @@ function queueJob(buildId: number, jobId: number, sshAndVnc = false): Promise<vo
processes.push(jobProcess);
jobProcesses.next(processes);
jobEvents.next({ type: 'process', build_id: buildId, job_id: jobId, data: 'jobQueued' });
})
.catch(err => logger.error(err));
}).catch(err => logger.error(err));
}

function prepareJob(buildId: number, jobId: number, cmds: any, sshAndVnc = false):
@@ -326,6 +325,7 @@ function prepareJob(buildId: number, jobId: number, cmds: any, sshAndVnc = false
.then(() => getBuild(buildId))
.then(build => {
if (build.repository.access_token) {
const config: any = getConfig();
const sha = build.data.after || build.data.pull_request.head.sha;
const name = build.data.repository.full_name;
const gitUrl = `https://api.github.com/repos/${name}/statuses/${sha}`;
@@ -358,6 +358,7 @@ function prepareJob(buildId: number, jobId: number, cmds: any, sshAndVnc = false
.then(() => getBuild(buildId))
.then(build => {
if (build.repository.access_token) {
const config: any = getConfig();
const sha = build.data.after || build.data.pull_request.head.sha;
const name = build.data.repository.full_name;
const gitUrl = `https://api.github.com/repos/${name}/statuses/${sha}`;
@@ -384,7 +385,7 @@ function prepareJob(buildId: number, jobId: number, cmds: any, sshAndVnc = false
});
}).catch(err => logger.error(err));
});
});
}).catch(err => logger.error(err));
});
}

@@ -424,6 +425,7 @@ export function restartBuild(buildId: number): Promise<any> {
})
.then(() => {
if (accessToken) {
const config: any = getConfig();
const sha = buildData.data.after;
const name = buildData.data.repository.full_name;
const gitUrl = `https://api.github.com/repos/${name}/statuses/${sha}`;
@@ -432,9 +434,8 @@ export function restartBuild(buildId: number): Promise<any> {
} else {
return Promise.resolve();
}
})
.catch(err => logger.error(err));
});
}).catch(err => logger.error(err));
}).catch(err => logger.error(err));
}

export function stopBuild(buildId: number): Promise<any> {
@@ -447,6 +448,7 @@ export function stopBuild(buildId: number): Promise<any> {
.then(() => getBuild(buildId))
.then(buildData => {
if (buildData.repository.access_token) {
const config: any = getConfig();
const sha = buildData.data.after;
const name = buildData.data.repository.full_name;
const gitUrl = `https://api.github.com/repos/${name}/statuses/${sha}`;
@@ -481,6 +483,7 @@ export function restartJob(jobId: number): Promise<void> {
.then(() => getBuild(jobData.builds_id))
.then(build => {
if (build.repository.access_token) {
const config: any = getConfig();
const sha = build.data.after || build.data.pull_request.head.sha;
const name = build.data.repository.full_name;
const gitUrl = `https://api.github.com/repos/${name}/statuses/${sha}`;
@@ -518,6 +521,7 @@ export function restartJobWithSshAndVnc(jobId: number): Promise<void> {
.then(() => getBuild(jobData.builds_id))
.then(build => {
if (build.repository.access_token) {
const config: any = getConfig();
const sha = build.data.after || build.data.pull_request.head.sha;
const name = build.data.repository.full_name;
const gitUrl = `https://api.github.com/repos/${name}/statuses/${sha}`;
@@ -527,7 +531,7 @@ export function restartJobWithSshAndVnc(jobId: number): Promise<void> {
} else {
return Promise.resolve();
}
});
}).catch(err => logger.error(err));
}

export function startSetup(name: string): Promise<void> {
@@ -5,10 +5,10 @@ import { pingRepository, createPullRequest, synchronizePullRequest } from './db/
import { startBuild } from './process-manager';
import { writeJsonFile } from './fs';

const config: any = getConfig();
export const webhooks = express.Router();

webhooks.post('/github', (req: express.Request, res: express.Response) => {
let config: any = getConfig();
const headers = req.headers;
const payload = req.body;

@@ -32,19 +32,22 @@ webhooks.post('/github', (req: express.Request, res: express.Response) => {
return res.status(400).json({ error: 'X-Hub-Signature does not match blob signature' });
}

// return res.status(200).json({ msg: 'ok' });
if (req.secure) {
config.url = 'https://' + req.headers.host;
} else {
config.url = 'http://' + req.headers.host;
}

switch (ev) {
case 'ping':
let config: any = getConfig();
config.url = req.headers.host;
writeJsonFile(getFilePath('config.json'), config)
.then(() => pingRepository(payload))
.then(repo => res.status(200).json({ msg: 'ok' }))
.catch(err => res.status(400).json(err));
break;
case 'push':
pingRepository(payload)
writeJsonFile(getFilePath('config.json'), config)
.then(() => pingRepository(payload))
.then(repo => {
const buildData = {
data: payload,
@@ -63,20 +66,22 @@ webhooks.post('/github', (req: express.Request, res: express.Response) => {
case 'pull_request':
switch (payload.action) {
case 'opened':
createPullRequest(payload)
.then(build => startBuild(build))
.then(() => res.status(200).json({ msg: 'ok' }))
.catch(err => {
console.error(err);
res.status(400).json({ error: err });
});
writeJsonFile(getFilePath('config.json'), config)
.then(() => createPullRequest(payload))
.then(build => startBuild(build))
.then(() => res.status(200).json({ msg: 'ok' }))
.catch(err => {
console.error(err);
res.status(400).json({ error: err });
});
break;
case 'closed':
// should kill all jobs related to this PR?
res.status(200).json({ msg: 'ok' });
break;
case 'reopened':
synchronizePullRequest(payload)
writeJsonFile(getFilePath('config.json'), config)
.then(() => synchronizePullRequest(payload))
.then(build => startBuild(build))
.then(() => res.status(200).json({ msg: 'ok' }))
.catch(err => {
@@ -106,7 +111,8 @@ webhooks.post('/github', (req: express.Request, res: express.Response) => {
res.status(200).json({ msg: 'ok' });
break;
case 'synchronize':
synchronizePullRequest(payload)
writeJsonFile(getFilePath('config.json'), config)
.then(() => synchronizePullRequest(payload))
.then(build => startBuild(build))
.then(() => res.status(200).json({ msg: 'ok' }))
.catch(err => {
@@ -38,8 +38,9 @@ <h1 class="bold">
<hr/>

<div class="column is-4">
<h2 *ngIf="build?.data?.pull_request">{{ build?.data?.pull_request?.title }}</h2>
<h2 *ngIf="!build?.data?.pull_request">{{ build?.data?.commits[0]?.message }}</h2>
<h2 *ngIf="build?.data?.pull_request && !tag">{{ build?.data?.pull_request?.title }}</h2>
<h2 *ngIf="!build?.data?.pull_request && !tag">{{ build?.data?.commits[build?.data?.commits.length - 1]?.message }}</h2>
<h2 *ngIf="tag">{{ build?.data?.head_commit?.message }}</h2>
</div>
<div class="column is-2">
<p>
@@ -55,8 +56,9 @@ <h2 *ngIf="!build?.data?.pull_request">{{ build?.data?.commits[0]?.message }}</h
<span class="icon">
<img [src]="build?.data?.sender?.avatar_url" class="avatar-img">
</span>
<span *ngIf="build?.data?.pull_request">{{ build?.data?.sender?.login }} commited {{ timeWords }} ago</span>
<span *ngIf="!build?.data?.pull_request">{{ build?.data?.commits[0]?.committer?.name }} commited {{ timeWords }} ago</span>
<span *ngIf="build?.data?.pull_request && !tag">{{ build?.data?.sender?.login }} commited {{ timeWords }} ago</span>
<span *ngIf="!build?.data?.pull_request && !tag">{{ build?.data?.commits[0]?.committer?.name }} commited {{ timeWords }} ago</span>
<span *ngIf="tag">{{ build?.data?.head_commit?.comitter?.name }} commited {{ timeWords }} ago</span>
</p>
</div>
<div class="column is-2">
@@ -18,6 +18,7 @@ export class AppBuildDetailsComponent implements OnInit {
previousRuntime: number;
processingBuild: boolean;
approximatelyRemainingTime: string;
tag: string;

constructor(
private socketService: SocketService,
@@ -37,6 +38,11 @@ export class AppBuildDetailsComponent implements OnInit {
this.apiService.getBuild(this.id).subscribe(build => {
this.loading = false;
this.build = build;

if (this.build.data.ref.startsWith('refs/tags/')) {
this.tag = this.build.data.ref.replace('refs/tags/', '');
}

this.build.jobs.forEach(job => job.time = '00:00');
this.timeWords = distanceInWordsToNow(this.build.start_time);
if (this.build.lastBuild) {
@@ -1,8 +1,9 @@
<div class="columns">
<div class="column is-2">
<img class="avatar-icon" [src]="build?.data?.sender?.avatar_url" *ngIf="build?.data?.sender?.avatar_url">
<span *ngIf="!build?.pr" class="bold larger">#{{ build?.id }}</span>
<span *ngIf="build?.pr" class="bold larger">PR #{{ build?.pr }}</span>
<span *ngIf="!build?.pr && !tag" class="bold larger">#{{ build?.id }}</span>
<span *ngIf="build?.pr && !tag" class="bold larger">PR #{{ build?.pr }}</span>
<span *ngIf="tag" class="bold larger">{{ tag }}</span>
</div>
<div class="column is-2">
<span class="larger">{{ build?.repository?.full_name }}</span>
@@ -11,15 +12,19 @@
<span class="icon">
<img src="images/icons/git-commit.svg">
</span>
<span class="bold" *ngIf="build?.data?.pull_request?.head.sha">{{ build?.data?.pull_request.head.sha }}</span>
<span class="bold" *ngIf="build?.data?.pull_request?.head.sha && !tag">{{ build?.data?.pull_request.head.sha }}</span>
<span class="bold" *ngIf="!build?.data?.pull_request?.head.sha">{{ build?.data?.after }}</span>
<span *ngIf="build?.data?.commits">{{ build?.data?.commits[0]?.message }}</span>
<span *ngIf="!build?.data?.commits">{{ build?.data?.pull_request?.title }}</span>

<span *ngIf="build?.data?.commits && !tag">{{ build?.data?.commits[build?.data?.commits.length - 1]?.message }}</span>
<span *ngIf="!build?.data?.commits && !tag">{{ build?.data?.pull_request?.title }}</span>
<span *ngIf="tag">{{ build?.data?.head_commit?.message }}</span>

<span class="smaller">{{ build?.timeInWords }} ago</span>
</div>
<div class="column is-2">
<span *ngIf="build?.data?.commits">{{ build?.data?.commits[0]?.committer?.name }}</span>
<span *ngIf="!build?.data?.commits">{{ build?.data?.sender.login }}</span>
<span *ngIf="build?.data?.commits && !tag">{{ build?.data?.commits[0]?.committer?.name }}</span>
<span *ngIf="!build?.data?.commits && !tag">{{ build?.data?.sender.login }}</span>
<span *ngIf="tag">{{ build?.data?.head_commit?.comitter?.name }}</span>
</div>
<div class="column is-1">
<span class="build-time">{{ build?.totalTime }}</span>
@@ -10,10 +10,15 @@ export class AppBuildItemComponent {
@HostBinding('class') classes = 'column is-12';

processingRequest: boolean;
tag: string;

constructor(private socketService: SocketService) { }

ngOnInit() {
if (this.build.data.ref.startsWith('refs/tags/')) {
this.tag = this.build.data.ref.replace('refs/tags/', '');
}

this.socketService.outputEvents
.filter(x => x.type === 'buildRestarted' || x.type === 'buildStopped')
.subscribe(e => this.processingRequest = false);
@@ -54,8 +54,9 @@ <h1 class="bold">
<hr/>

<div class="column is-4">
<h2 *ngIf="job?.build?.data?.pull_request">{{ job?.build?.data?.pull_request?.title }}</h2>
<h2 *ngIf="!job?.build?.data?.pull_request">{{ job?.build?.data?.commits[0]?.message }}</h2>
<h2 *ngIf="job?.build?.data?.pull_request && !tag">{{ build?.job?.data?.pull_request?.title }}</h2>
<h2 *ngIf="!job?.build?.data?.pull_request && !tag">{{ build?.job?.data?.commits[build?.data?.commits.length - 1]?.message }}</h2>
<h2 *ngIf="tag">{{ job?.build?.data?.head_commit?.message }}</h2>
</div>
<div class="column is-2">
<p>
@@ -30,6 +30,7 @@ export class AppJobComponent implements OnInit, OnDestroy {
sshd: string;
vnc: string;
expectedProgress: number;
tag: string;

constructor(
private socketService: SocketService,
@@ -89,6 +90,11 @@ export class AppJobComponent implements OnInit, OnDestroy {

this.apiService.getJob(this.id).subscribe(job => {
this.job = job;

if (this.job.build.data.ref.startsWith('refs/tags/')) {
this.tag = this.job.build.data.ref.replace('refs/tags/', '');
}

this.jobRun = job.runs[job.runs.length - 1];
this.terminalInput = this.jobRun.log;
this.timeWords = distanceInWordsToNow(job.build.start_time);

0 comments on commit 9e14668

Please sign in to comment.