import { Embed , EmbedAuthor , EmbedField } from '../model/DiscordApi' ; import { TypeParseProvder } from '../provider/BaseProvider' ; /**
 * https://docs.microsoft.com/en-us/vsts/service-hooks/create-subscription
 */ export class VSTS extends TypeParseProvder { private embed : Embed ; constructor ( ) { super ( ) ; this . setEmbedColor ( 0x68217a ) ; this . embed = { } ; } public getName ( ) { return 'VSTS' ; } public getType ( ) { return this . body . eventType ; } public knownTypes ( ) { return [ 'gitPush' , 'tfvcCheckin' , 'gitPullrequestCreated' , 'gitPullrequestMerged' , 'gitPullrequestUpdated' , 'workitemCommented' , 'workitemCreated' , 'workitemDeleted' , 'workitemRestored' , 'workitemUpdated' , 'buildComplete' , 'msVssReleaseReleaseCreatedEvent' , 'msVssReleaseReleaseAbandonedEvent' , 'msVssReleaseDeploymentApprovalCompleted' , 'msVssReleaseDeploymentApprovalPendingEvent' , 'msVssReleaseDeploymentCompletedEvent' , 'msVssReleaseDeplyomentStartedEvent' ] ; } public async gitPush ( ) { const fields = [ ] ; this . body . resource . commits . forEach ( ( commit ) => { fields . push ( { name : 'Commit from ' + this . body . resource . pushedBy . displayName , value : '([`' + commit . commitId . substring ( 0 , 7 ) + '`](' + this . body . resource . repository . remoteUrl + '/commit/' + commit . commitId + ')) ' + commit . comment , inline : false } ) ; } ) ; this . embed . fields = fields ; this . embed . author = { name : this . body . resource . pushedBy . displayName , icon_url : this . body . resource . pushedBy . imageUrl } ; this . addMinimalMessage ( ) ; } public async tfvcCheckin ( ) { this . embed . fields = [ { name : 'Check in from ' + this . body . resource . checkedInBy . displayName , value : '([`' + this . body . resource . changesetId + '`](' + this . body . resource . url + ')) ' + this . body . resource . comment , inline : false } ] ; this . addMinimalMessage ( ) ; } public async gitPullrequestCreated ( ) { this . embed . author = this . extractCreatedByAuthor ( ) ; this . embed . fields = [ { name : 'Pull Request from ' + this . body . resource . createdBy . displayName , value : '([`' + this . body . resource . title + '`](' + this . body . resource . repository . remoteUrl + ')) ' + this . body . resource . description , inline : false } ] ; this . addMinimalMessage ( ) ; } public async gitPullrequestMerged ( ) { this . embed . author = this . extractCreatedByAuthor ( ) ; this . embed . fields = [ { name : 'Pull Request Merge Commit from ' + this . body . resource . createdBy . displayName , value : '([`' + this . body . resource . title + '`](' + this . body . resource . repository . remoteUrl + ')) ' + this . body . resource . description , inline : false } ] ; this . addMinimalMessage ( ) ; } public async gitPullrequestUpdated ( ) { this . embed . author = this . extractCreatedByAuthor ( ) ; this . embed . fields = [ { name : 'Pull Request Updated by ' + this . body . resource . createdBy . displayName , value : '([`' + this . body . resource . title + '`](' + this . body . resource . repository . remoteUrl + ')) ' + this . body . resource . description , inline : false } ] ; this . addMinimalMessage ( ) ; } public async workitemCommented ( ) { this . addMinimalMessage ( ) ; } public async workitemCreated ( ) { this . addMinimalMessage ( ) ; } public async workitemDeleted ( ) { this . addMinimalMessage ( ) ; } public async workitemRestored ( ) { this . addMinimalMessage ( ) ; } public async workitemUpdated ( ) { this . addMinimalMessage ( ) ; } public async buildComplete ( ) { this . addMinimalMessage ( ) ; } public async msVssReleaseReleaseCreatedEvent ( ) { this . addMinimalMessage ( ) ; } public async msVssReleaseReleaseAbandonedEvent ( ) { this . addMinimalMessage ( ) ; } public async msVssReleaseDeploymentApprovalCompleted ( ) { this . addMinimalMessage ( ) ; } public async msVssReleaseDeploymentApprovalPendingEvent ( ) { this . addMinimalMessage ( ) ; } public async msVssReleaseDeploymentCompletedEvent ( ) { this . addMinimalMessage ( ) ; } public async msVssReleaseDeplyomentStartedEvent ( ) { this . addMinimalMessage ( ) ; } private addMinimalMessage ( ) { this . embed . title = this . body . message . markdown as string ; if ( this . embed . title . length > 256 ) { this . embed . title = this . body . resource . title ?? this . body . message . markdown . substring ( 0 , 256 ) ; } this . addEmbed ( this . embed ) ; } private extractCreatedByAuthor ( ) { return { name : this . body . resource . createdBy . displayName , icon_url : this . body . resource . createdBy . imageUrl } ; } }