import { Logger } from "../utils/logger" ; export class Build { public readonly id : number ; public readonly buildNumber : number ; public readonly isPersonal : boolean ; public readonly status : string ; public readonly name : string ; public readonly statusText : string ; public readonly projectName : string ; public readonly webUrl : string ; public constructor ( id , buildNumber , isPersonal , status , name = "" , statusText = "" , projectName = "" , webUrl = "" ) { this . id = id ; this . buildNumber = buildNumber ; this . isPersonal = isPersonal ; this . status = status ; this . name = name ; this . statusText = statusText ; this . projectName = projectName ; this . webUrl = webUrl ; } public static fromXmlRpcObject ( buildObj ) { const id = this . getXmlRpcId ( buildObj ) ; const buildNumber = this . getXmlRpcNumber ( buildObj ) ; const isPersonal = this . isPersonalXmlRpc ( buildObj ) ; const status = this . getStatusXmlRpc ( buildObj ) ; const name = this . getName ( buildObj ) ; const instance = new Build ( id , buildNumber , isPersonal , status ) ; return instance ; } private static getXmlRpcId ( buildObj ) { if ( ! buildObj || buildObj . id === undefined || buildObj . id [ 0 ] === undefined ) { return - 1 ; } return buildObj . id [ 0 ] ; } private static getXmlRpcNumber ( buildObj ) { if ( ! buildObj || buildObj . number === undefined || buildObj . number [ 0 ] === undefined ) { return - 1 ; } return buildObj . number [ 0 ] ; } private static isPersonalXmlRpc ( buildObj ) { if ( ! buildObj || buildObj . personal === undefined || buildObj . personal [ 0 ] === undefined ) { return false ; } return ( buildObj . personal [ 0 ] === "true" ) ; } private static getStatusXmlRpc ( buildObj ) { if ( ! buildObj || ! buildObj . statusDescriptor || ! buildObj . statusDescriptor [ 0 ] || buildObj . statusDescriptor [ 0 ] . myText === undefined || buildObj . statusDescriptor [ 0 ] . myText [ 0 ] === undefined ) { return "UNKNOWN" ; } return buildObj . statusDescriptor [ 0 ] . myText [ 0 ] ; } private static getProjectName ( buildObj ) { if ( ! buildObj || ! buildObj . build || ! buildObj . build . buildType || ! buildObj . build . buildType [ 0 ] || ! buildObj . build . buildType [ 0 ] . $ ) { Logger . logDebug ( `BuildItemProxy#projectName: projectName is not reachable. default: undefined` ) ; return undefined ; } return buildObj . build . buildType [ 0 ] . $ . projectName ; } public static fromRestParsedObject ( buildObj ) { const id = this . getRestXmlId ( buildObj ) ; const buildNumber = this . getRestXmlNumber ( buildObj ) ; const isPersonal = this . isPersonalRestXml ( buildObj ) ; const status = this . getStatusRestXml ( buildObj ) ; const name = this . getName ( buildObj ) ; const statusText = this . getStatusText ( buildObj ) ; const projectName = this . getProjectName ( buildObj ) ; const webUrl = this . getWebUrl ( buildObj ) ; const instance = new Build ( id , buildNumber , isPersonal , status , name , statusText , projectName , webUrl ) ; return instance ; } private static getRestXmlId ( buildObj ) { if ( ! buildObj || ! buildObj . build || ! buildObj . build . $ || buildObj . build . $ . id === undefined ) { Logger . logDebug ( `BuildItemProxy#changeId: changeId is not reachable. default: -1` ) ; return - 1 ; } return buildObj . build . $ . id ; } private static getRestXmlNumber ( buildObj ) { if ( ! buildObj || ! buildObj . build || ! buildObj . build . $ || buildObj . build . $ . number === undefined ) { Logger . logDebug ( `BuildItemProxy#changeId: changeId is not reachable. default: -1` ) ; return - 1 ; } return buildObj . build . $ . number ; } private static isPersonalRestXml ( buildObj ) { if ( ! buildObj || ! buildObj . build || ! buildObj . build . $ || buildObj . build . $ . personal === undefined ) { Logger . logDebug ( `BuildItemProxy#isPersonal: isPersonal is not reachable. default: false` ) ; return false ; } return ( buildObj . build . $ . personal === "true" ) ; } private static getStatusRestXml ( buildObj ) { if ( ! buildObj || ! buildObj . build || ! buildObj . build . $ || buildObj . build . $ . status === undefined ) { Logger . logDebug ( `BuildItemProxy#status: status is not reachable. default: UNKNOWN` ) ; return "UNKNOWN" ; } return buildObj . build . $ . status ; } private static getName ( buildObj ) { if ( ! buildObj || ! buildObj . build || ! buildObj . build . buildType || ! buildObj . build . buildType [ 0 ] || ! buildObj . build . buildType [ 0 ] . $ ) { return undefined ; } return buildObj . build . buildType [ 0 ] . $ . name ; } private static getWebUrl ( buildObj ) { if ( ! buildObj || ! buildObj . build || ! buildObj . build . $ ) { Logger . logDebug ( `BuildItemProxy#status: status is not reachable. default: undefined` ) ; return undefined ; } return buildObj . build . $ . webUrl ; } private static getStatusText ( buildObj ) { if ( ! buildObj || ! buildObj . build || ! buildObj . build . statusText ) { Logger . logDebug ( `BuildItemProxy#status: status is not reachable. default: empty string` ) ; return "" ; } return buildObj . build . statusText ; } }