Skip to content
Merged
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
3 changes: 2 additions & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
"src/index.ts"
],
"protocol": "inspector",
"sourceMaps": true
"sourceMaps": true,
"console": "integratedTerminal"
}
]
}
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,12 @@ Set to the user name of the user whose token is used (see above). This is requir

What is the name of the new repo

#### github.recreateRepo

If true (default is false), we will try to delete the destination github repository if present, and (re)create it. The github token must be granted `delete_repo` scope. The newly created repository will be made private by default.

This is useful when debugging this tool or a specific migration. You will always be prompted for confirmation.

### s3 (optional)

S3 can be used to store attachments from issues. If omitted, `has attachment` label will be added to GitHub issue.
Expand Down
17 changes: 14 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,13 @@
"aws-sdk": "^2.1053.0",
"axios": "^0.24.0",
"mime-types": "^2.1.34",
"readline-sync": "^1.4.10",
"ts-node": "^10.4.0"
},
"devDependencies": {
"@types/mime-types": "^2.1.1",
"@types/node": "^14.0.20",
"@types/node": "^14.18.5",
"@types/readline-sync": "^1.4.4",
"husky": "^7.0.4",
"lint-staged": "^12.1.7",
"prettier": "^2.5.1",
Expand Down
1 change: 1 addition & 0 deletions sample_settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export default {
token: '{{token}}',
token_owner: '{{token_owner}}',
repo: '{{repo}}',
recreateRepo: false,
},
s3: {
accessKeyId: '{{accessKeyId}}',
Expand Down
30 changes: 30 additions & 0 deletions src/githubHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1260,4 +1260,34 @@ export class GithubHelper {
const ref = path && line ? `${path} line ${line}` : `${head_sha}`;
return `Commented on [${ref}](${repoLink}/compare/${base_sha}..${head_sha}${slug})\n\n`;
}

/**
* Deletes the GH repository, then creates it again.
*/
async recreateRepo() {
let params = {
owner: this.githubOwner,
repo: this.githubRepo,
};

try {
console.log(`Deleting repo ${params.owner}/${params.repo}...`);
await this.githubApi.repos.delete(params);
console.log('\t...done.');
} catch (err) {
if (err.status == 404) console.log(' not found.');
else console.error(`\n\tSomething went wrong: ${err}.`);
}
try {
console.log(`Creating repo ${params.owner}/${params.repo}...`);
await this.githubApi.repos.createForAuthenticatedUser({
name: this.githubRepo,
private: true,
});
console.log('\t...done.');
} catch (err) {
console.error(`\n\tSomething went wrong: ${err}.`);
}
await utils.sleep(this.delayInMs);
}
}
18 changes: 18 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { Octokit as GitHubApi } from '@octokit/rest';
import { throttling } from '@octokit/plugin-throttling';
import { Gitlab } from '@gitbeaker/node';

import { default as readlineSync } from 'readline-sync';
import * as fs from 'fs';

import AWS from 'aws-sdk';
Expand Down Expand Up @@ -101,11 +102,28 @@ if (!settings.gitlab.projectId) {
gitlabHelper.listProjects();
} else {
// user has chosen a project
if (settings.github.recreateRepo === true) {
recreate();
}
migrate();
}

// ----------------------------------------------------------------------------

/**
* Asks for confirmation and maybe recreates the GitHub repository.
*/
async function recreate() {
readlineSync.setDefaultOptions({
limit: ['no', 'yes'],
limitMessage: 'Please enter yes or no',
defaultInput: 'no',
});
const ans = readlineSync.question('Delete and recreate? [yes/no] ');
if (ans == 'yes') await githubHelper.recreateRepo();
else console.log("OK, I won't delete anything then.");
}

/*
* TODO description
*/
Expand Down
115 changes: 58 additions & 57 deletions src/settings.ts
Original file line number Diff line number Diff line change
@@ -1,57 +1,58 @@
export default interface Settings {
debug: boolean;
gitlab: GitlabSettings;
github: GithubSettings;
usermap: {
[key: string]: string;
};
projectmap: {
[key: string]: string;
};
conversion: {
useLowerCaseLabels: boolean;
};
transfer: {
description: boolean;
milestones: boolean;
labels: boolean;
issues: boolean;
mergeRequests: boolean;
releases: boolean;
};
useIssueImportAPI: boolean;
usePlaceholderIssuesForMissingIssues: boolean;
useReplacementIssuesForCreationFails: boolean;
useIssuesForAllMergeRequests: boolean;
filterByLabel: string | null;
skipMergeRequestStates: string[];
skipMatchingComments: string[];
mergeRequests: {
logFile: string;
log: boolean;
};
s3?: S3Settings;
}

export interface GithubSettings {
baseUrl?: string;
owner: string;
token: string;
token_owner: string;
repo: string;
timeout?: number;
username?: string; // when is this set???
}

export interface GitlabSettings {
url?: string;
token: string;
projectId: number;
sessionCookie: string;
}

export interface S3Settings {
accessKeyId: string;
secretAccessKey: string;
bucket: string;
}
export default interface Settings {
debug: boolean;
gitlab: GitlabSettings;
github: GithubSettings;
usermap: {
[key: string]: string;
};
projectmap: {
[key: string]: string;
};
conversion: {
useLowerCaseLabels: boolean;
};
transfer: {
description: boolean;
milestones: boolean;
labels: boolean;
issues: boolean;
mergeRequests: boolean;
releases: boolean;
};
useIssueImportAPI: boolean;
usePlaceholderIssuesForMissingIssues: boolean;
useReplacementIssuesForCreationFails: boolean;
useIssuesForAllMergeRequests: boolean;
filterByLabel: string | null;
skipMergeRequestStates: string[];
skipMatchingComments: string[];
mergeRequests: {
logFile: string;
log: boolean;
};
s3?: S3Settings;
}

export interface GithubSettings {
baseUrl?: string;
owner: string;
token: string;
token_owner: string;
repo: string;
timeout?: number;
username?: string; // when is this set???
recreateRepo?: boolean;
}

export interface GitlabSettings {
url?: string;
token: string;
projectId: number;
sessionCookie: string;
}

export interface S3Settings {
accessKeyId: string;
secretAccessKey: string;
bucket: string;
}