diff --git a/app.js b/app.js
index b233719..20fd04c 100644
--- a/app.js
+++ b/app.js
@@ -280,7 +280,10 @@ async function createGithubIssue(repo, oldIssue, closeOriginal) {
}
chrome.storage.sync.get({ preventReferences: false }, async (item) => {
- const newIssueBody = `From ${currentRepo} created by [${oldIssue.user.login}](${oldIssue.user.html_url}): [${organization}/${currentRepo}#${issueNumber}](https://github.com/${organization}/${currentRepo}/issues/${issueNumber}) \n\n${oldIssue.body}`
+ const blockQuoteOldBody = addBlockQuote(oldIssue.body)
+ const createdAt = oldIssue.created_at.split('T')[0]
+ const newIssueBody = `**[ @${oldIssue.user.login}](${oldIssue.user.html_url})** cloned issue [${organization}/${currentRepo}#${issueNumber}](${oldIssue.html_url}) on ${createdAt}: \n\n${blockQuoteOldBody}`
+
const newIssue = {
title: oldIssue.title,
body: item.preventReferences ? preventReferences(newIssueBody) : newIssueBody,
@@ -297,11 +300,6 @@ async 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/')
-}
-
async function cloneOldIssueComments(newIssue, repo, url) {
const response = await ajaxRequest('GET', '', url)
@@ -321,8 +319,11 @@ async function cloneOldIssueComments(newIssue, repo, url) {
response.data.reduce(async (previous, current) => {
await previous
+ const blockQuoteOldBody = addBlockQuote(current.body)
+ const createdAt = current.created_at.split('T')[0]
+ const newCommentBody = `**[ @${current.user.login}](${current.user.html_url})** [commented](${current.html_url}) on ${createdAt}: \n\n${blockQuoteOldBody}`
const comment = {
- body: item.preventReferences ? preventReferences(current.body) : current.body,
+ body: item.preventReferences ? preventReferences(newCommentBody) : newCommentBody,
}
return ajaxRequest('POST', comment, `${githubApiUrl}repos/${repo}/issues/${newIssue}/comments`)
}, Promise.resolve())
diff --git a/batch.js b/batch.js
index ea9c024..fde3d8b 100644
--- a/batch.js
+++ b/batch.js
@@ -291,7 +291,10 @@ async function createGithubIssue(repo, oldIssue, closeOriginal) {
}
chrome.storage.sync.get({ preventReferences: false }, async (item) => {
- const newIssueBody = `From ${currentRepo} created by [${oldIssue.user.login}](${oldIssue.user.html_url}): [${organization}/${currentRepo}#${issueNumber}](https://github.com/${organization}/${currentRepo}/issues/${issueNumber}) \n\n${oldIssue.body}`
+ const blockQuoteOldBody = addBlockQuote(oldIssue.body)
+ const createdAt = oldIssue.created_at.split('T')[0]
+ const newIssueBody = `**[ @${oldIssue.user.login}](${oldIssue.user.html_url})** cloned issue [${organization}/${currentRepo}#${issueNumber}](${oldIssue.html_url}) on ${createdAt}: \n\n${blockQuoteOldBody}`
+
const newIssue = {
title: oldIssue.title,
body: item.preventReferences ? preventReferences(newIssueBody) : newIssueBody,
@@ -308,17 +311,13 @@ async 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/')
-}
-
async function cloneOldIssueComments(newIssue, repo, url) {
const comments = await ajaxRequest('GET', '', url)
chrome.storage.sync.get(
{
cloneComments: false,
+ preventReferences: false,
},
async (item) => {
if (!item.cloneComments) {
@@ -329,13 +328,16 @@ async function cloneOldIssueComments(newIssue, repo, url) {
return null
}
- for (var comment of comments.data) {
- const c = {
- body: comment.body,
+ comments.data.reduce(async (previous, current) => {
+ await previous
+ const blockQuoteOldBody = addBlockQuote(current.body)
+ const createdAt = current.created_at.split('T')[0]
+ const newCommentBody = `**[ @${current.user.login}](${current.user.html_url})** commented [on ${createdAt}](${current.html_url}): \n\n${blockQuoteOldBody}`
+ const comment = {
+ body: item.preventReferences ? preventReferences(newCommentBody) : newCommentBody,
}
-
- await ajaxRequest('POST', c, `https://api.github.com/repos/${repo}/issues/${newIssue}/comments`)
- }
+ return ajaxRequest('POST', comment, `${githubApiUrl}repos/${repo}/issues/${newIssue}/comments`)
+ }, Promise.resolve())
}
)
}
@@ -445,21 +447,6 @@ function addRepoToList(repoFullName, section) {
}
}
-function populateUrlMetadata() {
- var url = document.location.href
- const urlArray = url.split('/')
- const currentRepo = urlArray[4]
- const organization = urlArray[3]
-
- const urlObject = {
- url: url,
- currentRepo: currentRepo,
- organization: organization,
- }
-
- return urlObject
-}
-
function closeBatchModal() {
$('#batchModal').removeClass('in')
$('#batchModal').css('display', '')
diff --git a/lib/addBlockQuote.js b/lib/addBlockQuote.js
new file mode 100644
index 0000000..282fcc9
--- /dev/null
+++ b/lib/addBlockQuote.js
@@ -0,0 +1,5 @@
+function addBlockQuote(text) {
+ return text.replace(/^/gm, '> ')
+}
+
+module.exports = addBlockQuote
diff --git a/lib/preventReferences.js b/lib/preventReferences.js
new file mode 100644
index 0000000..55af1b7
--- /dev/null
+++ b/lib/preventReferences.js
@@ -0,0 +1,6 @@
+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/')
+}
+
+module.exports = preventReferences
diff --git a/manifest.json b/manifest.json
index da20810..3f6955b 100644
--- a/manifest.json
+++ b/manifest.json
@@ -9,6 +9,8 @@
"./handlebars.runtime.min-v4.7.7.js",
"./lib/populateUrlMetadata.js",
"./lib/createFilters.js",
+ "./lib/addBlockQuote.js",
+ "./lib/preventReferences.js",
"./batch.js",
"./template.js"
],
@@ -23,6 +25,8 @@
"./handlebars.runtime.min-v4.7.7.js",
"./lib/populateUrlMetadata.js",
"./lib/createFilters.js",
+ "./lib/addBlockQuote.js",
+ "./lib/preventReferences.js",
"./app.js",
"./template.js"
],
@@ -54,6 +58,8 @@
"handlebars.runtime.min-v4.7.7.js",
"lib/populateUrlMetadata.js",
"lib/createFilters.js",
+ "lib/addBlockQuote.js",
+ "lib/preventReferences.js",
"template.js",
"app.js",
"options.html",
diff --git a/tests/addBlockQuote.spec.js b/tests/addBlockQuote.spec.js
new file mode 100644
index 0000000..009c41a
--- /dev/null
+++ b/tests/addBlockQuote.spec.js
@@ -0,0 +1,10 @@
+const addBlockQuote = require('../lib/addBlockQuote')
+
+describe('addBlockQuote', () => {
+ it('adds block quotes to text', () => {
+ const originalText = 'This is text'
+
+ const blockQuoteText = addBlockQuote(originalText)
+ expect(blockQuoteText).toEqual(`> ${originalText}`)
+ })
+})
diff --git a/tests/preventReferences.spec.js b/tests/preventReferences.spec.js
new file mode 100644
index 0000000..2f58ceb
--- /dev/null
+++ b/tests/preventReferences.spec.js
@@ -0,0 +1,10 @@
+const preventReferences = require('../lib/preventReferences')
+
+describe('preventReferences', () => {
+ it('updates the url for github', () => {
+ const originalText = 'This is text with a url: https://github.com/'
+
+ const alteredText = preventReferences(originalText)
+ expect(alteredText).toEqual(`This is text with a url: https://www.github.com/`)
+ })
+})