Last active
May 20, 2020 09:34
-
-
Save bojanpopic/2c3025d2952844de1dd0 to your computer and use it in GitHub Desktop.
A (dirty) bash script that will backup issues from the GitHub repo using API. It takes pagination into consideration. Originally created by @boombatower. Done under a hour, so it can be improved (grep anyone?), but hey, it's one time script and it works. What more do you need? :)
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
#!/bin/bash | |
repo="" # put the name of the repo here. Usually it is like this: organization/repo-name | |
username="" # your github username | |
password="" # your github password | |
numberofpages= # leave blank for now and script will help you find the number of pages | |
if [ -z $numberofpages ] | |
then | |
echo "No number of pages set, lets find out how many pages are there" | |
# -I will give back only the headers without the data | |
curl -I -u "$username:$password" \ | |
"https://api.github.com/repos/$repo/issues?per_page=100&state=all" | |
echo "Look above and find something like rel='last'. Just before that there will be the number of the last page. Put it in the variable numberofpages;" | |
else | |
echo "OK, all set, dumping issues..." | |
echo | |
echo | |
for i in `eval echo {0..$numberofpages}` | |
do | |
filename=$(echo "$repo-issues-page$i.json" | tr / -) | |
curl -u $username:$password \ | |
"https://api.github.com/repos/$repo/issues?per_page=100&state=all&filter=all&page=$i" \ | |
> $filename | |
echo "Page $i finished..." | |
done | |
fi | |
This worked great but the issues were in reverse order. Anyone know an easy fix?
Cool, works well, thanks. A few notes:
-
you can use this to dump a repo you don't own, as long as it's public access. I wasn't understanding this at first, since a password is needed...
-
if you change everywhere it says
issues
topulls
, you get your Pull Requests :-)
In case anybody's interested... I just updated this on my fork with a version that handles number of pages automatically.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Works for me! Thanks 👍