Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option to prevent references on the original issue. #189

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,7 @@
"Repos",
"kamino",
"linkstring"
]
],
"html.format.indentInnerHtml": true,
"html.format.wrapAttributes": "preserve"
}
72 changes: 43 additions & 29 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ function initializeExtension() {
$('.noClone').click(() => {
closeModal()
})
}
}
}

function saveAppliedFilters(urlObj) {
Expand Down Expand Up @@ -162,7 +162,7 @@ function saveAppliedFilters(urlObj) {
{
filters: item.filters,
},
() => {}
() => { }
)
}
}
Expand Down Expand Up @@ -211,7 +211,7 @@ function loadRepos() {

// create a way to go to options without using the extension context menu
$('.kamino-heading').click(() => {
chrome.runtime.sendMessage({ action: 'goToOptions' }, (response) => {})
chrome.runtime.sendMessage({ action: 'goToOptions' }, (response) => { })
})

// if there's no personal access token, disable the button
Expand All @@ -231,7 +231,7 @@ function loadRepos() {
$('.repoDropdown').append('<li class="dropdown-header dropdown-header-used">Last Used</li>')
$('.repoDropdown').append('<li class="dropdown-header dropdown-header-rest">The Rest</li>')

getRepos('https://api.github.com/user/repos?per_page=100').then(() => {})
getRepos('https://api.github.com/user/repos?per_page=100').then(() => { })
}

function compileRepositoryList(list, searchTerm) {
Expand Down Expand Up @@ -312,39 +312,53 @@ function getGithubIssue(repo, closeOriginal) {
'',
`https://api.github.com/repos/${urlObj.organization}/${urlObj.currentRepo}/issues/${urlObj.issueNumber}`
).then((issue) => {
// build new issue
const newIssue = {
title: issue.data.title,
body: `From ${urlObj.currentRepo} created by [${issue.data.user.login}](${issue.data.user.html_url}): ${urlObj.organization}/${urlObj.currentRepo}#${urlObj.issueNumber} \n\n${issue.data.body}`,
labels: issue.data.labels,
}

createGithubIssue(newIssue, repo, issue.data, closeOriginal)
createGithubIssue(repo, issue.data, closeOriginal)
})
}

// create the cloned GitHub issue
function createGithubIssue(newIssue, repo, oldIssue, closeOriginal) {
function createGithubIssue(repo, oldIssue, closeOriginal) {
const urlObj = populateUrlMetadata()

ajaxRequest('POST', newIssue, `https://api.github.com/repos/${repo}/issues`).then((response) => {
// clone comments from old issue to new issue
cloneOldIssueComments(
response.data.number,
repo,
`https://api.github.com/repos/${urlObj.organization}/${urlObj.currentRepo}/issues/${urlObj.issueNumber}/comments?per_page=100`
).then((res) => {
// add a comment to the closed issue
commentOnIssue(repo, oldIssue, response.data, closeOriginal)
chrome.storage.sync.get(
{
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}`;

// build new issue
const newIssue = {
title: oldIssue.title,
body: item.preventReferences ? preventReferences(newIssueBody) : newIssueBody,
labels: oldIssue.labels,
}

ajaxRequest('POST', newIssue, `https://api.github.com/repos/${repo}/issues`).then((response) => {
// clone comments from old issue to new issue
cloneOldIssueComments(
response.data.number,
repo,
`https://api.github.com/repos/${urlObj.organization}/${urlObj.currentRepo}/issues/${urlObj.issueNumber}/comments?per_page=100`
).then((res) => {
// add a comment to the closed issue
commentOnIssue(repo, oldIssue, response.data, 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(
{
cloneComments: false,
preventReferences: false,
},
(item) => {
if (!item.cloneComments) {
Expand All @@ -358,13 +372,13 @@ function cloneOldIssueComments(newIssue, repo, url) {
comments.data.reduce(
(p, comment) => p.then(_ => {
const c = {
body: comment.body,
body: item.preventReferences ? preventReferences(comment.body) : comment.body,
}
return ajaxRequest('POST', c, `https://api.github.com/repos/${repo}/issues/${newIssue}/comments`)
}),
Promise.resolve()
).then((res) => {
return Promise.resolve({})
).then((res) => {
return Promise.resolve({})
})
}
)
Expand All @@ -382,7 +396,7 @@ function closeGithubIssue(oldIssue) {
'PATCH',
issueToClose,
`https://api.github.com/repos/${urlObj.organization}/${urlObj.currentRepo}/issues/${urlObj.issueNumber}`
).then((done) => {})
).then((done) => { })
}

function commentOnIssue(repo, oldIssue, newIssue, closeOriginal) {
Expand Down Expand Up @@ -426,7 +440,7 @@ function goToIssueList(repo, issueNumber, org, oldRepo) {
// based on user settings, determines if the issues list will open after a clone or not
chrome.runtime.sendMessage(
{ repo: repo, issueNumber: issueNumber, organization: org, oldRepo: oldRepo },
(response) => {}
(response) => { }
)
}

Expand Down Expand Up @@ -538,7 +552,7 @@ function addToMostUsed(repo) {
{
mostUsed: item.mostUsed,
},
(done) => {}
(done) => { }
)
}
)
Expand Down
26 changes: 16 additions & 10 deletions options.html
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
<!DOCTYPE html>
<html>

<head>
<title>Kamino Settings</title>
<link rel="stylesheet" href="css/options.css" />
<link
href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css"
rel="stylesheet"
integrity="sha384-eOJMYsd53ii+scO/bJGFsiCZc+5NDVN2yr8+0RDqr0Ql0h+rP48ckxlpbzKgwra6"
crossorigin="anonymous"
/>
crossorigin="anonymous" />
</head>

<body>
Expand Down Expand Up @@ -42,7 +42,8 @@ <h2 id="generaloptions">General Settings</h2>
</div>

<div class="checkbox">
<label><input class="me-2" type="checkbox" id="go-to-issue-list" />Go to original repo's issue list after cloning</label>
<label><input class="me-2" type="checkbox" id="go-to-issue-list" />Go to original repo's issue list after
cloning</label>
</div>

<div class="checkbox">
Expand All @@ -54,10 +55,15 @@ <h2 id="generaloptions">General Settings</h2>
</div>

<div class="checkbox">
<label
><input class="me-2" type="checkbox" id="disable-comment-on-original" />Disable Kamino automatic comments on original
issue</label
>
<label><input class="me-2" type="checkbox" id="disable-comment-on-original" />Disable Kamino automatic
comments on original issue</label>
</div>

<div class="checkbox">
<label><input class="me-2" type="checkbox" id="prevent-references" />Prevent references to cloned issue on
original issue
(using <a href="https://github.com/orgs/community/discussions/23123#discussioncomment-3239240">this hacky
method</a>)</label>
</div>
</div>

Expand All @@ -77,8 +83,8 @@ <h2 id="generaloptions">General Settings</h2>
<script
src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"
integrity="sha384-JEW9xMcG8R+pH31jmWH6WWP0WintQrMb4s7ZOdauHnUtxwoG2vI5DkLtS3qm9Ekf"
crossorigin="anonymous"
></script>
crossorigin="anonymous"></script>
<script src="options.js"></script>
</body>
</html>

</html>
4 changes: 4 additions & 0 deletions options.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ function save_options() {
const createTab = document.getElementById('create-tab').checked
const cloneComments = document.getElementById('clone-comments').checked
const disableCommentsOnOriginal = document.getElementById('disable-comment-on-original')
const preventReferences = document.getElementById('prevent-references')

chrome.storage.sync.set(
{
Expand All @@ -13,6 +14,7 @@ function save_options() {
createTab,
cloneComments,
disableCommentsOnOriginal,
preventReferences
},
function () {
// Update status to let user know options were saved.
Expand All @@ -38,13 +40,15 @@ function restore_options() {
createTab: true,
cloneComments: false,
disableCommentsOnOriginal: false,
preventReferences: false,
},
function (items) {
document.getElementById('github-pat').value = items.githubToken
document.getElementById('go-to-issue-list').checked = items.goToList
document.getElementById('create-tab').checked = items.createTab
document.getElementById('clone-comments').checked = items.cloneComments
document.getElementById('disable-comment-on-original').checked = items.disableCommentsOnOriginal
document.getElementById('prevent-references').checked = items.preventReferences
}
)
}
Expand Down
17 changes: 10 additions & 7 deletions templates/button.handlebars
Original file line number Diff line number Diff line change
@@ -1,21 +1,24 @@
<div class="discussion-sidebar-item sidebar-kamino">
<button class="discussion-sidebar-heading kamino-heading discussion-sidebar-toggle js-menu-target">
<svg class="octicon octicon-gear" viewBox="0 0 14 16" version="1.1" width="14" height="16" aria-hidden="true">
<path fill-rule="evenodd" d="M14 8.77v-1.6l-1.94-.64-.45-1.09.88-1.84-1.13-1.13-1.81.91-1.09-.45-.69-1.92h-1.6l-.63 1.94-1.11.45-1.84-.88-1.13 1.13.91 1.81-.45 1.09L0 7.23v1.59l1.94.64.45 1.09-.88 1.84 1.13 1.13 1.81-.91 1.09.45.69 1.92h1.59l.63-1.94 1.11-.45 1.84.88 1.13-1.13-.92-1.81.47-1.09L14 8.75v.02zM7 11c-1.66 0-3-1.34-3-3s1.34-3 3-3 3 1.34 3 3-1.34 3-3 3z"></path>
</svg>
Kamino
<svg class="octicon octicon-gear" viewBox="0 0 14 16" version="1.1" width="14" height="16" aria-hidden="true">
<path fill-rule="evenodd"
d="M14 8.77v-1.6l-1.94-.64-.45-1.09.88-1.84-1.13-1.13-1.81.91-1.09-.45-.69-1.92h-1.6l-.63 1.94-1.11.45-1.84-.88-1.13 1.13.91 1.81-.45 1.09L0 7.23v1.59l1.94.64.45 1.09-.88 1.84 1.13 1.13 1.81-.91 1.09.45.69 1.92h1.59l.63-1.94 1.11-.45 1.84.88 1.13-1.13-.92-1.81.47-1.09L14 8.75v.02zM7 11c-1.66 0-3-1.34-3-3s1.34-3 3-3 3 1.34 3 3-1.34 3-3 3z">
</path>
</svg>
Kamino
</button>

<div class="btn-group" role="group">
<button type="button" class="btn btn-sm btn-primary quickClone">Clone to</button>
<button type="button" class="btn btn-sm btn-primary dropdown-toggle kaminoButton" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
<button type="button" class="btn btn-sm btn-primary dropdown-toggle kaminoButton" data-toggle="dropdown"
aria-haspopup="true" aria-expanded="false">
<span class="caret"></span>
<span class="sr-only">Toggle Dropdown</span>
</button>

<div class="dropdown-menu repoDropdownContainer">
<input class="repoSearch" type="text" placeholder="Search for a repo..." />
<hr/>
<hr />
<ul class="repoDropdown"></ul>
</div>
</div>
Expand Down
6 changes: 4 additions & 2 deletions templates/modal.handlebars
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@
<p class="confirmText">{{confirmText}}</p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-primary cloneAndClose" style="margin-right:20px;" data-dismiss="modal" data-repo="">Clone and Close</button>
<button type="button" class="btn btn-primary cloneAndKeepOpen" style="margin-right:20px;" data-dismiss="modal" data-repo="">Just Clone</button>
<button type="button" class="btn btn-primary cloneAndClose" style="margin-right:20px;"
data-dismiss="modal" data-repo="">Clone and Close</button>
<button type="button" class="btn btn-primary cloneAndKeepOpen" style="margin-right:20px;"
data-dismiss="modal" data-repo="">Just Clone</button>
<button type="button" class="btn btn-info noClone" data-dismiss="modal">Nevermind</button>
</div>
</div>
Expand Down