Skip to content

Commit a15a1a1

Browse files
committed
Add information about assignees and reviewers to body
1 parent 5b8750d commit a15a1a1

6 files changed

Lines changed: 89 additions & 4 deletions

File tree

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,10 @@ When one renames the project while transfering so that the projects don't loose
162162

163163
If this is set to true (default) then labels from GitLab will be converted to lowercase in GitHub.
164164

165+
#### conversion.addIssueInformation
166+
167+
If this is set to `true` (default) then issues and pull requests will get information about assignees (both), reviewers and approvers (PR only) added to their description.
168+
165169
### transfer
166170

167171
#### transfer.milestones

sample_settings.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ export default {
3434
},
3535
conversion: {
3636
useLowerCaseLabels: true,
37+
addIssueInformation: true,
3738
},
3839
transfer: {
3940
description: true,

src/githubHelper.ts

Lines changed: 41 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,9 @@ export class GithubHelper {
346346
let bodyConverted = await this.convertIssuesAndComments(
347347
issue.description ?? '',
348348
issue,
349-
!this.userIsCreator(issue.author) || !issue.description
349+
!this.userIsCreator(issue.author) || !issue.description,
350+
true,
351+
true,
350352
);
351353

352354
let props: RestEndpointMethodTypes['issues']['create']['parameters'] = {
@@ -460,7 +462,9 @@ export class GithubHelper {
460462
: await this.convertIssuesAndComments(
461463
issue.description ?? '',
462464
issue,
463-
!this.userIsCreator(issue.author) || !issue.description
465+
!this.userIsCreator(issue.author) || !issue.description,
466+
true,
467+
true,
464468
);
465469

466470
let props: IssueImport = {
@@ -985,7 +989,10 @@ export class GithubHelper {
985989
if (canCreate) {
986990
let bodyConverted = await this.convertIssuesAndComments(
987991
mergeRequest.description,
988-
mergeRequest
992+
mergeRequest,
993+
true,
994+
true,
995+
true,
989996
);
990997

991998
// GitHub API Documentation to create a pull request: https://developer.github.com/v3/pulls/#create-a-pull-request
@@ -1027,7 +1034,9 @@ export class GithubHelper {
10271034
let bodyConverted = await this.convertIssuesAndComments(
10281035
mergeStr + mergeRequest.description,
10291036
mergeRequest,
1030-
!this.userIsCreator(mergeRequest.author) || !settings.useIssueImportAPI
1037+
!this.userIsCreator(mergeRequest.author) || !settings.useIssueImportAPI,
1038+
true,
1039+
true,
10311040
);
10321041

10331042
if (settings.useIssueImportAPI) {
@@ -1284,12 +1293,15 @@ export class GithubHelper {
12841293
* @param str Body of the GitLab note
12851294
* @param item GitLab item to which the note belongs
12861295
* @param add_line Set to true to add the line with author and creation date
1296+
* @param add_line_ref Set to true to add the line ref to the comment
1297+
* @param add_issue_information Set to true to add assignees, reviewers, and approvers
12871298
*/
12881299
async convertIssuesAndComments(
12891300
str: string,
12901301
item: GitLabIssue | GitLabMergeRequest | GitLabNote | MilestoneImport | GitLabDiscussionNote,
12911302
add_line: boolean = true,
12921303
add_line_ref: boolean = true,
1304+
add_issue_information: boolean = false,
12931305
): Promise<string> {
12941306
// A note on implementation:
12951307
// We don't convert project names once at the beginning because otherwise
@@ -1464,6 +1476,11 @@ export class GithubHelper {
14641476
this.gitlabHelper
14651477
);
14661478

1479+
if (add_issue_information && settings.conversion.addIssueInformation) {
1480+
let issue = item as GitLabIssue;
1481+
str = await this.addIssueInformation(issue, str)
1482+
}
1483+
14671484
if ('web_url' in item) {
14681485
str += '\n\n*Migrated from GitLab: ' + item.web_url + '*';
14691486
}
@@ -1564,6 +1581,26 @@ export class GithubHelper {
15641581
return lineRef;
15651582
}
15661583

1584+
async addIssueInformation(issue: GitLabIssue | GitLabMergeRequest, description: string): Promise<string> {
1585+
let bodyConverted = description;
1586+
1587+
let assignees = issue.assignees.map(a => a.username) as string[];
1588+
bodyConverted += utils.organizationUsersString(assignees, "Assignees");
1589+
1590+
// check whether issue is of type GitLabMergeRequest
1591+
if (issue.reviewers) {
1592+
let mergeRequest = issue as GitLabMergeRequest;
1593+
1594+
let mrReviewers = mergeRequest.reviewers.map(a => a.username) as string[];
1595+
bodyConverted += utils.organizationUsersString(mrReviewers, 'Reviewers');
1596+
1597+
let approvals = await this.gitlabHelper.getMergeRequestApprovals(mergeRequest.iid);
1598+
bodyConverted += utils.organizationUsersString(approvals, 'Approved by');
1599+
}
1600+
1601+
return bodyConverted;
1602+
}
1603+
15671604
/**
15681605
* Meh...
15691606
* @param milestoneMap

src/gitlabHelper.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,28 @@ export class GitlabHelper {
151151
return this.allBranches as any[];
152152
}
153153

154+
async getMergeRequestApprovals(pullRequestIid: number): Promise<string[]> {
155+
try {
156+
let approvals = await this.gitlabApi.MergeRequestApprovals.showConfiguration(
157+
this.gitlabProjectId,
158+
{
159+
mergerequestIId: pullRequestIid,
160+
},
161+
);
162+
163+
if (approvals.rules[0]) {
164+
return approvals.rules[0].approved_by.map(user => user.username);
165+
}
166+
167+
console.log(`No approvals found for GitLab merge request !${pullRequestIid}.`)
168+
} catch (err) {
169+
console.error(
170+
`Could not fetch approvals for GitLab merge request !${pullRequestIid}: ${err}`
171+
);
172+
}
173+
return [];
174+
}
175+
154176
/**
155177
* Gets all notes for a given merge request.
156178
*/

src/settings.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ export default interface Settings {
1111
};
1212
conversion: {
1313
useLowerCaseLabels: boolean;
14+
addIssueInformation: boolean;
1415
};
1516
transfer: {
1617
description: boolean;

src/utils.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { S3Settings } from './settings';
2+
import settings from '../settings';
23
import * as mime from 'mime-types';
34
import * as path from 'path';
45
import * as crypto from 'crypto';
@@ -97,3 +98,22 @@ export const migrateAttachments = async (
9798
({}, {}, {}, {}, offset, {}) => offsetToAttachment[offset]
9899
);
99100
};
101+
102+
export const organizationUsersString = (users: string[], prefix: string): string => {
103+
let organizationUsers = [];
104+
for (let assignee of users) {
105+
let githubUser = settings.usermap[assignee as string];
106+
if (githubUser) {
107+
githubUser = '@' + githubUser;
108+
} else {
109+
githubUser = assignee as string;
110+
}
111+
organizationUsers.push(githubUser);
112+
}
113+
114+
if (organizationUsers.length > 0) {
115+
return `\n\n**${prefix}:** ` + organizationUsers.join(', ');
116+
}
117+
118+
return '';
119+
}

0 commit comments

Comments
 (0)