Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Link checklist items as children #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 27 additions & 1 deletion packages/import/src/importIssues.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import * as inquirer from "inquirer";
import _, { uniq } from "lodash";
import { Comment, Importer, ImportResult } from "./types";
import { replaceImagesInMarkdown } from "./utils/replaceImages";
import { IssueUpdateInput } from "packages/sdk/dist/_generated_documents";

interface ImportAnswers {
newTeam: boolean;
Expand All @@ -29,6 +30,7 @@ const defaultStateColors = {
*/
export const importIssues = async (apiKey: string, importer: Importer): Promise<void> => {
const client = new LinearClient({ apiKey });

const importData = await importer.import();

const teamsQuery = await client.teams();
Expand Down Expand Up @@ -259,6 +261,7 @@ export const importIssues = async (apiKey: string, importer: Importer): Promise<
}
}

const idMap = {} as { [key: string]: any }
// Create issues
for (const issue of importData.issues) {
const issueDescription = issue.description
Expand Down Expand Up @@ -311,7 +314,7 @@ export const importIssues = async (apiKey: string, importer: Importer): Promise<

const formattedDueDate = issue.dueDate ? format(issue.dueDate, "yyyy-MM-dd") : undefined;

await client.createIssue({
const issueResponse = await client.createIssue({
teamId,
projectId: projectId as unknown as string,
title: issue.title,
Expand All @@ -322,6 +325,29 @@ export const importIssues = async (apiKey: string, importer: Importer): Promise<
assigneeId,
dueDate: formattedDueDate,
});

const newId = (await issueResponse?.issue)?.id
if (issue.originalId) {
idMap[issue.originalId] = newId
}
}

console.info(chalk.green('Starting sub-issue update'))

if (importData.subIssues) {
for (const parentId of Object.keys(importData.subIssues)) {
const childIds = importData.subIssues[parentId]
for (const childId of childIds) {
const newChildId = idMap[childId]
const newParentId = idMap[parentId]
if (newChildId && newParentId) {
const input: IssueUpdateInput = { parentId: newParentId }
await client.updateIssue(newChildId, input)
} else {
console.error(chalk.red(`Couldn't find new IDs for ${childId} or ${parentId}`))
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In case the checklist item links to a card that no longer exists

}
}
}
}

console.info(chalk.green(`${importer.name} issues imported to your team: https://linear.app/team/${teamKey}/all`));
Expand Down
22 changes: 22 additions & 0 deletions packages/import/src/importers/trelloJson/TrelloJsonImporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ type TrelloLabelColor = "green" | "yellow" | "orange" | "red" | "purple" | "blue
interface TrelloCard {
name: string;
desc: string;
url: string;
shortUrl: string;
closed: boolean;
labels: {
Expand Down Expand Up @@ -73,12 +74,30 @@ export class TrelloJsonImporter implements Importer {
labels: {},
users: {},
statuses: {},
subIssues: {}
};

// Map card id => checklist so we can add them to the issues in the next step
const checkLists: { [key: string]: TrelloChecklist } = {};
const trelloCheckLists: { [key: string]: string[] } = {};

const urlsToIds: { [key: string]: string } = {}
data.cards.forEach((card: TrelloCard) => {
urlsToIds[card.url] = card.id
urlsToIds[card.shortUrl] = card.id
})

for (const checklist of data.checklists as TrelloChecklist[]) {
checkLists[checklist.idCard] = checklist;
checklist.checkItems.forEach((item) => {
if (item.name.includes("trello.com")) {
trelloCheckLists[checklist.idCard] ||= []
const cardId: string = urlsToIds[item.name]
if (cardId) {
trelloCheckLists[checklist.idCard].push(cardId)
}
}
})
}

// Map card id => comments so we can add them to the issues in the next step
Expand Down Expand Up @@ -114,6 +133,7 @@ export class TrelloJsonImporter implements Importer {
let formattedChecklist = "";
if (checklist) {
formattedChecklist = checklist.checkItems
.filter((item) => !urlsToIds[item.name])
.sort((item1, item2) => item1.pos - item2.pos)
.map(item => `- [${item.state === "complete" ? "x" : " "}] ${item.name}`)
.join("\n");
Expand Down Expand Up @@ -144,6 +164,7 @@ export class TrelloJsonImporter implements Importer {
url,
labels,
comments: comments[card.id],
originalId: card.id
});

const allLabels = card.labels.map(label => ({
Expand All @@ -158,6 +179,7 @@ export class TrelloJsonImporter implements Importer {
importData.labels[id] = labelData;
}
}
importData.subIssues = trelloCheckLists

return importData;
};
Expand Down
2 changes: 2 additions & 0 deletions packages/import/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export interface Issue {
completedAt?: Date;
/** When the issue was started. */
startedAt?: Date;
originalId?: string;
}

/** Issue comment */
Expand Down Expand Up @@ -64,6 +65,7 @@ export interface ImportResult {
};
/// A suffix to be appended to each resource URL (e.g. to authenticate requests)
resourceURLSuffix?: string;
subIssues?: { [key: string]: string[] };
}

/**
Expand Down
Loading