Download all StackExchange git repos

-8

Introduction

We all love StackExchange, therefore it would be essential to download all gems hidden on Stack Overflow repositories in the simplest possible way.

Challenge/Task

Your task is to write a script or program which would:

  1. Fetch the list of all (within current page) repositories under Stack Overflow GitHub account. This can be achieved either by using direct link, or by using API callback (in JSON format). Example URLs for public access:

    https://github.com/StackExchange
    https://api.github.com/users/StackExchange/repos
    
  2. Parse the list either from HTML, JSON or whatever format you would have into standard git URL format (recognised by git), such as:

    https://github.com/StackExchange/foo.git
    https://github.com/StackExchange/foo
    git@github.com:StackExchange/foo.git
    

    The last one assumes that your public key is already added.

  3. For each repository, git clone needs to be executed/invoked, for example:

    git clone URL_to_1st_repo
    git clone URL_to_2nd_repo
    ...
    
  4. All repositories are cloned (destination doesn't matter) and should be present (not just echoed or silently processed).

Assumptions

  • We're assuming all necessary standard tools are installed (e.g. git command) and it's in your PATH..
  • Assume that github.com fingerprint is already added into your system, e.g.

    ssh-keyscan -H github.com >> ~/.ssh/known_hosts
    
  • Assume that your public key to access the remote repository has been added to the system (this is only required when accessing via git@).

  • We are not assuming any page or API rate limits.

Rules & Requirements

  • Smallest working/reproducible code with positive score wins.
  • After execution, all repositories should be cloned and the script/program must exit without crashing.
  • You can import libraries, but they must be made before the challenge. However, you're not allowed to alias libraries to make them shorter to use in your code. All libraries/tools which are provided by ubuntu/vivid64 sandbox (specified below) are not necessary to mention.
  • All used languages or tools needs to be at least 1 year old to prevent too narrow submissions.

Examples

You can find some useful examples at: How to clone all repos at once from Git.

Sandboxes

  • if you've got Vagrant installed, try running:

    vagrant init ubuntu/vivid64 && vagrant up --provider virtualbox && vagrant ssh
    
  • OpenRISC OR1K Javascript Emulator - Running Linux With Network Support

    However the curl doesn't always seems to work there (e.g. curl -v ifconfig.co).

kenorb

Posted 2015-09-27T14:18:19.700

Reputation: 398

Is there a reason to make the winner have to have at least 5 upvotes to win? Also, why does the language have to be a year old to compete? – Blue – 2015-09-27T14:24:53.737

@muddyfish For the reason of potential cheating. If somebody finds some loophole which hasn't been mentioned yet and people won't like the solution, the downvotes should sort that out. So there is not possibility of the winner with 1-2 byte of code (claiming that it magically works somehow) and having negative number of votes at the same time. In other words, the winner should be approved by the community in some way. – kenorb – 2015-09-27T14:31:50.633

1

Have you looked at the standard loopholes?

– Blue – 2015-09-27T14:33:36.030

@muddyfish I'm fairly new into writing some challenges, so thanks for pointing that out. But still applies if somebody will use some 1-5 byte of code by installing some magic libraries, so it won't be a standard loophole. So I think the score should be at some point an important factor, otherwise there is no point of voting the answers. Sorry if I'm introducing something new, this can be taken off if this rule is not well received. I believe the answer should be matured enough at some point to be accepted. – kenorb – 2015-09-27T14:39:00.983

1I'm pretty sure you're not allowed to use libraries written after the challenge either. – Blue – 2015-09-27T14:40:53.460

2If you trust the community to upvote only valid answers, you can also trust it to downvote and delete cheating answers. The score and age requirements seem unnecessary to me. – Dennis – 2015-09-27T15:16:31.463

@Dennis Changed to positive score if that's better. – kenorb – 2015-09-27T15:19:37.157

That is better. Personally, I'd eliminate the extra requirements (score, age of language) altogether, but it's your challenge... – Dennis – 2015-09-27T15:21:19.543

@Dennis Thanks. I wouldn't like to see the solution to work on some languages which were created a month ago, as it wouldn't be useful in some real life usage. So I'm expecting to see the solutions by using already matured tools/commands/languages. Just securing challenge for any ambiguity which I could think of which would be not expected. – kenorb – 2015-09-27T15:33:44.153

3Usability should be a minor concern in code golf. The shortest solution is almost never the most useful one. Take my answer, for example: It tries to clone every whitespace-delimited string in the JSON-file, so it makes a lot of unnecessary network requests and takes a lot longer than it should. – Dennis – 2015-09-27T15:59:46.197

@Dennis When testing, I'm usually dumping curl request into file and trying to parse the static file and checking for the right output, so the requests are only done twice on initial and final testing. GitHub has necessary API limitations, so it won't allow you to abuse their server much. So as you can see, I forgot on another loopholes, which is preventing fetching invalid repos:) So not good practical usage, but at least your example works:) – kenorb – 2015-09-27T16:11:52.723

3Dennis is right about the extraneous requirements. What you gain in loophole haters you'll lose in TL;DRers. – Calvin's Hobbies – 2015-09-27T18:53:46.400

Answers

4

Bash, 81 bytes

curl https://api.github.com/users/StackExchange/repos|tr -d ,|xargs -n1 git clone

Git will be fed a lot of invalid repos, but it will happily clone the valid ones.

Dennis

Posted 2015-09-27T14:18:19.700

Reputation: 196 637

1

sh (92 characters)

Example using Linux shell:

curl https://api.github.com/orgs/StackExchange/repos|grep -o 'git@[^"]*'|xargs -L1 git clone

And alternative version sh, but 94 characters:

grep -o 'git@[^"]*'|xargs -L1 git clone<(curl https://api.github.com/orgs/StackExchange/repos)

Explanation

Downloads API page via curl, extracts URLs which starts with git@, then execute git clone for each match.

kenorb

Posted 2015-09-27T14:18:19.700

Reputation: 398