Skip to content

Commit

Permalink
feat(tags): show git tag data
Browse files Browse the repository at this point in the history
  • Loading branch information
jkuri committed Aug 20, 2017
1 parent 496ae9b commit 9e14668
Show file tree
Hide file tree
Showing 8 changed files with 77 additions and 42 deletions.
34 changes: 19 additions & 15 deletions src/api/process-manager.ts
Expand Up @@ -113,6 +113,7 @@ export function startBuild(data: any): Promise<any> {
insertBuildRun(data) insertBuildRun(data)
.then(() => { .then(() => {
if (repository.access_token) { if (repository.access_token) {
const config: any = getConfig();
const name = data.data.repository.full_name; const name = data.data.repository.full_name;
const gitUrl = `https://api.github.com/repos/${name}/statuses/${sha}`; const gitUrl = `https://api.github.com/repos/${name}/statuses/${sha}`;
const abstruseUrl = `${config.url}/build/${build.id}`; const abstruseUrl = `${config.url}/build/${build.id}`;
Expand Down Expand Up @@ -164,10 +165,10 @@ export function startBuild(data: any): Promise<any> {
}).catch(err => logger.error(err)); }).catch(err => logger.error(err));
}); });
}, Promise.resolve()); }, Promise.resolve());
}); }).catch(err => logger.error(err));
}); });
}); });
}); }).catch(err => logger.error(err));
} }


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


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


processes = processes.filter(proc => proc.job_id !== jobId); processes = processes.filter(proc => proc.job_id !== jobId);
jobProcesses.next(processes); 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> { function queueJob(buildId: number, jobId: number, sshAndVnc = false): Promise<void> {
Expand Down Expand Up @@ -276,8 +276,7 @@ function queueJob(buildId: number, jobId: number, sshAndVnc = false): Promise<vo
processes.push(jobProcess); processes.push(jobProcess);
jobProcesses.next(processes); jobProcesses.next(processes);
jobEvents.next({ type: 'process', build_id: buildId, job_id: jobId, data: 'jobQueued' }); 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): function prepareJob(buildId: number, jobId: number, cmds: any, sshAndVnc = false):
Expand Down Expand Up @@ -326,6 +325,7 @@ function prepareJob(buildId: number, jobId: number, cmds: any, sshAndVnc = false
.then(() => getBuild(buildId)) .then(() => getBuild(buildId))
.then(build => { .then(build => {
if (build.repository.access_token) { if (build.repository.access_token) {
const config: any = getConfig();
const sha = build.data.after || build.data.pull_request.head.sha; const sha = build.data.after || build.data.pull_request.head.sha;
const name = build.data.repository.full_name; const name = build.data.repository.full_name;
const gitUrl = `https://api.github.com/repos/${name}/statuses/${sha}`; const gitUrl = `https://api.github.com/repos/${name}/statuses/${sha}`;
Expand Down Expand Up @@ -358,6 +358,7 @@ function prepareJob(buildId: number, jobId: number, cmds: any, sshAndVnc = false
.then(() => getBuild(buildId)) .then(() => getBuild(buildId))
.then(build => { .then(build => {
if (build.repository.access_token) { if (build.repository.access_token) {
const config: any = getConfig();
const sha = build.data.after || build.data.pull_request.head.sha; const sha = build.data.after || build.data.pull_request.head.sha;
const name = build.data.repository.full_name; const name = build.data.repository.full_name;
const gitUrl = `https://api.github.com/repos/${name}/statuses/${sha}`; const gitUrl = `https://api.github.com/repos/${name}/statuses/${sha}`;
Expand All @@ -384,7 +385,7 @@ function prepareJob(buildId: number, jobId: number, cmds: any, sshAndVnc = false
}); });
}).catch(err => logger.error(err)); }).catch(err => logger.error(err));
}); });
}); }).catch(err => logger.error(err));
}); });
} }


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


export function startSetup(name: string): Promise<void> { export function startSetup(name: string): Promise<void> {
Expand Down
34 changes: 20 additions & 14 deletions src/api/webhooks.ts
Expand Up @@ -5,10 +5,10 @@ import { pingRepository, createPullRequest, synchronizePullRequest } from './db/
import { startBuild } from './process-manager'; import { startBuild } from './process-manager';
import { writeJsonFile } from './fs'; import { writeJsonFile } from './fs';


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


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


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


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


constructor( constructor(
private socketService: SocketService, private socketService: SocketService,
Expand All @@ -37,6 +38,11 @@ export class AppBuildDetailsComponent implements OnInit {
this.apiService.getBuild(this.id).subscribe(build => { this.apiService.getBuild(this.id).subscribe(build => {
this.loading = false; this.loading = false;
this.build = build; 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.build.jobs.forEach(job => job.time = '00:00');
this.timeWords = distanceInWordsToNow(this.build.start_time); this.timeWords = distanceInWordsToNow(this.build.start_time);
if (this.build.lastBuild) { if (this.build.lastBuild) {
Expand Down
19 changes: 12 additions & 7 deletions src/app/components/app-build-item/app-build-item.component.html
@@ -1,8 +1,9 @@
<div class="columns"> <div class="columns">
<div class="column is-2"> <div class="column is-2">
<img class="avatar-icon" [src]="build?.data?.sender?.avatar_url" *ngIf="build?.data?.sender?.avatar_url"> <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 && !tag" 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">PR #{{ build?.pr }}</span>
<span *ngIf="tag" class="bold larger">{{ tag }}</span>
</div> </div>
<div class="column is-2"> <div class="column is-2">
<span class="larger">{{ build?.repository?.full_name }}</span> <span class="larger">{{ build?.repository?.full_name }}</span>
Expand All @@ -11,15 +12,19 @@
<span class="icon"> <span class="icon">
<img src="images/icons/git-commit.svg"> <img src="images/icons/git-commit.svg">
</span> </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 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> <span class="smaller">{{ build?.timeInWords }} ago</span>
</div> </div>
<div class="column is-2"> <div class="column is-2">
<span *ngIf="build?.data?.commits">{{ build?.data?.commits[0]?.committer?.name }}</span> <span *ngIf="build?.data?.commits && !tag">{{ 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?.sender.login }}</span>
<span *ngIf="tag">{{ build?.data?.head_commit?.comitter?.name }}</span>
</div> </div>
<div class="column is-1"> <div class="column is-1">
<span class="build-time">{{ build?.totalTime }}</span> <span class="build-time">{{ build?.totalTime }}</span>
Expand Down
5 changes: 5 additions & 0 deletions src/app/components/app-build-item/app-build-item.component.ts
Expand Up @@ -10,10 +10,15 @@ export class AppBuildItemComponent {
@HostBinding('class') classes = 'column is-12'; @HostBinding('class') classes = 'column is-12';


processingRequest: boolean; processingRequest: boolean;
tag: string;


constructor(private socketService: SocketService) { } constructor(private socketService: SocketService) { }


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

this.socketService.outputEvents this.socketService.outputEvents
.filter(x => x.type === 'buildRestarted' || x.type === 'buildStopped') .filter(x => x.type === 'buildRestarted' || x.type === 'buildStopped')
.subscribe(e => this.processingRequest = false); .subscribe(e => this.processingRequest = false);
Expand Down
5 changes: 3 additions & 2 deletions src/app/components/app-job/app-job.component.html
Expand Up @@ -54,8 +54,9 @@ <h1 class="bold">
<hr/> <hr/>


<div class="column is-4"> <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 && !tag">{{ build?.job?.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?.commits[build?.data?.commits.length - 1]?.message }}</h2>
<h2 *ngIf="tag">{{ job?.build?.data?.head_commit?.message }}</h2>
</div> </div>
<div class="column is-2"> <div class="column is-2">
<p> <p>
Expand Down
6 changes: 6 additions & 0 deletions src/app/components/app-job/app-job.component.ts
Expand Up @@ -30,6 +30,7 @@ export class AppJobComponent implements OnInit, OnDestroy {
sshd: string; sshd: string;
vnc: string; vnc: string;
expectedProgress: number; expectedProgress: number;
tag: string;


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


this.apiService.getJob(this.id).subscribe(job => { this.apiService.getJob(this.id).subscribe(job => {
this.job = 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.jobRun = job.runs[job.runs.length - 1];
this.terminalInput = this.jobRun.log; this.terminalInput = this.jobRun.log;
this.timeWords = distanceInWordsToNow(job.build.start_time); this.timeWords = distanceInWordsToNow(job.build.start_time);
Expand Down

0 comments on commit 9e14668

Please sign in to comment.