Skip to content

Commit

Permalink
Add use_boards_as_projects logic to sprint and sprint_report streams
Browse files Browse the repository at this point in the history
  • Loading branch information
matiaslcoulougian committed Feb 7, 2025
1 parent 23d14d8 commit 355beb3
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ export class FarosSprintReports extends JiraConverter {
const boardUid = toString(sprintReport.boardId);
const results: DestinationRecord[] = [];
const source = this.initializeSource(ctx);
const projectKey = sprintReport.projectKey;
// If the project key is provided and use_board_ownership enabled, we use it as board uid.
const board =
projectKey && this.useBoardOwnership(ctx)
? {uid: projectKey, source}
: {uid: boardUid, source};
for (const issue of sprintReport.issues || []) {
const status = issue.status
? {
Expand All @@ -34,7 +40,7 @@ export class FarosSprintReports extends JiraConverter {
task: {uid: issue.key, source},
sprint: {uid: sprintUid, source},
},
board: {uid: boardUid, source},
board,
points: issue.points,
plannedPoints: issue.plannedPoints,
classification: {category: issue.classification},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ export class FarosSprints extends JiraConverter {
const sprint = record.record.data;
const source = this.initializeSource(ctx);
const uid = toString(sprint.id);
// If the project key is provided and use_board_ownership enabled, we use it as board uid.
const board =
sprint.projectKey && this.useBoardOwnership(ctx)
? {uid: sprint.projectKey, source}
: {uid: toString(sprint.boardId), source};
return [
{
model: 'tms_Sprint',
Expand All @@ -36,7 +41,7 @@ export class FarosSprints extends JiraConverter {
model: 'tms_SprintBoardRelationship',
record: {
sprint: {uid, source},
board: {uid: toString(sprint.boardId), source},
board,
},
},
];
Expand Down
1 change: 1 addition & 0 deletions faros-airbyte-common/src/jira/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ export interface Sprint extends AgileModels.Sprint {
export interface SprintReport {
readonly sprintId: number;
readonly boardId: string;
readonly projectKey?: string;
readonly completeDate: Date;
readonly issues: SprintIssue[];
}
Expand Down
32 changes: 29 additions & 3 deletions sources/jira-source/src/streams/faros_sprint_reports.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {StreamKey, SyncMode} from 'faros-airbyte-cdk';
import {SprintReport} from 'faros-airbyte-common/jira';
import {Utils} from 'faros-js-client';
import {toString} from 'lodash';
import {Dictionary} from 'ts-essentials';

import {DEFAULT_GRAPH, Jira} from '../jira';
Expand Down Expand Up @@ -34,13 +35,37 @@ export class FarosSprintReports extends StreamWithBoardSlices {
): AsyncGenerator<SprintReport> {
const boardId = streamSlice.board;
const jira = await Jira.instance(this.config, this.logger);
const board = await jira.getBoard(boardId);
if (board.type !== 'scrum') return;
const updateRange =
syncMode === SyncMode.INCREMENTAL
? this.getUpdateRange(streamState[boardId]?.cutoff)
: this.getUpdateRange();

if (this.config.use_projects_as_boards) {
// If the use_projects_as_boards is true, boardId is actually a project key.
const projectKey = boardId;
const boards = await jira.getProjectBoards(projectKey);
for (const board of boards) {
if (board.type !== 'scrum') continue;
yield* this.processBoardSprints(
jira,
toString(board.id),
updateRange,
projectKey
);
}
} else {
const board = await jira.getBoard(boardId);
if (board.type !== 'scrum') return;
yield* this.processBoardSprints(jira, boardId, updateRange);
}
}

private async *processBoardSprints(
jira: Jira,
boardId: string,
updateRange: [Date | undefined, Date | undefined],
projectKey?: string
): AsyncGenerator<SprintReport> {
const sprints =
this.isWebhookSupplementMode() && this.hasFarosClient()
? jira.getSprintsFromFarosGraph(
Expand All @@ -50,10 +75,11 @@ export class FarosSprintReports extends StreamWithBoardSlices {
updateRange?.[0]
)
: jira.getSprints(boardId, updateRange);

for (const sprint of await sprints) {
const report = await jira.getSprintReport(sprint, boardId);
if (!report) continue;
yield report;
yield projectKey ? {...report, projectKey} : report;
}
}

Expand Down
30 changes: 27 additions & 3 deletions sources/jira-source/src/streams/faros_sprints.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,37 @@ export class FarosSprints extends StreamWithBoardSlices {
): AsyncGenerator<Sprint> {
const boardId = streamSlice.board;
const jira = await Jira.instance(this.config, this.logger);

const board = await jira.getBoard(boardId);
if (board.type !== 'scrum') return;
const updateRange =
syncMode === SyncMode.INCREMENTAL
? this.getUpdateRange(streamState[boardId]?.cutoff)
: this.getUpdateRange();

if (this.config.use_projects_as_boards) {
// If the use_projects_as_boards is true, boardId is actually a project key.
const projectKey = boardId;
const boards = await jira.getProjectBoards(projectKey);
for (const board of boards) {
if (board.type !== 'scrum') continue;
yield* this.processBoardSprints(
jira,
toString(board.id),
updateRange,
projectKey
);
}
} else {
const board = await jira.getBoard(boardId);
if (board.type !== 'scrum') return;
yield* this.processBoardSprints(jira, boardId, updateRange);
}
}

private async *processBoardSprints(
jira: Jira,
boardId: string,
updateRange: [Date | undefined, Date | undefined],
projectKey?: string
): AsyncGenerator<Sprint> {
for (const sprint of await jira.getSprints(boardId, updateRange)) {
yield {
id: sprint.id,
Expand All @@ -48,6 +71,7 @@ export class FarosSprints extends StreamWithBoardSlices {
completeDate: sprint.completeDate,
activatedDate: sprint['activatedDate'],
boardId: toInteger(boardId),
...(projectKey ? {projectKey} : {}),
};
}
}
Expand Down

0 comments on commit 355beb3

Please sign in to comment.