forked from piceaTech/node-gitlab-2-github
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgithubHelper.js
More file actions
797 lines (672 loc) · 25.4 KB
/
githubHelper.js
File metadata and controls
797 lines (672 loc) · 25.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
import * as settings from './settings';
import utils from './utils';
export default class GithubHelper {
constructor(githubApi, githubSettings, gitlabHelper) {
this.githubApi = githubApi;
this.githubOwner = githubSettings.owner;
this.githubToken = githubSettings.token;
this.githubRepo = githubSettings.repo;
this.githubTimeout = githubSettings.timeout;
this.gitlabHelper = gitlabHelper;
// regex for converting user from GitLab to GitHub
this.userProjectRegex = utils.generateUserProjectRegex();
}
/*
******************************************************************************
******************************** GET METHODS *********************************
******************************************************************************
*/
/**
* Get a list of all GitHub milestones currently in new repo
*/
async getAllGithubMilestones() {
try {
await utils.sleep(2000);
// get an array of GitHub milestones for the new repo
let result = await this.githubApi.issues.listMilestonesForRepo({
owner: this.githubOwner,
repo: this.githubRepo,
state: 'all',
});
// extract the milestone number and title and put into a new array
const milestones = result.data.map(x => ({
number: x.number,
title: x.title,
}));
return milestones;
} catch (err) {
console.error('Could not access all GitHub milestones');
console.error(err);
process.exit(1);
}
}
// ----------------------------------------------------------------------------
/**
* Get a list of all the current GitHub issues.
* This uses a while loop to make sure that each page of issues is received.
*/
async getAllGithubIssues() {
let allIssues = [];
let page = 1;
const perPage = 100;
while (true) {
await utils.sleep(2000);
// get a paginated list of issues
const issues = await this.githubApi.issues.listForRepo({
owner: this.githubOwner,
repo: this.githubRepo,
state: 'all',
per_page: perPage,
page: page,
});
// if this page has zero issues then we are done!
if (issues.data.length === 0) break;
// join this list of issues with the master list
allIssues = allIssues.concat(issues.data);
// if there are strictly less issues on this page than the maximum number per page
// then we can be sure that this is all the issues. No use querying again.
if (issues.data.length < perPage) break;
// query for the next page of issues next iteration
page++;
}
return allIssues;
}
// ----------------------------------------------------------------------------
/**
* Get a list of all GitHub label names currently in new repo
*/
async getAllGithubLabelNames() {
try {
await utils.sleep(2000);
// get an array of GitHub labels for the new repo
let result = await this.githubApi.issues.listLabelsForRepo({
owner: this.githubOwner,
repo: this.githubRepo,
});
// extract the label name and put into a new array
let labels = result.data.map(x => x.name);
return labels;
} catch (err) {
console.error('Could not access all GitHub label names');
console.error(err);
process.exit(1);
}
}
// ----------------------------------------------------------------------------
/**
* Get a list of all the current GitHub pull requests.
* This uses a while loop to make sure that each page of issues is received.
*/
async getAllGithubPullRequests() {
let allPullRequests = [];
let page = 1;
const perPage = 100;
while (true) {
await utils.sleep(2000);
// get a paginated list of pull requests
const pullRequests = await this.githubApi.pulls.list({
owner: this.githubOwner,
repo: this.githubRepo,
state: 'all',
per_page: perPage,
page: page,
});
// if this page has zero PRs then we are done!
if (pullRequests.data.length === 0) break;
// join this list of PRs with the master list
allPullRequests = allPullRequests.concat(pullRequests.data);
// if there are strictly less PRs on this page than the maximum number per page
// then we can be sure that this is all the PRs. No use querying again.
if (pullRequests.data.length < perPage) break;
// query for the next page of PRs next iteration
page++;
}
return allPullRequests;
}
// ----------------------------------------------------------------------------
/*
******************************************************************************
******************************** POST METHODS ********************************
******************************************************************************
*/
/**
* TODO description
*/
async createIssue(milestones, issue) {
let bodyConverted = this.convertIssuesAndComments(issue.description, issue);
let props = {
owner: this.githubOwner,
repo: this.githubRepo,
title: issue.title.trim(),
body: bodyConverted,
};
//
// Issue Assignee
//
// If the GitLab issue has an assignee, make sure to carry it over -- but only
// if the username is a valid GitHub username.
if (issue.assignee) {
props.assignees = [];
if (issue.assignee.username === settings.github.username) {
props.assignees.push(settings.github.username);
} else if (
settings.usermap &&
settings.usermap[issue.assignee.username]
) {
// get GitHub username name from settings
props.assignees.push(settings.usermap[issue.assignee.username]);
}
}
//
// Issue Milestone
//
// if the GitLab issue has an associated milestone, make sure to attach it.
if (issue.milestone) {
let milestone = milestones.find(m => m.title === issue.milestone.title);
if (milestone) {
props.milestone = milestone.number;
}
}
//
// Issue Labels
//
// make sure to add any labels that existed in GitLab
if (issue.labels) {
props.labels = issue.labels.filter(l => {
if (issue.state !== 'closed') return true;
let lower = l.toLowerCase();
// ignore any labels that should have been removed when the issue was closed
return lower !== 'doing' && lower !== 'to do';
});
}
//
// Issue Attachments
//
// if the issue contains a url that contains "/uploads/", it is likely to
// have an attachment. Therefore, add the "has attachment" label.
if (props.body && props.body.indexOf('/uploads/') > -1) {
props.labels.push('has attachment');
}
await utils.sleep(2000);
if (settings.debug) return Promise.resolve({ data: issue });
// create the GitHub issue from the GitLab issue
return this.githubApi.issues.create(props);
}
// ----------------------------------------------------------------------------
/**
* TODO description
*/
async createIssueComments(githubIssue, issue) {
console.log('\tMigrating issue comments...');
// retrieve any notes/comments associated with this issue
if (issue.isPlaceholder) {
console.log(
'\t...this is a placeholder issue, no comments are migrated.'
);
return;
}
let notes = await this.gitlabHelper.getIssueNotes(issue.iid);
// if there are no notes, then there is nothing to do!
if (notes.length === 0) {
console.log(`\t...no issue comments available, nothing to migrate.`);
return;
}
// sort notes in ascending order of when they were created (by id)
notes = notes.sort((a, b) => a.id - b.id);
let nrOfMigratedNotes = 0;
for (let note of notes) {
const gotMigrated = await this.processNote(note, githubIssue);
if (gotMigrated) {
nrOfMigratedNotes++;
}
}
console.log(
`\t...Done creating issue comments (migrated ${nrOfMigratedNotes} comments, skipped ${notes.length -
nrOfMigratedNotes} comments)`
);
}
// ----------------------------------------------------------------------------
/**
* This function checks if a note needs to be processed or if it can be skipped.
* A note can be skipped if it contains predefined terms (like 'Status changed to...')
* or if it contains any value from settings.skipMatchingComments ->
* Note that this is case insensitive!
*
*/
checkIfNoteCanBeSkipped(noteBody) {
const stateChange =
(/Status changed to .*/i.test(noteBody) &&
!/Status changed to closed by commit.*/i.test(noteBody)) ||
/changed milestone to .*/i.test(noteBody) ||
/Milestone changed to .*/i.test(noteBody) ||
/Reassigned to /i.test(noteBody) ||
/added .* labels/i.test(noteBody) ||
/Added ~.* label/i.test(noteBody) ||
/removed ~.* label/i.test(noteBody) ||
/mentioned in issue.*/i.test(noteBody);
const matchingComment = settings.skipMatchingComments.reduce(
(a, b) => a || new RegExp(b, 'i').test(noteBody),
false
);
return stateChange || matchingComment;
}
// ----------------------------------------------------------------------------
/*
* Processes the current note.
* This means, it either creates a comment in the github issue, or it gets skipped.
* Return false when it got skipped, otherwise true.
*/
async processNote(note, githubIssue) {
if (this.checkIfNoteCanBeSkipped(note.body)) {
// note will be skipped
return false;
} else {
let bodyConverted = this.convertIssuesAndComments(note.body, note);
await utils.sleep(2000);
if (settings.debug) {
return true;
}
await this.githubApi.issues
.createComment({
owner: this.githubOwner,
repo: this.githubRepo,
number: githubIssue.number,
body: bodyConverted,
})
.catch(x => {
console.error('could not create GitHub issue comment!');
console.error(x);
process.exit(1);
});
return true;
}
}
// ----------------------------------------------------------------------------
/**
* Update the issue state (i.e., closed or open).
*/
async updateIssueState(githubIssue, issue) {
// default state is open so we don't have to update if the issue is closed.
if (issue.state !== 'closed' || githubIssue.state === 'closed') return;
let props = {
owner: this.githubOwner,
repo: this.githubRepo,
number: githubIssue.number,
state: issue.state,
milestone: issue.milestone,
labels: issue.labels,
assignees: issue.assignees
};
await utils.sleep(2000);
if (settings.debug) {
return Promise.resolve();
}
// make the state update
return await this.githubApi.issues.update(props);
}
// ----------------------------------------------------------------------------
/**
* Create a GitHub milestone from a GitLab milestone
*/
async createMilestone(milestone) {
// convert from GitLab to GitHub
let githubMilestone = {
owner: this.githubOwner,
repo: this.githubRepo,
title: milestone.title,
description: milestone.description,
state: milestone.state === 'active' ? 'open' : 'closed',
};
if (milestone.due_date) {
githubMilestone.due_on = milestone.due_date + 'T00:00:00Z';
}
await utils.sleep(2000);
if (settings.debug) return Promise.resolve();
// create the GitHub milestone
return await this.githubApi.issues.createMilestone(githubMilestone);
}
// ----------------------------------------------------------------------------
/**
* Create a GitHub label from a GitLab label
*/
async createLabel(label) {
// convert from GitLab to GitHub
let githubLabel = {
owner: this.githubOwner,
repo: this.githubRepo,
name: label.name,
color: label.color.substr(1), // remove leading "#" because gitlab returns it but github wants the color without it
};
await utils.sleep(2000);
if (settings.debug) return Promise.resolve();
// create the GitHub label
return await this.githubApi.issues.createLabel(githubLabel);
}
// ----------------------------------------------------------------------------
/**
* Create a pull request, set its data, and set its comments
* @param milestones a list of the milestones that exist in the GitHub repository
* @param pullRequest the GitLab pull request that we want to migrate
* @returns {Promise<void>}
*/
async createPullRequestAndComments(milestones, pullRequest) {
let githubPullRequestData = await this.createPullRequest(pullRequest);
let githubPullRequest = githubPullRequestData.data;
// data is set to null if one of the branches does not exist and the pull request cannot be created
if (githubPullRequest) {
// Add milestones, labels, and other attributes from the Issues API
await this.updatePullRequestData(
githubPullRequest,
pullRequest,
milestones
);
// add any comments/nodes associated with this pull request
await this.createPullRequestComments(githubPullRequest, pullRequest);
// Make sure to close the GitHub pull request if it is closed or merged in GitLab
await this.updatePullRequestState(githubPullRequest, pullRequest);
}
}
// ----------------------------------------------------------------------------
/**
* Create a pull request. A pull request can only be created if both the target and source branches exist on the GitHub
* repository. In many cases, the source branch is deleted when the merge occurs, and the merge request may not be able
* to be migrated. In this case, an issue is created instead with a 'gitlab merge request' label.
* @param pullRequest the GitLab pull request object that we want to duplicate
* @returns {Promise<Promise<{data: null}>|Promise<Github.Response<Github.PullsCreateResponse>>|Promise<{data: *}>>}
*/
async createPullRequest(pullRequest) {
let canCreate = true;
// Check to see if the target branch exists in GitHub - if it does not exist, we cannot create a pull request
try {
await this.githubApi.repos.getBranch({
owner: this.githubOwner,
repo: this.githubRepo,
branch: pullRequest.target_branch,
});
} catch (err) {
let gitlabBranches = await this.gitlabHelper.getAllBranches();
if (gitlabBranches.find(m => m.name === pullRequest.target_branch)) {
// Need to move that branch over to GitHub!
console.error(
`The '${pullRequest.target_branch}' branch exists on GitLab but has not been migrated to GitHub. Please migrate the branch before migrating pull request #${pullRequest.iid}.`
);
return Promise.resolve({ data: null });
} else {
console.error(
`Merge request ${pullRequest.iid} (target branch '${pullRequest.target_branch}' does not exist => cannot migrate pull request, creating an issue instead.`
);
canCreate = false;
}
}
// Check to see if the source branch exists in GitHub - if it does not exist, we cannot create a pull request
try {
await this.githubApi.repos.getBranch({
owner: this.githubOwner,
repo: this.githubRepo,
branch: pullRequest.source_branch,
});
} catch (err) {
let gitlabBranches = await this.gitlabHelper.getAllBranches();
if (gitlabBranches.find(m => m.name === pullRequest.source_branch)) {
// Need to move that branch over to GitHub!
console.error(
`The '${pullRequest.source_branch}' branch exists on GitLab but has not been migrated to GitHub. Please migrate the branch before migrating pull request #${pullRequest.iid}.`
);
return Promise.resolve({ data: null });
} else {
console.error(
`Pull request #${pullRequest.iid} (source branch '${pullRequest.source_branch}' does not exist => cannot migrate pull request, creating an issue instead.`
);
canCreate = false;
}
}
if (settings.debug) return Promise.resolve({ data: pullRequest });
if (canCreate) {
let bodyConverted = this.convertIssuesAndComments(
pullRequest.description,
pullRequest
);
// GitHub API Documentation to create a pull request: https://developer.github.com/v3/pulls/#create-a-pull-request
let props = {
owner: this.githubOwner,
repo: this.githubRepo,
title: pullRequest.title.trim(),
body: bodyConverted,
head: pullRequest.source_branch,
base: pullRequest.target_branch,
};
await utils.sleep(2000);
// create the GitHub pull request from the GitLab issue
return this.githubApi.pulls.create(props);
} else {
// Create an issue with a descriptive title
let mergeStr =
'_Merges ' +
pullRequest.source_branch +
' -> ' +
pullRequest.target_branch +
'_\n\n';
let bodyConverted = this.convertIssuesAndComments(
mergeStr + pullRequest.description,
pullRequest
);
let props = {
owner: this.githubOwner,
repo: this.githubRepo,
title: pullRequest.title.trim() + ' - [' + pullRequest.state + ']',
body: bodyConverted,
};
// Add a label to indicate the issue is a merge request
pullRequest.labels.push('gitlab merge request');
return this.githubApi.issues.create(props);
}
}
// ----------------------------------------------------------------------------
/**
* Create comments for the pull request
* @param githubPullRequest the GitHub pull request object
* @param pullRequest the GitLab pull request object
* @returns {Promise<void>}
*/
async createPullRequestComments(githubPullRequest, pullRequest) {
console.log('\tMigrating pull request comments...');
if (!pullRequest.iid) {
console.log(
'\t...this is a placeholder for a deleted GitLab merge request, no comments are created.'
);
return Promise.resolve();
}
let notes = await this.gitlabHelper.getAllMergeRequestNotes(
pullRequest.iid
);
// if there are no notes, then there is nothing to do!
if (notes.length === 0) {
console.log(
`\t...no pull request comments available, nothing to migrate.`
);
return;
}
// Sort notes in ascending order of when they were created (by id)
notes = notes.sort((a, b) => a.id - b.id);
let nrOfMigratedNotes = 0;
for (let note of notes) {
const gotMigrated = await this.processNote(note, githubPullRequest);
if (gotMigrated) {
nrOfMigratedNotes++;
}
}
console.log(
`\t...Done creating pull request comments (migrated ${nrOfMigratedNotes} pull request comments, skipped ${notes.length -
nrOfMigratedNotes} pull request comments)`
);
}
// ----------------------------------------------------------------------------
/**
* Update the pull request data. The GitHub Pull Request API does not supply mechanisms to set the milestone, assignee,
* or labels; these data are set via the Issues API in this function
* @param githubPullRequest the GitHub pull request object
* @param pullRequest the GitLab pull request object
* @param milestones a list of Milestones that exist in the GitHub repo
* @returns {Promise<Github.Response<Github.IssuesUpdateResponse>>}
*/
async updatePullRequestData(githubPullRequest, pullRequest, milestones) {
let props = {
owner: this.githubOwner,
repo: this.githubRepo,
number: githubPullRequest.number || githubPullRequest.iid,
};
//
// Pull Request Assignee
//
// If the GitLab merge request has an assignee, make sure to carry it over --
// but only if the username is a valid GitHub username
if (pullRequest.assignee) {
props.assignees = [];
if (pullRequest.assignee.username === settings.github.username) {
props.assignees.push(settings.github.username);
} else if (
settings.usermap &&
settings.usermap[pullRequest.assignee.username]
) {
// Get GitHub username from settings
props.assignees.push(settings.usermap[pullRequest.assignee.username]);
}
}
//
// Pull Request Milestone
//
// if the GitLab merge request has an associated milestone, make sure to attach it
if (pullRequest.milestone) {
let milestone = milestones.find(
m => m.title === pullRequest.milestone.title
);
if (milestone) {
props.milestone = milestone.number;
}
}
//
// Merge Request Labels
//
// make sure to add any labels that existed in GitLab
if (pullRequest.labels) {
props.labels = pullRequest.labels.filter(l => {
if (pullRequest.state !== 'closed') return true;
let lower = l.toLowerCase();
// ignore any labels that should have been removed when the issue was closed
return lower !== 'doing' && lower !== 'to do';
});
}
return await this.githubApi.issues.update(props);
}
// ----------------------------------------------------------------------------
/**
* Update the pull request state
* @param githubPullRequest GitHub pull request object
* @param pullRequest GitLab pull request object
* @returns {Promise<Promise<Github.AnyResponse>|Github.Response<Github.PullsUpdateResponse>|Promise<void>>}
*/
async updatePullRequestState(githubPullRequest, pullRequest) {
if (
pullRequest.state === 'merged' &&
githubPullRequest.state !== 'closed' &&
!settings.debug
) {
// Merging the pull request adds new commits to the tree; to avoid that, just close the merge requests
pullRequest.state = 'closed';
}
// Default state is open so we don't have to update if the request is closed
if (pullRequest.state !== 'closed' || githubPullRequest.state === 'closed')
return;
let props = {
owner: this.githubOwner,
repo: this.githubRepo,
number: githubPullRequest.number,
state: pullRequest.state,
};
await utils.sleep(2000);
if (settings.debug) {
return Promise.resolve();
}
// Use the Issues API; all pull requests are issues, and we're not modifying any pull request-sepecific fields. This
// then works for merge requests that cannot be created and are migrated as issues.
return await this.githubApi.issues.update(props);
}
// ----------------------------------------------------------------------------
/**
* TODO description
*/
async createIssueAndComments(milestones, issue) {
// create the issue in GitHub
const githubIssueData = await this.createIssue(milestones, issue);
const githubIssue = githubIssueData.data;
// add any comments/notes associated with this issue
await this.createIssueComments(githubIssue, issue);
// make sure to close the GitHub issue if it is closed in GitLab
await this.updateIssueState(githubIssue, issue);
}
// ----------------------------------------------------------------------------
// TODO fix unexpected type coercion risk
/**
* Converts issue body and issue comments from GitLab to GitHub. That means:
* - Add a line at the beginning indicating which original user created the
* issue or the comment and when - because the GitHub API creates everything
* as the API user
* - Change username from GitLab to GitHub in "mentions" (@username)
*/
convertIssuesAndComments(str, item) {
if (
(!settings.usermap || Object.keys(settings.usermap).length === 0) &&
(!settings.projectmap || Object.keys(settings.projectmap).length === 0)
) {
return GithubHelper.addMigrationLine(str, item);
} else {
// - Replace userids as defined in settings.usermap.
// They all start with '@' in the issues but we have them without in usermap
// - Replace cross-project issue references. They are matched on org/project# so 'matched' ends with '#'
// They all have a '#' right after the project name in the issues but we have them without in projectmap
let strWithMigLine = GithubHelper.addMigrationLine(str, item);
strWithMigLine = strWithMigLine.replace(
this.userProjectRegex,
matched => {
if (matched.startsWith('@')) {
// this is a userid
return '@' + settings.usermap[matched.substr(1)];
} else if (matched.endsWith('#')) {
// this is a cross-project issue reference
return (
settings.projectmap[matched.substring(0, matched.length - 1)] +
'#'
);
} else {
// something went wrong, do nothing
return matched;
}
}
);
return strWithMigLine;
}
}
// ----------------------------------------------------------------------------
/**
* Adds a line of text at the beginning of a comment that indicates who, when
* and from GitLab.
*/
static addMigrationLine(str, item) {
if (!item || !item.author || !item.author.username || !item.created_at) {
return str;
}
const dateformatOptions = {
month: 'short',
day: 'numeric',
year: 'numeric',
hour: 'numeric',
minute: 'numeric',
hour12: false,
};
const formattedDate = new Date(item.created_at).toLocaleString(
'en-US',
dateformatOptions
);
return `In GitLab by @${item.author.username} on ${formattedDate}\n\n${str}`;
}
}