@@ -3,8 +3,10 @@ import { Version3Client } from "jira.js";
33import {
44 type ActivityLink ,
55 ActivityType ,
6+ ActivityUpdate ,
67 type NewActivityWithNotes ,
78} from "@plotday/twister" ;
9+ import type { Actor , ActorId , NewContact } from "@plotday/twister/plot" ;
810import type {
911 Project ,
1012 ProjectAuth ,
@@ -90,11 +92,7 @@ export class Jira extends Tool<Jira> implements ProjectTool {
9092 ? R
9193 : [ ]
9294 ) : Promise < ActivityLink > {
93- const jiraScopes = [
94- "read:jira-work" ,
95- "write:jira-work" ,
96- "read:jira-user" ,
97- ] ;
95+ const jiraScopes = [ "read:jira-work" , "write:jira-work" , "read:jira-user" ] ;
9896
9997 // Generate opaque token for authorization
10098 const authToken = crypto . randomUUID ( ) ;
@@ -155,19 +153,13 @@ export class Jira extends Tool<Jira> implements ProjectTool {
155153 * Start syncing issues from a Jira project
156154 */
157155 async startSync <
158- TCallback extends (
159- issue : NewActivityWithNotes ,
160- ...args : any [ ]
161- ) => any
156+ TCallback extends ( issue : NewActivityWithNotes , ...args : any [ ] ) => any
162157 > (
163158 authToken : string ,
164159 projectId : string ,
165160 callback : TCallback ,
166161 options ?: ProjectSyncOptions ,
167- ...extraArgs : TCallback extends (
168- issue : any ,
169- ...rest : infer R
170- ) => any
162+ ...extraArgs : TCallback extends ( issue : any , ...rest : infer R ) => any
171163 ? R
172164 : [ ]
173165 ) : Promise < void > {
@@ -265,6 +257,8 @@ export class Jira extends Tool<Jira> implements ProjectTool {
265257 "description" ,
266258 "status" ,
267259 "assignee" ,
260+ "reporter" ,
261+ "creator" ,
268262 "comment" ,
269263 "created" ,
270264 "updated" ,
@@ -280,10 +274,7 @@ export class Jira extends Tool<Jira> implements ProjectTool {
280274 // Set unread based on sync type (false for initial sync to avoid notification overload)
281275 activityWithNotes . unread = ! state . initialSync ;
282276 // Execute the callback using the callback token
283- await this . tools . callbacks . run (
284- callbackToken ,
285- activityWithNotes
286- ) ;
277+ await this . tools . callbacks . run ( callbackToken , activityWithNotes ) ;
287278 }
288279
289280 // Check if more pages
@@ -294,7 +285,8 @@ export class Jira extends Tool<Jira> implements ProjectTool {
294285 await this . set ( `sync_state_${ projectId } ` , {
295286 startAt : nextStartAt ,
296287 batchNumber : state . batchNumber + 1 ,
297- issuesProcessed : state . issuesProcessed + ( searchResult . issues ?. length || 0 ) ,
288+ issuesProcessed :
289+ state . issuesProcessed + ( searchResult . issues ?. length || 0 ) ,
298290 initialSync : state . initialSync ,
299291 } ) ;
300292
@@ -322,6 +314,38 @@ export class Jira extends Tool<Jira> implements ProjectTool {
322314 const fields = issue . fields || { } ;
323315 const status = fields . status ?. name ;
324316 const comments = fields . comment ?. comments || [ ] ;
317+ const reporter = fields . reporter || fields . creator ;
318+ const assignee = fields . assignee ;
319+
320+ // Create contacts for reporter and assignee
321+ const contacts : NewContact [ ] = [ ] ;
322+ if ( reporter ?. emailAddress ) {
323+ contacts . push ( {
324+ email : reporter . emailAddress ,
325+ name : reporter . displayName ,
326+ avatar : reporter . avatarUrls ?. [ "48x48" ] ,
327+ } ) ;
328+ }
329+ if ( assignee ?. emailAddress && assignee . emailAddress !== reporter ?. emailAddress ) {
330+ contacts . push ( {
331+ email : assignee . emailAddress ,
332+ name : assignee . displayName ,
333+ avatar : assignee . avatarUrls ?. [ "48x48" ] ,
334+ } ) ;
335+ }
336+
337+ let authorActor : Actor | undefined ;
338+ let assigneeActor : Actor | undefined ;
339+
340+ if ( contacts . length > 0 ) {
341+ const actors = await this . tools . plot . addContacts ( contacts ) ;
342+ if ( reporter ?. emailAddress ) {
343+ authorActor = actors . find ( ( a ) => a . email === reporter . emailAddress ) ;
344+ }
345+ if ( assignee ?. emailAddress ) {
346+ assigneeActor = actors . find ( ( a ) => a . email === assignee . emailAddress ) ;
347+ }
348+ }
325349
326350 // Build notes array: description + comments
327351 const notes : Array < { content : string } > = [ ] ;
@@ -352,6 +376,8 @@ export class Jira extends Tool<Jira> implements ProjectTool {
352376 type : ActivityType . Action ,
353377 title : fields . summary || issue . key ,
354378 source : `jira:issue:${ projectId } :${ issue . key } ` ,
379+ author : authorActor ,
380+ assignee : assigneeActor ,
355381 doneAt :
356382 status === "Done" || status === "Closed" || status === "Resolved"
357383 ? new Date ( )
@@ -396,10 +422,7 @@ export class Jira extends Tool<Jira> implements ProjectTool {
396422 * @param authToken - Authorization token
397423 * @param update - ActivityUpdate with changed fields
398424 */
399- async updateIssue (
400- authToken : string ,
401- update : import ( "@plotday/twister" ) . ActivityUpdate
402- ) : Promise < void > {
425+ async updateIssue ( authToken : string , update : ActivityUpdate ) : Promise < void > {
403426 // Extract Jira issue key from source
404427 const issueKey = update . source ?. split ( ":" ) . pop ( ) ;
405428 if ( ! issueKey ) {
0 commit comments