Skip to content

Commit e09d1d8

Browse files
authored
Merge pull request #123 from gatewayapps/121/clone-comments
121/clone comments
2 parents 1e8df57 + a2d4abd commit e09d1d8

File tree

5 files changed

+55
-11
lines changed

5 files changed

+55
-11
lines changed

README.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,17 @@ Once you have your PAT, enter it on the Options screen for Kamino and click `Sav
1111

1212
# Features
1313

14+
## Settings
15+
- `Go to original repo's issue list after cloning` will navigate to the issue list for the repo from which the cloning was done
16+
- `Create tab for cloned issue` will open a new tab and navigate to the newly cloned issue
17+
- `Copy comments when cloning issue` will copy all comments when the issue is cloned
18+
1419
## Normal operations
1520
Clicking this button will display a dropdown list of repos. Selecting a repo will ask you to perform one of the following actions:
1621
- `Clone and Close` will clone the issue and automatically close the original issue
1722
- `Just Clone` will clone the issue and keep the original issue open. This is useful if you've got shared code bases across repos and the issue is similar or the same across repos.
1823
- `Nevermind` will close the modal and no action will be performed
1924

20-
There are user settings for opening the new issue in a tab as well as navigating back to the original issue's repository issues list and these things will happen after Kamino has cloned the issue. Check the `Options` screen where your Personal Access Token was entered and saved.
21-
2225
## Last used
2326
Kamino will remember the last 5 repositories you cloned to so that it will be easy for you to find. If you are someone that is a member of a lot of repos, this should be very handy!
2427

app.js

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -303,9 +303,42 @@ function getGithubIssue(repo, closeOriginal) {
303303

304304
// create the cloned GitHub issue
305305
function createGithubIssue(newIssue, repo, oldIssue, closeOriginal) {
306+
const urlObj = populateUrlMetadata()
307+
306308
ajaxRequest('POST', newIssue, `https://api.github.com/repos/${repo}/issues`).then((response) => {
307-
// add a comment to the closed issue
308-
commentOnIssue(repo, oldIssue, response.data, closeOriginal)
309+
// clone comments from old issue to new issue
310+
cloneOldIssueComments(response.data.number, repo, `https://api.github.com/repos/${urlObj.organization}/${urlObj.currentRepo}/issues/${urlObj.issueNumber}/comments?per_page=100`).then((res) => {
311+
// add a comment to the closed issue
312+
commentOnIssue(repo, oldIssue, response.data, closeOriginal)
313+
})
314+
})
315+
}
316+
317+
function cloneOldIssueComments(newIssue, repo, url) {
318+
return ajaxRequest('GET', '', url).then((comments) => {
319+
chrome.storage.sync.get({
320+
cloneComments: false
321+
}, (item) => {
322+
if (!item.cloneComments) {
323+
return Promise.resolve(null)
324+
}
325+
326+
if (!comments || !comments.data || comments.data.length === 0) {
327+
return Promise.resolve(null)
328+
}
329+
330+
const promises = []
331+
comments.data.forEach((comment) => {
332+
const c = {
333+
body: comment.body
334+
}
335+
promises.push(ajaxRequest('POST', c, `https://api.github.com/repos/${repo}/issues/${newIssue}/comments`))
336+
})
337+
338+
Promise.all(promises).then((res) => {
339+
return Promise.resolve({})
340+
})
341+
})
309342
})
310343
}
311344

manifest.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
"webNavigation",
3636
"*://github.com/*"
3737
],
38-
"version": "2.9.2",
38+
"version": "2.10.0",
3939
"web_accessible_resources":[
4040
"icons/*.png",
4141
"bootstrap/js/bootstrap.min.js",
@@ -48,4 +48,4 @@
4848
"options.js",
4949
"background.js"
5050
]
51-
}
51+
}

options.html

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,16 @@ <h2 id="generaloptions">General Settings</h2>
4040
</div>
4141

4242
<div class="checkbox">
43-
<label><input type="checkbox" id="go-to-issue-list">Go to organization's issue list after cloning</label>
43+
<label><input type="checkbox" id="go-to-issue-list">Go to original repo's issue list after cloning</label>
4444
</div>
4545

4646
<div class="checkbox">
4747
<label><input type="checkbox" id="create-tab">Create tab for cloned issue</label>
4848
</div>
49+
50+
<div class="checkbox">
51+
<label><input type="checkbox" id="clone-comments">Copy comments when cloning issue</label>
52+
</div>
4953
</div>
5054

5155
<p>
@@ -64,4 +68,4 @@ <h2 id="generaloptions">General Settings</h2>
6468
<script src="options.js"></script>
6569
</body>
6670

67-
</html>
71+
</html>

options.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,13 @@ function save_options() {
33
var token = document.getElementById('github-pat').value;
44
var goToList = document.getElementById('go-to-issue-list').checked;
55
var createTab = document.getElementById('create-tab').checked;
6+
var cloneComments = document.getElementById('clone-comments').checked;
67

78
chrome.storage.sync.set({
89
githubToken: token,
910
goToList: goToList,
10-
createTab: createTab
11+
createTab: createTab,
12+
cloneComments: cloneComments
1113
}, function() {
1214
// Update status to let user know options were saved.
1315
var status = document.getElementById('status');
@@ -27,16 +29,18 @@ function restore_options() {
2729
chrome.storage.sync.get({
2830
githubToken: '',
2931
goToList: false,
30-
createTab: true
32+
createTab: true,
33+
cloneComments: false
3134
}, function(items) {
3235
document.getElementById('github-pat').value = items.githubToken;
3336
document.getElementById('go-to-issue-list').checked = items.goToList;
3437
document.getElementById('create-tab').checked = items.createTab;
38+
document.getElementById('clone-comments').checked = items.cloneComments;
3539
});
3640
}
3741

3842
document.addEventListener('DOMContentLoaded', restore_options);
3943
document.getElementById('saveButton').addEventListener('click',
4044
save_options);
4145
document.getElementById('paypal-button').addEventListener('click',
42-
paypal_donate);
46+
paypal_donate);

0 commit comments

Comments
 (0)