@@ -5,7 +5,7 @@ import * as utils from './utils';
55import { resolve } from 'path' ;
66import { Observable } from 'rxjs' ;
77import { exists } from './fs' ;
8- import { getFilePath } from './utils' ;
8+ import { getFilePath , generateBadgeHtml } from './utils' ;
99import { reinitializeDatabase } from './db/migrations' ;
1010import {
1111 usersExists ,
@@ -16,7 +16,13 @@ import {
1616 updateUserPassword ,
1717 getUsers
1818} from './db/user' ;
19- import { addRepository , getRepositories , getRepository , getRepositoryBadge } from './db/repository' ;
19+ import {
20+ addRepository ,
21+ getRepositories ,
22+ getRepository ,
23+ getRepositoryBadge ,
24+ getRepositoryId
25+ } from './db/repository' ;
2026import { getBuilds , getBuild } from './db/build' ;
2127import { getJob } from './db/job' ;
2228import { imageExists } from './docker' ;
@@ -146,64 +152,18 @@ export function badgeRoutes(): express.Router {
146152
147153 router . get ( '/:id' , ( req : express . Request , res : express . Response ) => {
148154 getRepositoryBadge ( req . params . id ) . then ( status => {
149- let background = null ;
150- if ( status === 'failing' ) {
151- background = '#f03e3e' ;
152- } else if ( status === 'running' ) {
153- background = '#ffd43b' ;
154- } else if ( status === 'queued' ) {
155- background = '#ffd43b' ;
156- } else {
157- background = '#39B54A' ;
158- }
159-
160- let html = `
161- <svg xmlns="http://www.w3.org/2000/svg" width="97" height="20" style="shape-rendering:
162- geometricPrecision; image-rendering:optimizeQuality; fill-rule:evenodd;
163- clip-rule:evenodd">
164- <linearGradient id="b" x2="0" y2="100%">
165- <stop offset="0" stop-color="#bbb" stop-opacity=".1"/>
166- <stop offset="1" stop-opacity=".1"/>
167- </linearGradient>
168- <mask id="a">
169- <rect width="97" height="20" rx="3" fill="#fff"/>
170- </mask>
171- <g mask="url(#a)">
172- <path fill="#333" d="M0 0h53v20H0z"/>
173- <path fill="` + background + `" d="M53 0h75v20H53z"/>
174- <path fill="url(#b)" d="M0 0h97v20H0z"/>
175- </g>
176- <g transform="matrix(0.27,0,0,0.27,3,2.7)">
177- <circle fill-rule="evenodd" clip-rule="evenodd" fill="none" stroke="#FFFFFF"
178- stroke-width="3px" stroke-linecap="round" stroke-linejoin="round"
179- stroke-miterlimit="10" cx="27" cy="27" r="26"/>
180- <path fill-rule="evenodd" clip-rule="evenodd" fill="#FFFFFF"
181- d="M24.83,25.84c0.01,1.54,0.01,3.08,0.01,4.63
182- c0.02,0.96,0.18,1.99,0.79,2.76c0.69,0.88,1.83,1.27,2.9,1.35c1.16,0.06,
183- 2.4,0.07,3.44-0.53c1-0.57,1.53-1.7,
184- 1.66-2.81c0.19-1.26,0.12-2.62-0.57-3.73c-0.69-1.1-2.03-1.66-3.28-1.67H24.83z
185- M19.18,11.57c1.1-1.1,2.99-1.24,4.25-0.33c0.88,0.6,
186- 1.48,1.65,1.41,2.73v4.65c-0.01,0.19,0,0.53,0.1,0.53c1.74-0.01,3.48,0,
187- 5.21-0.01c2.04-0.06,4.11,0.5,5.85,1.57c1.48,0.92,2.69,2.28,3.41,3.88c0.79,
188- 1.71,1.04,3.61,1.01,5.49c0,2.09-0.32,4.24-1.3,6.12c-0.82,
189- 1.65-2.19,3.01-3.84,3.84c-1.78,0.92-3.78,1.29-5.77,
190- 1.36c-2.3-0.04-4.68-0.41-6.66-1.67c-1.92-1.19-3.2-3.18-3.85-5.29c-0.77-2.47-0.85-5.08-0.85-7.64
191- c-0.02-0.32,0.12-0.66-0.02-0.98c-0.75-0.04-1.5,
192- 0.07-2.22-0.11c-1.04-0.27-1.93-1.1-2.29-2.12c-0.32-0.89-0.24-1.92,0.21-2.75
193- c0.46-0.82,1.25-1.45,2.16-1.67c0.7-0.06,1.41-0.01,2.1-0.02c-0.01-1.6,
194- 0-3.2-0.01-4.81C18.09,13.33,18.42,12.27,19.18,11.57z"/>
195- </g>
196- <g fill="#fff" font-family="DejaVu Sans,Verdana,Geneva,sans-serif" font-size="9">
197- <text x="22" y="15" fill="#010101" fill-opacity=".3">build</text>
198- <text x="22" y="14">build</text>
199- <text x="58" y="15" fill="#010101" fill-opacity=".3">` + status + `</text>
200- <text x="58" y="14">` + status + `</text>
201- </g>
202- </svg>
203- ` ;
155+ res . writeHead ( 200 , { 'Content-Type' : 'image/svg+xml' } ) ;
156+ res . write ( generateBadgeHtml ( status ) ) ;
157+ res . end ( ) ;
158+ } ) ;
159+ } ) ;
204160
161+ router . get ( '/:owner/:repository' , ( req : express . Request , res : express . Response ) => {
162+ getRepositoryId ( req . params . owner , req . params . repository )
163+ . then ( id => getRepositoryBadge ( id ) )
164+ . then ( status => {
205165 res . writeHead ( 200 , { 'Content-Type' : 'image/svg+xml' } ) ;
206- res . write ( html ) ;
166+ res . write ( generateBadgeHtml ( status ) ) ;
207167 res . end ( ) ;
208168 } ) ;
209169 } ) ;
0 commit comments