Skip to content

Commit 11c10a0

Browse files
committed
Merge branch 'master' into feature/126-milestone-references
2 parents 4869808 + a9f2cd6 commit 11c10a0

8 files changed

Lines changed: 75 additions & 5 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
}

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,12 @@ Set to the user name of the user whose token is used (see above). This is requir
8686

8787
What is the name of the new repo
8888

89+
#### github.recreateRepo
90+
91+
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.
92+
93+
This is useful when debugging this tool or a specific migration. You will always be prompted for confirmation.
94+
8995
### s3 (optional)
9096

9197
S3 can be used to store attachments from issues. If omitted, `has attachment` label will be added to GitHub issue.

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
@@ -14,6 +14,7 @@ export default {
1414
token: '{{token}}',
1515
token_owner: '{{token_owner}}',
1616
repo: '{{repo}}',
17+
recreateRepo: false,
1718
},
1819
s3: {
1920
accessKeyId: '{{accessKeyId}}',

src/githubHelper.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1379,4 +1379,34 @@ export class GithubHelper {
13791379
milestoneData.forEach(m => this.milestoneMap.set(m.number, m));
13801380
}
13811381
}
1382+
1383+
/**
1384+
* Deletes the GH repository, then creates it again.
1385+
*/
1386+
async recreateRepo() {
1387+
let params = {
1388+
owner: this.githubOwner,
1389+
repo: this.githubRepo,
1390+
};
1391+
1392+
try {
1393+
console.log(`Deleting repo ${params.owner}/${params.repo}...`);
1394+
await this.githubApi.repos.delete(params);
1395+
console.log('\t...done.');
1396+
} catch (err) {
1397+
if (err.status == 404) console.log(' not found.');
1398+
else console.error(`\n\tSomething went wrong: ${err}.`);
1399+
}
1400+
try {
1401+
console.log(`Creating repo ${params.owner}/${params.repo}...`);
1402+
await this.githubApi.repos.createForAuthenticatedUser({
1403+
name: this.githubRepo,
1404+
private: true,
1405+
});
1406+
console.log('\t...done.');
1407+
} catch (err) {
1408+
console.error(`\n\tSomething went wrong: ${err}.`);
1409+
}
1410+
await utils.sleep(this.delayInMs);
1411+
}
13821412
}

src/index.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import { Octokit as GitHubApi } from '@octokit/rest';
1111
import { throttling } from '@octokit/plugin-throttling';
1212
import { Gitlab } from '@gitbeaker/node';
1313

14+
import { default as readlineSync } from 'readline-sync';
1415
import * as fs from 'fs';
1516

1617
import AWS from 'aws-sdk';
@@ -94,11 +95,28 @@ if (!settings.gitlab.projectId) {
9495
gitlabHelper.listProjects();
9596
} else {
9697
// user has chosen a project
98+
if (settings.github.recreateRepo === true) {
99+
recreate();
100+
}
97101
migrate();
98102
}
99103

100104
// ----------------------------------------------------------------------------
101105

106+
/**
107+
* Asks for confirmation and maybe recreates the GitHub repository.
108+
*/
109+
async function recreate() {
110+
readlineSync.setDefaultOptions({
111+
limit: ['no', 'yes'],
112+
limitMessage: 'Please enter yes or no',
113+
defaultInput: 'no',
114+
});
115+
const ans = readlineSync.question('Delete and recreate? [yes/no] ');
116+
if (ans == 'yes') await githubHelper.recreateRepo();
117+
else console.log("OK, I won't delete anything then.");
118+
}
119+
102120
/**
103121
* Creates dummy data for a placeholder milestone
104122
*

src/settings.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ export interface GithubSettings {
4343
repo: string;
4444
timeout?: number;
4545
username?: string; // when is this set???
46+
recreateRepo?: boolean;
4647
}
4748

4849
export interface GitlabSettings {

0 commit comments

Comments
 (0)