Last active
February 22, 2016 18:36
-
-
Save Rplus/63d9c66afa6bd35b778e to your computer and use it in GitHub Desktop.
backup github issues & comments
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* globals fetch, confirm, prompt, location */ | |
// How to use: | |
// | |
// 0. save the code below into your bookmark as a bookmarklet | |
// 1. go to target repo | |
// 2. click the bookmarklet in your Chrome | |
// 3. open console panel in devtool | |
// 4. enter `copy(githubIssues)` | |
// 5. paste directly in your text editor and save it!! ALL DONE! | |
javascript: (function () { | |
'use strict'; | |
let repoUrl = location.href; | |
let user; | |
let repo; | |
(function checkRepoUrl () { | |
let isInRepo = repoUrl.match(/\/\/github\.com\/([^/]+?)\/([^/]+)/); | |
if (isInRepo) { | |
user = isInRepo[1]; | |
repo = isInRepo[2]; | |
} else { | |
repoUrl = prompt('enter target repo:'); | |
checkRepoUrl(); | |
} | |
})(); | |
if (!confirm(`你要備份的 issues 是這一個嗎?\n* User: ${user}\n* Repo: ${repo}`)) { | |
return; | |
} | |
let apiUrl = `https://api.github.com/repos/${user}/${repo}/issues?per_page=100&page=1`; | |
fetch(apiUrl) | |
.then((response) => { | |
if (response.status !== 200) { | |
console.log('Looks like there was a problem. Status Code: ' + response.status); | |
return; | |
} | |
response.json().then((issues) => { | |
issues.forEach((issue) => { | |
if (issue.comments) { | |
fetch(issue.comments_url) | |
.then((commentsResponse) => { | |
commentsResponse.json() | |
.then((comments_content) => { | |
issue.comments_content = comments_content; | |
}); | |
}) | |
.catch((err) => { | |
console.log('Fetch Error :-S', err); | |
}); | |
} | |
}); | |
return issues; | |
}) | |
.then((issues) => { | |
window.githubIssues = issues; | |
console.log('Backup issues success!', issues); | |
}); | |
}) | |
.catch((err) => { | |
console.log('Fetch Error :-S', err); | |
}); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment