diff --git a/app.js b/app.js index a58a254..cc81a0e 100644 --- a/app.js +++ b/app.js @@ -325,12 +325,14 @@ function createGithubIssue(repo, oldIssue, closeOriginal) { preventReferences: false, }, (item) => { - const newIssueBody = `From ${urlObj.currentRepo} created by [${oldIssue.user.login}](${oldIssue.user.html_url}): [${urlObj.organization}/${urlObj.currentRepo}#${urlObj.issueNumber}](https://github.com/${urlObj.organization}/${urlObj.currentRepo}/issues/${urlObj.issueNumber}) \n\n${oldIssue.body}`; + const quotedOldBody = addBlockQuote(oldIssue.body) + const createdAtDate = oldIssue.created_at.split('T')[0]; + const newBody = `**[ @${oldIssue.user.login}](${oldIssue.user.html_url})** opened issue [${urlObj.organization}/${urlObj.currentRepo}#${urlObj.issueNumber}](${oldIssue.html_url}) on ${createdAtDate}: \n\n${quotedOldBody}` // build new issue const newIssue = { title: oldIssue.title, - body: item.preventReferences ? preventReferences(newIssueBody) : newIssueBody, + body: item.preventReferences ? preventReferences(newBody) : newBody, labels: oldIssue.labels, } @@ -348,11 +350,6 @@ function createGithubIssue(repo, oldIssue, closeOriginal) { }) } -function preventReferences(text) { - // replace "github.com" links with "www.github.com" links, which do not cause references on the original issue due to the "www" (see https://github.com/orgs/community/discussions/23123#discussioncomment-3239240) - return text.replace(/https:\/\/github.com\//gi, "https://www.github.com/") -} - function cloneOldIssueComments(newIssue, repo, url) { return ajaxRequest('GET', '', url).then((comments) => { chrome.storage.sync.get( @@ -371,8 +368,11 @@ function cloneOldIssueComments(newIssue, repo, url) { comments.data.reduce( (p, comment) => p.then(_ => { + const quotedOldBody = addBlockQuote(comment.body) + const createdAtDate = comment.created_at.split('T')[0]; + const newBody = `**[ @${comment.user.login}](${comment.user.html_url})** commented [on ${createdAtDate}](${comment.html_url}): \n\n${quotedOldBody}` const c = { - body: item.preventReferences ? preventReferences(comment.body) : comment.body, + body: item.preventReferences ? preventReferences(newBody) : newBody, } return ajaxRequest('POST', c, `https://api.github.com/repos/${repo}/issues/${newIssue}/comments`) }), @@ -588,3 +588,12 @@ function openModal() { $('#kaminoModal').addClass('in') $('#kaminoModal').css('display', 'block') } + +function addBlockQuote(text) { + return text.replace(/^/gm, "> ") +} + +function preventReferences(text) { + // replace "github.com" links with "www.github.com" links, which do not cause references on the original issue due to the "www" (see https://github.com/orgs/community/discussions/23123#discussioncomment-3239240) + return text.replace(/https:\/\/github.com\//gi, "https://www.github.com/") +} \ No newline at end of file