Skip to content

Commit

Permalink
Revived the github issues migration script
Browse files Browse the repository at this point in the history
  • Loading branch information
Fgerthoffert committed Oct 1, 2024
1 parent 47d8d46 commit 5e1a4e8
Show file tree
Hide file tree
Showing 19 changed files with 993 additions and 620 deletions.
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,12 @@
"fs-extra": "^8.1.0",
"graphql": "^14.5.8",
"graphql-tag": "^2.10.1",
"jira2md": "^2.0.4",
"jira2md": "^3.0.1",
"js-yaml": "^3.13.1",
"load-yaml-file": "^0.2.0",
"lodash": "^4.17.15",
"node-fetch": "^2.6.0",
"nodejs-file-downloader": "^4.13.0",
"p-map": "^4.0.0",
"tslib": "^1.11.1",
"uuid": "^8.3.1",
Expand Down Expand Up @@ -100,7 +101,7 @@
"postpack": "rm -f oclif.manifest.json",
"prepack": "rm -rf lib && tsc -b && oclif-dev readme",
"test": "nyc --extension .ts mocha --forbid-only \"test/**/*.test.ts\"",
"lint": "eslint . --ext .js,.ts --fix"
"lint": "eslint . --ext .js,.ts --fix"
},
"types": "lib/index.d.ts",
"bit": {
Expand Down
5 changes: 3 additions & 2 deletions src/commands/github/import.ts
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ export default class Import extends Command {

const failedLabels: string[] = [];
for (const importStatus of response.data) {
const importIssue = issues.find(i => i.status.id === importStatus.id);
const importIssue = issues.filter(i => i.status !== undefined && i.status !== null).find(i => i.status.id === importStatus.id);
if (importIssue !== undefined) {
const updateIssue = {
...importIssue,
Expand All @@ -226,6 +226,7 @@ export default class Import extends Command {
});
if (importStatus.status === 'failed') {
for (const error of importStatus.errors) {
this.log('Unable to import issue: ' + importIssue.source.key + ' Error: ' + JSON.stringify(error));
if (error.resource === 'Label') {
if (!failedLabels.includes(error.value)) {
failedLabels.push(error.value);
Expand Down Expand Up @@ -263,7 +264,7 @@ export default class Import extends Command {
);
this.log('Found: ' + missingIssues.length + ' issues missing');
this.log(
'Fetching errors for first 10 missing issues (problems are often similar between issues',
'Fetching errors for first 10 missing issues (problems are often similar between issues)',
);
for (const mi of missingIssues.slice(0, 10)) {
cli.action.start('Fetching status for missing issue: ' + mi.source.key);
Expand Down
90 changes: 54 additions & 36 deletions src/commands/jira/ghexport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,14 @@ import getComments from '../../utils/import/getComments';
import getAssignee from '../../utils/import/getAssignee';
import getReporter from '../../utils/import/getReporter';
import getLabels from '../../utils/import/getLabels';
import cleanJiraContent from '../../utils/import/cleanJiraContent';


import { esMapping, esSettings } from '../../components/githubImport';

import { checkEsIndex, pushEsNodes } from '../../components/esUtils/index';

import { ImportConfig } from '../../utils/import/importConfig.type';
import { ImportConfig, JiraUser } from '../../utils/import/importConfig.type';

//https://gist.github.com/jonmagic/5282384165e0f86ef105
export default class Issues extends Command {
Expand Down Expand Up @@ -65,37 +67,36 @@ export default class Issues extends Command {
'Verifying that all users (creator, reporter, assignee) are present in import config',
);

const userUniqueEmails: string[] = [];
const uniqueJiraUsers: JiraUser[] = [];
for (const i of issues.filter(i => i.key !== undefined)) {
// Reporter
if (i.reporter !== undefined && i.reporter !== null) {
if (!userUniqueEmails.includes(i.reporter.emailAddress)) {
userUniqueEmails.push(i.reporter.emailAddress);
}
}
if (i.creator !== undefined && i.creator !== null) {
if (!userUniqueEmails.includes(i.creator.emailAddress)) {
userUniqueEmails.push(i.creator.emailAddress);
}
}
if (i.assignee !== undefined && i.assignee !== null) {
if (!userUniqueEmails.includes(i.assignee.emailAddress)) {
userUniqueEmails.push(i.assignee.emailAddress);
}
const issueObjs = ['creator', 'assignee', 'reporter'];
for (const issueObj of issueObjs) {
if (i[issueObj] !== undefined && i[issueObj] !== null) {
if (!uniqueJiraUsers.find(u => u.emailAddress === i[issueObj].emailAddress)) {
uniqueJiraUsers.push({
name: i[issueObj].name,
key: i[issueObj].key,
emailAddress: i[issueObj].emailAddress,
displayName: i[issueObj].displayName
});
}
}
}
if (i.comments !== undefined && i.comments.totalCount > 0) {
for (const comment of i.comments.edges) {
if (
comment.node.author !== undefined &&
!userUniqueEmails.includes(comment.node.author.emailAddress)
) {
userUniqueEmails.push(comment.node.author.emailAddress);
}
if (
comment.node.updateAuthor !== undefined &&
!userUniqueEmails.includes(comment.node.updateAuthor.emailAddress)
) {
userUniqueEmails.push(comment.node.updateAuthor.emailAddress);
const issueObjs = ['author', 'updateAuthor'];
for (const issueObj of issueObjs) {
if (
comment.node[issueObj] !== undefined &&
!uniqueJiraUsers.find(u => u.emailAddress === comment.node[issueObj].emailAddress)
) {
uniqueJiraUsers.push({
name: comment.node[issueObj].name,
key: comment.node[issueObj].key,
emailAddress: comment.node[issueObj].emailAddress,
displayName: comment.node[issueObj].displayName
});
}
}
}
}
Expand All @@ -110,23 +111,31 @@ export default class Issues extends Command {
this.exit();
}
}
const missingEmails: string[] = userUniqueEmails.filter(
u => importConfig.users.find(us => us.jiraEmail === u) === undefined,
const missingUsers: JiraUser[] = uniqueJiraUsers.filter(
u => importConfig.users.find(us => us.jira.emailAddress === u.emailAddress) === undefined,
);
if (missingEmails.length > 0) {

if (missingUsers.length > 0) {
this.log('The following users are missing from import-config.yml:');
missingEmails.forEach(m => this.log(m));
missingUsers.forEach(m => this.log(JSON.stringify(m)));
const formatMissing = {
users: missingEmails.map((m: string) => {
return { jiraEmail: m, githubUsername: 'TOBEREPLACED' };
users: missingUsers.map((m: JiraUser) => {
return {
jira: {
...m
},
github: {
username: 'TOBEREPLACED'
}
};
}),
};
fs.writeFileSync(
path.join(this.config.configDir, 'import-config.template.yml'),
jsYaml.safeDump(formatMissing),
);
this.log(
'A template was prepopulated at: ' +
'\n A template was prepopulated at: ' +
path.join(this.config.configDir, 'import-config.template.yml'),
);
this.log(
Expand Down Expand Up @@ -169,6 +178,7 @@ export default class Issues extends Command {
const preppedIssues: any[] = [];
//.filter(i => i.key === 'FORM-1585')
for (let i of issues.filter(i => i.key !== undefined)) {
console.log(i.key)
const repoCfg: any = importConfig.repos.find(
r => r.jiraProjectKey === i.project.key,
);
Expand All @@ -191,13 +201,19 @@ export default class Issues extends Command {
}

const header = getHeader(i, importConfig.users);
console.log(1)
const comments = getComments(i, importConfig.users);
console.log(2)
const assignee = getAssignee(i, importConfig.users);
console.log(3)
const reporter = getReporter(i, importConfig.users);
console.log(4)
const labels = getLabels(i);
console.log(5)

let body =
i.description !== null
? header + '\n\n\n' + jira2md.to_markdown(i.description)
? header + '\n\n\n' + cleanJiraContent(i.description, importConfig.users, i)
: header;

const bodySize = new TextEncoder().encode(body).length;
Expand All @@ -217,6 +233,7 @@ export default class Issues extends Command {
// eslint-disable-next-line @typescript-eslint/camelcase
updated_at: new Date(i.updatedAt).toISOString(),
};

if (assignee !== null) {
issuePayload = { ...issuePayload, assignee };
} else if (reporter !== null) {
Expand All @@ -229,6 +246,7 @@ export default class Issues extends Command {
closed_at: new Date(i.closedAt).toISOString(),
};
}

if (labels.length > 0) {
issuePayload = { ...issuePayload, labels };
}
Expand Down
Loading

0 comments on commit 5e1a4e8

Please sign in to comment.