简体   繁体   中英

How to clone and pull all repositories from an Organization?

我看到一些使用github的API来检索库列表的实现,但就我而言,并没有抓住所有实现。

Just in case someone is interested, I wrote a small bash file to do this, hope it helps.

Replace XXXXXXXX with the name of your target organization

#!/bin/bash
python3 << END

import re
import urllib.request


ORGANIZATION = "XXXXXXXX"
URL_BASE = "https://github.com/{}?page=".format(ORGANIZATION)
URL_CLONE = "https://github.com/{}/{}.git"


page = 1
libraries = True
urls = []
while libraries:
    url = URL_BASE + str(page)
    resp = urllib.request.urlopen(url)
    code = ''
    if resp.code == 200:
        resp_bytes = resp.read()
        code = resp_bytes.decode("utf8")
        resp.close()
    libraries = re.findall('href="/{}/([^"]+)[^>]+codeRepository'.format(ORGANIZATION), code)
    for library in libraries:
        url = URL_CLONE.format(ORGANIZATION, library)
        urls.append(url)
    page += 1


with open('libraries.txt', 'w', encoding='utf-8') as ofile:
    ofile.write('\n'.join(urls))

END

while read i; do
  git clone $i || echo "    Error while cloning, probably already exists"
done <libraries.txt

ls -d */ | xargs -I{} git -C {} pull

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM