import { Build } from "./build" ; import { Logger } from "../utils/logger" ; import { UserChangeStatus } from "../utils/constants" ; export class Change { public constructor ( public readonly id , public readonly isPersonal , public readonly status , public builds , public readonly myChangesCount , public readonly myDescription , public readonly myVersionControlName , public readonly vcsDate , public readonly displayVersion ) { } public toString ( ) { return `${ this . id }:${ this . status }` ; } public static fromXmlRpcObject ( changeObj ) { const isPersonal = Change . isPersonal ( changeObj ) ; const id = Change . getId ( changeObj ) ; const status = Change . getStatus ( changeObj ) ; const builds = Change . getBuilds ( changeObj ) ; const changesCount = Change . getChangesCount ( changeObj ) ; const description = Change . getDescription ( changeObj ) ; const versionControlName = Change . getVersionControlName ( changeObj ) ; const vcsDate = Change . getVcsDate ( changeObj ) ; const myDisplayVersion = Change . getDisplayVersion ( changeObj ) ; return new Change ( id , isPersonal , status , builds , changesCount , description , versionControlName , vcsDate , myDisplayVersion ) ; } private static isPersonal ( changeObj ) { return changeObj . mod [ 0 ] . personal [ 0 ] === true ; } private static getId ( changeObj ) { return changeObj . mod [ 0 ] . id [ 0 ] ; } private static getStatus ( changeObj ) { const text = changeObj . myStatus [ 0 ] ; switch ( text ) { case "CANCELED" : return UserChangeStatus . CANCELED ; case "CHECKED" : return UserChangeStatus . CHECKED ; case "FAILED" : return UserChangeStatus . FAILED ; case "PENDING" : return UserChangeStatus . PENDING ; case "RUNNING_FAILED" : return UserChangeStatus . RUNNING_FAILED ; case "RUNNING_SUCCESSFULY" : return UserChangeStatus . RUNNING_SUCCESSFULY ; default : return undefined ; } } private static getBuilds ( changeObj ) { if ( ! changeObj || ! changeObj . myTypeToInstanceMap || ! changeObj . myTypeToInstanceMap [ 0 ] || ! changeObj . myTypeToInstanceMap [ 0 ] . entry || ! changeObj . myTypeToInstanceMap [ 0 ] . entry [ 0 ] || ! changeObj . myTypeToInstanceMap [ 0 ] . entry [ 0 ] . Build || ! changeObj . myTypeToInstanceMap [ 0 ] . entry [ 0 ] . Build [ 0 ] || ! changeObj . myTypeToInstanceMap [ 0 ] . entry [ 0 ] . Build [ 0 ] . id ) { return [ ] ; } const builds = [ ] ; changeObj . myTypeToInstanceMap [ 0 ] . entry . forEach ( ( entry ) => { if ( entry && entry . Build && entry . Build [ 0 ] ) { builds . push ( Build . fromXmlRpcObject ( entry . Build [ 0 ] ) ) ; } } ) ; return builds ; } private static getDescription ( changeObj ) { return changeObj . mod [ 0 ] . myDescription [ 0 ] . toString ( ) . trim ( ) ; } private static getVersionControlName ( changeObj ) { return changeObj . mod [ 0 ] . myVersionControlName [ 0 ] ; } private static getChangesCount ( changeObj ) { return changeObj . mod [ 0 ] . myChangesCount [ 0 ] ; } private static getVcsDate ( changeObj ) { return new Date ( + changeObj . mod [ 0 ] . myVcsDate [ 0 ] ) ; } private static getDisplayVersion ( changeObj ) { if ( ! changeObj || ! changeObj . mod || ! changeObj . mod [ 0 ] || ! changeObj . mod [ 0 ] . myDisplayVersion || changeObj . mod [ 0 ] . myDisplayVersion [ 0 ] === undefined ) { Logger . logDebug ( `Change#getDisplayVersion: displayVersion is not reachable. default: empty line` ) ; return "" ; } return changeObj . mod [ 0 ] . myDisplayVersion [ 0 ] ; } }