Skip to content

Commit 474c2c8

Browse files
committed
Add option (and confirmation prompt) to recreate github repository
1 parent 515aa34 commit 474c2c8

7 files changed

Lines changed: 118 additions & 62 deletions

File tree

.vscode/launch.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@
1919
"src/index.ts"
2020
],
2121
"protocol": "inspector",
22-
"sourceMaps": true
22+
"sourceMaps": true,
23+
"console": "integratedTerminal"
2324
}
2425
]
2526
}

package-lock.json

Lines changed: 14 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,13 @@
3333
"aws-sdk": "^2.1053.0",
3434
"axios": "^0.24.0",
3535
"mime-types": "^2.1.34",
36+
"readline-sync": "^1.4.10",
3637
"ts-node": "^10.4.0"
3738
},
3839
"devDependencies": {
3940
"@types/mime-types": "^2.1.1",
40-
"@types/node": "^14.0.20",
41+
"@types/node": "^14.18.5",
42+
"@types/readline-sync": "^1.4.4",
4143
"husky": "^7.0.4",
4244
"lint-staged": "^12.1.7",
4345
"prettier": "^2.5.1",

sample_settings.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ export default {
1313
token: '{{token}}',
1414
token_owner: '{{token_owner}}',
1515
repo: '{{repo}}',
16+
recreateRepo: false,
1617
},
1718
s3: {
1819
accessKeyId: '{{accessKeyId}}',

src/githubHelper.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1260,4 +1260,29 @@ export class GithubHelper {
12601260
const ref = path && line ? `${path} line ${line}` : `${head_sha}`;
12611261
return `Commented on [${ref}](${repoLink}/compare/${base_sha}..${head_sha}${slug})\n\n`;
12621262
}
1263+
1264+
async recreateRepo() {
1265+
let params = {
1266+
owner: this.githubOwner,
1267+
repo: this.githubRepo,
1268+
};
1269+
1270+
try {
1271+
process.stdout.write(`Deleting repo ${params.owner}/${params.repo}...`);
1272+
await this.githubApi.repos.delete(params);
1273+
process.stdout.write(' done.');
1274+
} catch (err) {
1275+
if (err.status == 404) process.stdout.write(' not found.');
1276+
else console.error(`\n\tSomething went wrong: ${err}.`);
1277+
}
1278+
try {
1279+
process.stdout.write(`Creating repo ${params.owner}/${params.repo}...`);
1280+
await this.githubApi.repos.createForAuthenticatedUser({
1281+
name: this.githubRepo,
1282+
});
1283+
process.stdout.write(' done.');
1284+
} catch (err) {
1285+
console.error(`\n\tSomething went wrong: ${err}.`);
1286+
}
1287+
}
12631288
}

src/index.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { Octokit as GitHubApi } from '@octokit/rest';
66
import { throttling } from '@octokit/plugin-throttling';
77
import { Gitlab } from '@gitbeaker/node';
88

9+
import { default as readlineSync } from 'readline-sync';
910
import * as fs from 'fs';
1011

1112
import AWS from 'aws-sdk';
@@ -101,11 +102,25 @@ if (!settings.gitlab.projectId) {
101102
gitlabHelper.listProjects();
102103
} else {
103104
// user has chosen a project
105+
if (settings.github.recreateRepo === true) {
106+
recreate();
107+
}
104108
migrate();
105109
}
106110

107111
// ----------------------------------------------------------------------------
108112

113+
async function recreate() {
114+
readlineSync.setDefaultOptions({
115+
limit: ['no', 'yes'],
116+
limitMessage: 'Please enter yes or no',
117+
defaultInput: 'no',
118+
});
119+
const ans = readlineSync.question('Delete and recreate? [yes/no] ');
120+
if (ans == 'yes') await githubHelper.recreateRepo();
121+
else console.log("OK, I won't delete anything then.");
122+
}
123+
109124
/*
110125
* TODO description
111126
*/

src/settings.ts

Lines changed: 58 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1,57 +1,58 @@
1-
export default interface Settings {
2-
debug: boolean;
3-
gitlab: GitlabSettings;
4-
github: GithubSettings;
5-
usermap: {
6-
[key: string]: string;
7-
};
8-
projectmap: {
9-
[key: string]: string;
10-
};
11-
conversion: {
12-
useLowerCaseLabels: boolean;
13-
};
14-
transfer: {
15-
description: boolean;
16-
milestones: boolean;
17-
labels: boolean;
18-
issues: boolean;
19-
mergeRequests: boolean;
20-
releases: boolean;
21-
};
22-
useIssueImportAPI: boolean;
23-
usePlaceholderIssuesForMissingIssues: boolean;
24-
useReplacementIssuesForCreationFails: boolean;
25-
useIssuesForAllMergeRequests: boolean;
26-
filterByLabel: string | null;
27-
skipMergeRequestStates: string[];
28-
skipMatchingComments: string[];
29-
mergeRequests: {
30-
logFile: string;
31-
log: boolean;
32-
};
33-
s3?: S3Settings;
34-
}
35-
36-
export interface GithubSettings {
37-
baseUrl?: string;
38-
owner: string;
39-
token: string;
40-
token_owner: string;
41-
repo: string;
42-
timeout?: number;
43-
username?: string; // when is this set???
44-
}
45-
46-
export interface GitlabSettings {
47-
url?: string;
48-
token: string;
49-
projectId: number;
50-
sessionCookie: string;
51-
}
52-
53-
export interface S3Settings {
54-
accessKeyId: string;
55-
secretAccessKey: string;
56-
bucket: string;
57-
}
1+
export default interface Settings {
2+
debug: boolean;
3+
gitlab: GitlabSettings;
4+
github: GithubSettings;
5+
usermap: {
6+
[key: string]: string;
7+
};
8+
projectmap: {
9+
[key: string]: string;
10+
};
11+
conversion: {
12+
useLowerCaseLabels: boolean;
13+
};
14+
transfer: {
15+
description: boolean;
16+
milestones: boolean;
17+
labels: boolean;
18+
issues: boolean;
19+
mergeRequests: boolean;
20+
releases: boolean;
21+
};
22+
useIssueImportAPI: boolean;
23+
usePlaceholderIssuesForMissingIssues: boolean;
24+
useReplacementIssuesForCreationFails: boolean;
25+
useIssuesForAllMergeRequests: boolean;
26+
filterByLabel: string | null;
27+
skipMergeRequestStates: string[];
28+
skipMatchingComments: string[];
29+
mergeRequests: {
30+
logFile: string;
31+
log: boolean;
32+
};
33+
s3?: S3Settings;
34+
}
35+
36+
export interface GithubSettings {
37+
baseUrl?: string;
38+
owner: string;
39+
token: string;
40+
token_owner: string;
41+
repo: string;
42+
timeout?: number;
43+
username?: string; // when is this set???
44+
recreateRepo?: boolean;
45+
}
46+
47+
export interface GitlabSettings {
48+
url?: string;
49+
token: string;
50+
projectId: number;
51+
sessionCookie: string;
52+
}
53+
54+
export interface S3Settings {
55+
accessKeyId: string;
56+
secretAccessKey: string;
57+
bucket: string;
58+
}

0 commit comments

Comments
 (0)