Skip to content

Commit 6108287

Browse files
authored
Merge pull request #8 from GoodRequest/fix-parent-retrieval
TECH-792: Fix parent ticket retrieval
2 parents c3ae0d1 + dcd4cd0 commit 6108287

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

src/Jira.js

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -121,10 +121,22 @@ export default class Jira {
121121
// Add jira tickets to log
122122
const tickets = await Promise.all(promises)
123123

124-
log.tickets = tickets
125-
.flatMap((ticket) => (ticket?.fields?.issuetype?.subtask ? [ticket, ticket.fields.parent] : ticket))
126-
.filter((t) => t && this.includeTicket(t))
124+
// For each subtask ticket, fetch the parent ticket if it already hasn't been
125+
const parentPromises = []
126+
tickets.forEach((ticket) => {
127+
if (ticket?.fields?.issuetype?.subtask) {
128+
const parentKey = ticket?.fields?.parent?.key
129+
if (found[parentKey]) {
130+
return
131+
}
132+
found[parentKey] = true
133+
parentPromises.push(this.fetchJiraTicket(parentKey))
134+
}
135+
})
136+
const parentTickets = await Promise.all(parentPromises)
127137

138+
// Add found jira tickets and their parent tickets to log
139+
log.tickets = tickets.concat(parentTickets).filter((t) => t && this.includeTicket(t))
128140
return log
129141
}
130142

0 commit comments

Comments
 (0)