Skip to content

Instantly share code, notes, and snippets.

@bojanpopic
Last active May 20, 2020 09:34
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save bojanpopic/2c3025d2952844de1dd0 to your computer and use it in GitHub Desktop.
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? :)
#!/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
@WebDevJL
Copy link

WebDevJL commented Feb 5, 2016

Works for me! Thanks 👍

@newswim
Copy link

newswim commented Feb 8, 2017

This worked great but the issues were in reverse order. Anyone know an easy fix?

@pgorod
Copy link

pgorod commented Jul 6, 2017

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 to pulls, you get your Pull Requests :-)

@pgorod
Copy link

pgorod commented Jul 14, 2017

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