Author Topic: Pulling all Github repositories at once  (Read 3174 times)

0 Members and 1 Guest are viewing this topic.

Offline homebrewTopic starter

  • Frequent Contributor
  • **
  • Posts: 293
  • Country: ch
Pulling all Github repositories at once
« on: May 12, 2017, 06:19:33 am »
In case anybody would ever have the need to pull ALL KiCad repositories and be sure to catch all, here's how:
Code: [Select]
$ curl -s https://api.github.com/orgs/KiCad/repos?per_page=1000  | grep "svn_url" | grep ".pretty" | cut -d " " -f 6 | sed -e "s/\"\(.*\)\".*/\1/g" | sort | while read line; do git clone $line; done

This clones all available .pretty git repositories.

I prefer this approach over the premade lists that circulate around as this is always up to date ...

Modify: Corrected the script as it was mangled by the blog. Added support for direct cloning
« Last Edit: May 13, 2017, 05:19:39 am by homebrew »
 

Offline donotdespisethesnake

  • Super Contributor
  • ***
  • Posts: 1093
  • Country: gb
  • Embedded stuff
Re: Pulling all Github repositories at once
« Reply #1 on: May 13, 2017, 10:13:36 am »
You can ask for 1000, but github only returns max of 100 results, you have to get multiple pages.  As there are already over 100 repos, your one liner will miss some.

Another way is to use https://github.com/hairymnstr/kicad-getlibs, which also updates the library table for you.

Of course, if you just want a local copy of the footprints without a git clone, you can download them using KiCad.
Bob
"All you said is just a bunch of opinions."
 
The following users thanked this post: homebrew

Offline NivagSwerdna

  • Super Contributor
  • ***
  • Posts: 2495
  • Country: gb
Re: Pulling all Github repositories at once
« Reply #2 on: May 13, 2017, 10:25:57 am »
If you don't need history and only a single branch then do a shallow copy

git clone --depth 1 https://path/to/repo/foo.git -b bar



 
The following users thanked this post: homebrew

Offline homebrewTopic starter

  • Frequent Contributor
  • **
  • Posts: 293
  • Country: ch
Re: Pulling all Github repositories at once
« Reply #3 on: May 14, 2017, 12:47:00 pm »
You can ask for 1000, but github only returns max of 100 results, you have to get multiple pages.  As there are already over 100 repos, your one liner will miss some.

Ah,  :palm: stupid me! Didn't check ...

So here's the updated one-liner:
Code: [Select]
$ lastpage=$(curl -s -I https://api.github.com/orgs/KiCad/repos  | grep "Link:" | sed -e "s/.*page=\(.*\)>; rel=\"last\".*/\1/g"); for ((page=1;page<=$lastpage;page++)); do curl -s https://api.github.com/orgs/KiCad/repos?page=$page  | grep "svn_url" | grep ".pretty" | cut -d " " -f 6 | sed -e "s/\"\(.*\)\".*/\1/g"; done | sort | while read line; do git clone --depth 1 $line; done
Or in a more readable form to put in a script file:
Code: [Select]
#!/bin/bash

lastpage=$(\
        curl -s -I https://api.github.com/orgs/KiCad/repos  \
        | grep "Link:" \
        | sed -e "s/.*page=\(.*\)>; rel=\"last\".*/\1/g"\
        )
for ((page=1;page<=$lastpage;page++));
do
        curl -s https://api.github.com/orgs/KiCad/repos?page=$page  \
                | grep "svn_url" \
                | grep ".pretty" \
                | cut -d " " -f 6 \
                | sed -e "s/\"\(.*\)\".*/\1/g";
done | sort | while read line;
do
        git clone --depth 1 $line;
done
« Last Edit: May 14, 2017, 02:39:03 pm by homebrew »
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf