@@ -11,6 +11,8 @@ export interface JiraConfig {
1111 email : string ;
1212 apiToken : string ;
1313 projectKey : string ;
14+ forgeCommentUrl ?: string ;
15+ forgeSharedSecret ?: string ;
1416}
1517
1618export class JiraAdapter implements IssueTrackerAdapter {
@@ -39,7 +41,9 @@ export class JiraAdapter implements IssueTrackerAdapter {
3941 if ( res . status === 404 ) {
4042 throw new IssueTrackerNotFoundError ( "Jira resource" , path ) ;
4143 }
42- throw new Error ( `Jira API error: ${ res . status } ${ res . statusText } on ${ path } ` ) ;
44+ throw new Error (
45+ `Jira API error: ${ res . status } ${ res . statusText } on ${ path } ` ,
46+ ) ;
4347 }
4448 if ( res . status === 204 ) return null ;
4549 try {
@@ -69,17 +73,19 @@ export class JiraAdapter implements IssueTrackerAdapter {
6973 ) ,
7074 labels : data . fields . labels ?? [ ] ,
7175 trackerStatus : data . fields . status ?. name ?? "" ,
72- attachments : ( data . fields . attachment ?? [ ] ) . map ( ( a : any ) : TicketAttachment => {
73- const contentUrl =
74- a . content == null ? undefined : String ( a . content ) . trim ( ) ;
75- return {
76- id : String ( a . id ) ,
77- filename : a . filename ?? "" ,
78- mimeType : a . mimeType ?? "application/octet-stream" ,
79- size : sanitizeAttachmentSize ( a . size ) ,
80- contentUrl : contentUrl || undefined ,
81- } ;
82- } ) ,
76+ attachments : ( data . fields . attachment ?? [ ] ) . map (
77+ ( a : any ) : TicketAttachment => {
78+ const contentUrl =
79+ a . content == null ? undefined : String ( a . content ) . trim ( ) ;
80+ return {
81+ id : String ( a . id ) ,
82+ filename : a . filename ?? "" ,
83+ mimeType : a . mimeType ?? "application/octet-stream" ,
84+ size : sanitizeAttachmentSize ( a . size ) ,
85+ contentUrl : contentUrl || undefined ,
86+ } ;
87+ } ,
88+ ) ,
8389 } ;
8490 }
8591
@@ -100,6 +106,9 @@ export class JiraAdapter implements IssueTrackerAdapter {
100106 }
101107
102108 async postComment ( id : string , comment : string ) : Promise < string | null > {
109+ if ( this . config . forgeCommentUrl && this . config . forgeSharedSecret ) {
110+ return this . postCommentViaForge ( id , comment ) ;
111+ }
103112 const data = await this . request ( `/rest/api/3/issue/${ id } /comment` , {
104113 method : "POST" ,
105114 body : JSON . stringify ( {
@@ -115,6 +124,34 @@ export class JiraAdapter implements IssueTrackerAdapter {
115124 return `${ this . baseUrl } /browse/${ encodeURIComponent ( id ) } ?focusedCommentId=${ encodeURIComponent ( commentId ) } ` ;
116125 }
117126
127+ private async postCommentViaForge (
128+ id : string ,
129+ comment : string ,
130+ ) : Promise < string | null > {
131+ const res = await fetch ( this . config . forgeCommentUrl ! , {
132+ method : "POST" ,
133+ headers : {
134+ "Content-Type" : "application/json" ,
135+ "x-shared-secret" : this . config . forgeSharedSecret ! ,
136+ } ,
137+ body : JSON . stringify ( { issueKey : id , body : comment } ) ,
138+ } ) ;
139+ if ( res . status === 404 ) {
140+ throw new IssueTrackerNotFoundError ( "Jira issue" , id ) ;
141+ }
142+ if ( ! res . ok ) {
143+ throw new Error (
144+ `Forge postComment error: ${ res . status } ${ res . statusText } ` ,
145+ ) ;
146+ }
147+ const data = ( await res . json ( ) ) as {
148+ id ?: string | null ;
149+ permalinkPath ?: string | null ;
150+ } ;
151+ if ( ! data ?. id || ! data ?. permalinkPath ) return null ;
152+ return `${ this . baseUrl } /browse/${ encodeURIComponent ( id ) } ${ data . permalinkPath } ` ;
153+ }
154+
118155 async downloadAttachment (
119156 url : string ,
120157 opts : { timeoutMs ?: number } = { } ,
@@ -201,7 +238,9 @@ function extractAdfText(adf: any): string {
201238
202239function extractAcceptanceCriteria ( description : any ) : string {
203240 const text = extractAdfText ( description ) ;
204- const match = text . match ( / a c c e p t a n c e c r i t e r i a [: \s] * ( [ \s \S ] * ?) (?: \n \n | \n # | $ ) / i) ;
241+ const match = text . match (
242+ / a c c e p t a n c e c r i t e r i a [: \s] * ( [ \s \S ] * ?) (?: \n \n | \n # | $ ) / i,
243+ ) ;
205244 return match ?. [ 1 ] ?. trim ( ) ?? "" ;
206245}
207246
0 commit comments