Skip to content

Commit 0a1fd48

Browse files
committed
Add option to save a list of users
1 parent db2c69d commit 0a1fd48

File tree

5 files changed

+29
-0
lines changed

5 files changed

+29
-0
lines changed

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,12 @@ and add them to github in chronological order, but it would not preserve the ori
190190

191191
As default it is set to false. Doesn't fire the requests to github api and only does the work on the gitlab side to test for wonky cases before using up api-calls
192192

193+
### exportUsers
194+
195+
If this is set to true (default is false) then a file called "users.txt" wil be created containing all
196+
usernames that contributed to the repository. You can use this with dryRun when you need to map users
197+
for the migration, but you do not know all the source usernames.
198+
193199
### useIssueImportAPI
194200

195201
Set to true (default) to enable using the [GitHub preview API for importing issues](https://gist.github.com/jonmagic/5282384165e0f86ef105). This allows setting the date for issues and comments instead of inserting an additional line in the body.

sample_settings.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ export default {
4444
releases: true,
4545
},
4646
dryRun: false,
47+
exportUsers: false,
4748
useIssueImportAPI: true,
4849
usePlaceholderMilestonesForMissingMilestones: true,
4950
usePlaceholderIssuesForMissingIssues: true,

src/githubHelper.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ type GitHubPullRequest = PullsListResponseData[0];
2121

2222
const gitHubLocation = 'https://github.com';
2323

24+
// Source for regex: https://stackoverflow.com/a/30281147
25+
const usernameRegex = new RegExp('\\B@([a-z0-9](?:-(?=[a-z0-9])|[a-z0-9]){0,38}(?<=[a-z0-9]))', 'gi')
26+
2427
interface CommentImport {
2528
created_at?: string;
2629
body: string;
@@ -71,6 +74,7 @@ export class GithubHelper {
7174
delayInMs: number;
7275
useIssuesForAllMergeRequests: boolean;
7376
milestoneMap?: Map<number, SimpleMilestone>;
77+
users: Set<string>;
7478

7579
constructor(
7680
githubApi: GitHubApi,
@@ -91,6 +95,7 @@ export class GithubHelper {
9195
this.gitlabHelper = gitlabHelper;
9296
this.delayInMs = 2000;
9397
this.useIssuesForAllMergeRequests = useIssuesForAllMergeRequests;
98+
this.users = new Set<string>();
9499
}
95100

96101
/*
@@ -305,6 +310,7 @@ export class GithubHelper {
305310
******************************************************************************
306311
*/
307312
userIsCreator(author: GitLabUser) {
313+
this.users.add(author.username as string);
308314
return (
309315
author &&
310316
((settings.usermap &&
@@ -366,6 +372,7 @@ export class GithubHelper {
366372
let assignees: string[] = [];
367373
for (let assignee of item.assignees) {
368374
let username: string = assignee.username as string;
375+
this.users.add(username);
369376
if (username === settings.github.username) {
370377
assignees.push(settings.github.username);
371378
} else if (settings.usermap && settings.usermap[username]) {
@@ -516,6 +523,7 @@ export class GithubHelper {
516523
for (let note of notes) {
517524
if (this.checkIfNoteCanBeSkipped(note.body)) continue;
518525

526+
this.users.add(note.author.username);
519527
let userIsPoster =
520528
(settings.usermap &&
521529
settings.usermap[note.author.username] ===
@@ -1167,6 +1175,14 @@ export class GithubHelper {
11671175
);
11681176
}
11691177

1178+
// Store usernames found in the text
1179+
const matches: Array<string> = str.match(usernameRegex);
1180+
if (matches && matches.length > 0) {
1181+
for (const username of matches) {
1182+
this.users.add(username.substring(1));
1183+
}
1184+
}
1185+
11701186
//
11711187
// Issue reference conversion
11721188
//

src/index.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,11 @@ async function migrate() {
224224
await transferMergeRequests();
225225
}
226226
}
227+
228+
if (settings.exportUsers) {
229+
const users = Array.from(githubHelper.users.values()).join("\n");
230+
fs.writeFileSync('users.txt', users);
231+
}
227232
} catch (err) {
228233
console.error('Error during transfer:');
229234
console.error(err);

src/settings.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
export default interface Settings {
22
dryRun: boolean;
3+
exportUsers: boolean;
34
gitlab: GitlabSettings;
45
github: GithubSettings;
56
usermap: {

0 commit comments

Comments
 (0)