Skip to content

Commit

Permalink
Merge pull request #123 from gatewayapps/121/clone-comments
Browse files Browse the repository at this point in the history
121/clone comments
  • Loading branch information
johnmurphy01 authored Apr 2, 2019
2 parents 1e8df57 + a2d4abd commit e09d1d8
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 11 deletions.
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,17 @@ Once you have your PAT, enter it on the Options screen for Kamino and click `Sav

# Features

## Settings
- `Go to original repo's issue list after cloning` will navigate to the issue list for the repo from which the cloning was done
- `Create tab for cloned issue` will open a new tab and navigate to the newly cloned issue
- `Copy comments when cloning issue` will copy all comments when the issue is cloned

## Normal operations
Clicking this button will display a dropdown list of repos. Selecting a repo will ask you to perform one of the following actions:
- `Clone and Close` will clone the issue and automatically close the original issue
- `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.
- `Nevermind` will close the modal and no action will be performed

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.

## Last used
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!

Expand Down
37 changes: 35 additions & 2 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -303,9 +303,42 @@ function getGithubIssue(repo, closeOriginal) {

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

ajaxRequest('POST', newIssue, `https://api.github.com/repos/${repo}/issues`).then((response) => {
// add a comment to the closed issue
commentOnIssue(repo, oldIssue, response.data, closeOriginal)
// 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 cloneOldIssueComments(newIssue, repo, url) {
return ajaxRequest('GET', '', url).then((comments) => {
chrome.storage.sync.get({
cloneComments: false
}, (item) => {
if (!item.cloneComments) {
return Promise.resolve(null)
}

if (!comments || !comments.data || comments.data.length === 0) {
return Promise.resolve(null)
}

const promises = []
comments.data.forEach((comment) => {
const c = {
body: comment.body
}
promises.push(ajaxRequest('POST', c, `https://api.github.com/repos/${repo}/issues/${newIssue}/comments`))
})

Promise.all(promises).then((res) => {
return Promise.resolve({})
})
})
})
}

Expand Down
4 changes: 2 additions & 2 deletions manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
"webNavigation",
"*://github.com/*"
],
"version": "2.9.2",
"version": "2.10.0",
"web_accessible_resources":[
"icons/*.png",
"bootstrap/js/bootstrap.min.js",
Expand All @@ -48,4 +48,4 @@
"options.js",
"background.js"
]
}
}
8 changes: 6 additions & 2 deletions options.html
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,16 @@ <h2 id="generaloptions">General Settings</h2>
</div>

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

<div class="checkbox">
<label><input type="checkbox" id="create-tab">Create tab for cloned issue</label>
</div>

<div class="checkbox">
<label><input type="checkbox" id="clone-comments">Copy comments when cloning issue</label>
</div>
</div>

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

</html>
</html>
10 changes: 7 additions & 3 deletions options.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@ function save_options() {
var token = document.getElementById('github-pat').value;
var goToList = document.getElementById('go-to-issue-list').checked;
var createTab = document.getElementById('create-tab').checked;
var cloneComments = document.getElementById('clone-comments').checked;

chrome.storage.sync.set({
githubToken: token,
goToList: goToList,
createTab: createTab
createTab: createTab,
cloneComments: cloneComments
}, function() {
// Update status to let user know options were saved.
var status = document.getElementById('status');
Expand All @@ -27,16 +29,18 @@ function restore_options() {
chrome.storage.sync.get({
githubToken: '',
goToList: false,
createTab: true
createTab: true,
cloneComments: 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.addEventListener('DOMContentLoaded', restore_options);
document.getElementById('saveButton').addEventListener('click',
save_options);
document.getElementById('paypal-button').addEventListener('click',
paypal_donate);
paypal_donate);

0 comments on commit e09d1d8

Please sign in to comment.