Skip to content

Commit

Permalink
Fix release pagination issue, allow finding parentId when multiple re…
Browse files Browse the repository at this point in the history
…leases exits for an iteration
  • Loading branch information
nverges committed Dec 5, 2024
1 parent 1cbd671 commit 0b755d7
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 61 deletions.
2 changes: 1 addition & 1 deletion src/csv/pivotal/_build_formatted_issue.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ function buildDueDate(row) {
function buildTitle(row) {
if (row["Type"] == "release") {
return row["Iteration"]
? `[${row["Iteration"]}] ${row["Title"]}`
? `[Release ${row["Iteration"]}] ${row["Title"]}`
: row["Title"];
} else {
return row["Title"];
Expand Down
14 changes: 9 additions & 5 deletions src/issues/build_issue_params.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import roundEstimate from "../estimates/rounder.js";
import formatPriority from "../priority/formatter.js";
import extractLabelIds from "../labels/extract_label_ids.js";
import userDistributor from "../users/distributor.js";
import extractParentId from "./extract_parent_id.js";

const formatDate = (date) => (date ? new Date(date).toISOString() : undefined);

Expand All @@ -19,24 +20,27 @@ async function buildIssueParams({
const stateId = teamStatuses.find(
(state) => state.name === `${importSource} - ${issue.state}`,
)?.id;
const labelIds = extractLabelIds(issue, teamLabels, importSource);
const labelIds = extractLabelIds(
issue,
teamLabels,
options.shouldImportLabels,
importSource,
);
const priority = issue.priority ? formatPriority(issue.priority) : undefined;
const estimate = issue.estimate
? roundEstimate(issue.estimate, scale)
: undefined;
const dueDate = formatDate(issue.dueDate);
const createdAt = formatDate(issue.createdAt);
const { assigneeId, subscriberIds } = await userDistributor(issue, team.name);
const parentId = releaseIssues?.find((release) =>
release.title.includes(`[${issue.iteration}]`),
)?.id;
const parentId = extractParentId(issue, releaseIssues);

const issueParams = {
cycleId: null,
teamId: team.id,
title: issue.title,
description: issue.description,
labelIds: options.shouldImportLabels ? labelIds : undefined,
labelIds,
estimate: options.shouldImportEstimates ? estimate : undefined,
priority: options.shouldImportPriority ? priority : undefined,
assigneeId,
Expand Down
22 changes: 22 additions & 0 deletions src/issues/extract_parent_id.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { detailedLogger } from "../../logger/logger_instance.js";

function extractParentId(issue, releaseIssues) {
const matchingReleases =
releaseIssues?.filter((release) => {
return release.title.includes(`[Release ${issue.iteration}]`);
}) || [];

if (matchingReleases.length > 1) {
detailedLogger.warning(
`Multiple release issues found for iteration [Release ${issue.iteration}]. Using first match. Matches: ${matchingReleases
.map((r) => r.title)
.join(", ")}`,
);
}

const parentId = matchingReleases[0]?.id || undefined;

return parentId;
}

export default extractParentId;
68 changes: 27 additions & 41 deletions src/issues/list.mjs
Original file line number Diff line number Diff line change
@@ -1,56 +1,42 @@
import linearClient from "../../config/client.mjs";

async function fetchIssuesForTeam({ teamId, filters }) {
// Construct the filter object
const filter = {};
if (teamId) filter.team = { id: { eq: teamId } };
if (filters) Object.assign(filter, filters);

// Query issues with the constructed filter
const filteredIssues = await linearClient.issues({
filter,
// first: 100
});

let issues = [];

if (filteredIssues.nodes.length) {
filteredIssues.nodes.forEach((issue) => {
// console.log("FULL issue", issue)
const data = {
id: issue.id,
identifier: issue.identifier,
title: issue.title,
createdAt: issue.createdAt,
};
let allIssues = [];
let hasNextPage = true;
let endCursor = null;

issues.push(data);
while (hasNextPage) {
const filteredIssues = await linearClient.issues({
filter,
first: 100,
after: endCursor,
});

return issues;
if (filteredIssues.nodes.length) {
filteredIssues.nodes.forEach((issue) => {
const data = {
id: issue.id,
identifier: issue.identifier,
title: issue.title,
createdAt: issue.createdAt,
};
allIssues.push(data);
});
}

hasNextPage = filteredIssues.pageInfo.hasNextPage;
endCursor = filteredIssues.pageInfo.endCursor;
}

if (allIssues.length) {
return allIssues;
} else {
console.log("No issues found matching the criteria");
}
}

// fetchIssuesForTeam({ teamId: '9d138c4f-fe54-4692-b775-ac6413ecd727', labelId: 'a1940aec-35b4-43a4-b6ad-21c03b2559c2'})
export default fetchIssuesForTeam;

// import linearClient from "../../config/client.mjs";
// import chalk from "chalk";

// async function getMyIssues() {
// const me = await linearClient.viewer;
// console.log(chalk.green("me:", me.displayName));
// console.log(chalk.yellow("Getting my issues..."));
// const myIssues = await me.assignedIssues();

// if (myIssues.nodes.length) {
// myIssues.nodes.map((issue) =>
// console.log(`${issue.identifier} - ${issue.title}`),
// );
// } else {
// console.log(`${me.displayName} has no issues`);
// }
// }

// getMyIssues();
24 changes: 10 additions & 14 deletions src/labels/extract_label_ids.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { detailedLogger } from "../../logger/logger_instance.js";

function extractLabelIds(issue, teamLabels, importSource) {
function extractLabelIds(issue, teamLabels, shouldImportLabels, importSource) {
// Create a Map for O(1) label lookups
const labelMap = new Map(teamLabels.map((label) => [label.name, label.id]));

Expand All @@ -14,22 +14,18 @@ function extractLabelIds(issue, teamLabels, importSource) {
`No label found from 'Type' column for ${issue.type}, ${issue.type.length}`,
);

console.log(
"issue.type.trim()",
issue.type.trim(),
issue.type.trim().length,
);

process.exit(0);
}

// Process other labels more efficiently
const otherLabelIds = issue.labels
? issue.labels.split(",").reduce((ids, label) => {
const id = labelMap.get(label.trim());
if (id) ids.push(id);
return ids;
}, [])
// Process other labels if included options
const otherLabelIds = shouldImportLabels
? issue.labels
? issue.labels.split(",").reduce((ids, label) => {
const id = labelMap.get(label.trim());
if (id) ids.push(id);
return ids;
}, [])
: []
: [];

return [typeColumnLabelId, ...otherLabelIds].filter(Boolean);
Expand Down

0 comments on commit 0b755d7

Please sign in to comment.