import { Application } from 'egg' ; import { AppPluginBase } from '../../basic/AppPluginBase' ; import { JenkinsConfig } from '../../component/ci/config' ; import { join } from 'path' ; const Jenkins = require ( '../../third_party/jenkins/index' ) ; export class AppCIManager extends AppPluginBase < null > { constructor ( config , app ) { super ( config , app ) ; } public async onReady ( ) { } public async onStart ( ) { } public async onClose ( ) { } public async runJenkins ( jobName , pullNum , config ) { try { if ( ! jobName || ! pullNum || ! config || ! config . endpoint || ! config . user || ! config . token ) return ; if ( ! config . endpoint . endsWith ( '/' ) ) config . endpoint = config . endpoint + '/' ; const url = config . endpoint + join ( 'job' , jobName , 'view/change-requests' , 'job' , 'PR-' + pullNum ) ; this . logger . info ( url ) ; const jenkinsCli = new Jenkins ( config . user , config . token , config . endpoint , { timeout : config . timeout } ) ; await jenkinsCli . build ( url ) . then ( res => { this . logger . info ( res . status ) ; } ) . catch ( e => { this . logger . error ( e ) ; } ) ; } catch ( e ) { this . logger . error ( e ) ; } } }