Last active
August 29, 2015 13:57
-
-
Save ksomemo/9887346 to your computer and use it in GitHub Desktop.
guthub apiを使ってフォークしていないリポジトリをCloneし、アカウントと違うコミッターが含まれるリポジトリを残す。
This file contains hidden or 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
| # coding: utf-8 | |
| import sys | |
| import requests | |
| import subprocess | |
| def main(): | |
| """ | |
| guthub apiを使ってフォークしていないリポジトリをCloneし、 | |
| アカウントと違うコミッターが含まれるリポジトリを残す。 | |
| http://developer.github.com/v3/ | |
| requests from pip install requests | |
| """ | |
| if len(sys.argv) <= 2: | |
| raise Exception('引数はファイル名を含めて3つ以上必要です.' + str(len(sys.argv))) | |
| user = sys.argv[1] | |
| passwd = sys.argv[2] | |
| auth_token = sys.argv[3] | |
| committer = sys.argv[4] | |
| # requests.models.Response | |
| # res = requests.get('https://api.github.com', auth=(user, passwd)) | |
| headers={'Authorization': 'token %s' % auth_token} | |
| res = requests.get('https://api.github.com', headers=headers) | |
| print 'status code is %d' % res.status_code | |
| res = requests.get('https://api.github.com/users/%s/repos' % user) | |
| # res2json's type is dict | |
| for rep in res.json(): | |
| if rep['fork'] == True: | |
| continue | |
| args = ['git', 'clone', 'https://github.com/%s.git' % rep['full_name']] | |
| p = subprocess.Popen(args) | |
| p.wait() | |
| print 'clone end' | |
| try: | |
| p_log = subprocess.Popen(['git', '--git-dir=%s/.git' % rep['name'], 'log', '--pretty=full'], stdout=subprocess.PIPE) | |
| output = subprocess.check_output(('grep', committer), stdin=p_log.stdout) | |
| p_log.wait() | |
| except subprocess.CalledProcessError: | |
| # no output | |
| # shutil.rmtree(rep['name']) # WindowsError | |
| p_rm = subprocess.Popen(['rm', '-rf', rep['name']]) | |
| p_rm.wait() | |
| else: | |
| print output | |
| if __name__ == '__main__': | |
| main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment