From 9e1466849bbe86f78ebc37ecc894f139365fe7b3 Mon Sep 17 00:00:00 2001 From: Jan Kuri Date: Sun, 20 Aug 2017 08:51:29 +0200 Subject: [PATCH] feat(tags): show git tag data --- src/api/process-manager.ts | 34 +++++++++++-------- src/api/webhooks.ts | 34 +++++++++++-------- .../app-build-details.component.html | 10 +++--- .../app-build-details.component.ts | 6 ++++ .../app-build-item.component.html | 19 +++++++---- .../app-build-item.component.ts | 5 +++ .../components/app-job/app-job.component.html | 5 +-- .../components/app-job/app-job.component.ts | 6 ++++ 8 files changed, 77 insertions(+), 42 deletions(-) diff --git a/src/api/process-manager.ts b/src/api/process-manager.ts index eed4f4834..3eb2e60fc 100644 --- a/src/api/process-manager.ts +++ b/src/api/process-manager.ts @@ -113,6 +113,7 @@ export function startBuild(data: any): Promise { 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 { }).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 { @@ -200,8 +201,8 @@ export function startJob(buildId: number, jobId: number): Promise { data: 'jobStarted' }); }); - }); - }); + }).catch(err => logger.error(err)); + }).catch(err => logger.error(err)); } export function stopJob(jobId: number): Promise { @@ -239,10 +240,9 @@ export function stopJob(jobId: number): Promise { 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 { @@ -276,8 +276,7 @@ function queueJob(buildId: number, jobId: number, sshAndVnc = false): Promise 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 { }) .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 { } 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 { @@ -447,6 +448,7 @@ export function stopBuild(buildId: number): Promise { .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 { .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 { .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 { } else { return Promise.resolve(); } - }); + }).catch(err => logger.error(err)); } export function startSetup(name: string): Promise { diff --git a/src/api/webhooks.ts b/src/api/webhooks.ts index fc1e17f7e..d57ba68fc 100644 --- a/src/api/webhooks.ts +++ b/src/api/webhooks.ts @@ -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 => { diff --git a/src/app/components/app-build-details/app-build-details.component.html b/src/app/components/app-build-details/app-build-details.component.html index 100d11ced..cef2304bc 100644 --- a/src/app/components/app-build-details/app-build-details.component.html +++ b/src/app/components/app-build-details/app-build-details.component.html @@ -38,8 +38,9 @@


-

{{ build?.data?.pull_request?.title }}

-

{{ build?.data?.commits[0]?.message }}

+

{{ build?.data?.pull_request?.title }}

+

{{ build?.data?.commits[build?.data?.commits.length - 1]?.message }}

+

{{ build?.data?.head_commit?.message }}

@@ -55,8 +56,9 @@

{{ build?.data?.commits[0]?.message }} - {{ build?.data?.sender?.login }} commited {{ timeWords }} ago - {{ build?.data?.commits[0]?.committer?.name }} commited {{ timeWords }} ago + {{ build?.data?.sender?.login }} commited {{ timeWords }} ago + {{ build?.data?.commits[0]?.committer?.name }} commited {{ timeWords }} ago + {{ build?.data?.head_commit?.comitter?.name }} commited {{ timeWords }} ago

diff --git a/src/app/components/app-build-details/app-build-details.component.ts b/src/app/components/app-build-details/app-build-details.component.ts index a64b7df0f..0599b3eeb 100644 --- a/src/app/components/app-build-details/app-build-details.component.ts +++ b/src/app/components/app-build-details/app-build-details.component.ts @@ -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) { diff --git a/src/app/components/app-build-item/app-build-item.component.html b/src/app/components/app-build-item/app-build-item.component.html index 8de3dd80e..1c6e7a242 100644 --- a/src/app/components/app-build-item/app-build-item.component.html +++ b/src/app/components/app-build-item/app-build-item.component.html @@ -1,8 +1,9 @@
- #{{ build?.id }} - PR #{{ build?.pr }} + #{{ build?.id }} + PR #{{ build?.pr }} + {{ tag }}
{{ build?.repository?.full_name }} @@ -11,15 +12,19 @@ - {{ build?.data?.pull_request.head.sha }} + {{ build?.data?.pull_request.head.sha }} {{ build?.data?.after }} - {{ build?.data?.commits[0]?.message }} - {{ build?.data?.pull_request?.title }} + + {{ build?.data?.commits[build?.data?.commits.length - 1]?.message }} + {{ build?.data?.pull_request?.title }} + {{ build?.data?.head_commit?.message }} + {{ build?.timeInWords }} ago
- {{ build?.data?.commits[0]?.committer?.name }} - {{ build?.data?.sender.login }} + {{ build?.data?.commits[0]?.committer?.name }} + {{ build?.data?.sender.login }} + {{ build?.data?.head_commit?.comitter?.name }}
{{ build?.totalTime }} diff --git a/src/app/components/app-build-item/app-build-item.component.ts b/src/app/components/app-build-item/app-build-item.component.ts index a342adea8..fb86a4b32 100644 --- a/src/app/components/app-build-item/app-build-item.component.ts +++ b/src/app/components/app-build-item/app-build-item.component.ts @@ -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); diff --git a/src/app/components/app-job/app-job.component.html b/src/app/components/app-job/app-job.component.html index 473f8645a..dbfe1e864 100644 --- a/src/app/components/app-job/app-job.component.html +++ b/src/app/components/app-job/app-job.component.html @@ -54,8 +54,9 @@


-

{{ job?.build?.data?.pull_request?.title }}

-

{{ job?.build?.data?.commits[0]?.message }}

+

{{ build?.job?.data?.pull_request?.title }}

+

{{ build?.job?.data?.commits[build?.data?.commits.length - 1]?.message }}

+

{{ job?.build?.data?.head_commit?.message }}

diff --git a/src/app/components/app-job/app-job.component.ts b/src/app/components/app-job/app-job.component.ts index 1ff65d82a..45fc52d7e 100644 --- a/src/app/components/app-job/app-job.component.ts +++ b/src/app/components/app-job/app-job.component.ts @@ -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);