|
| 1 | +# coding: utf-8 |
| 2 | + |
| 3 | +import subprocess |
| 4 | + |
| 5 | +import requests |
| 6 | + |
| 7 | + |
| 8 | +def git_clone(repository_url, path_to_save): |
| 9 | + ''' Clone a Git repository using `git` binary ''' |
| 10 | + subprocess.call(['git', 'clone', repository_url, path_to_save]) |
| 11 | + |
| 12 | + |
| 13 | +def git_tag_list(repo_path): |
| 14 | + return subprocess.check_output("git tag -l".split(), cwd=repo_path).splitlines() |
| 15 | + |
| 16 | + |
| 17 | +def git_checkout(repo_path, rev): |
| 18 | + return subprocess.call(["git", "checkout", rev], cwd=repo_path) |
| 19 | + |
| 20 | + |
| 21 | +def git_reset_head(repo_path): |
| 22 | + return subprocess.call("git reset --hard".split(), cwd=repo_path) |
| 23 | + |
| 24 | + |
| 25 | +def git_current_branch(repo_path): |
| 26 | + return subprocess.check_output("git rev-parse --abbrev-ref " |
| 27 | + "HEAD".split(), cwd=repo_path).strip() |
| 28 | + |
| 29 | + |
| 30 | +def git_count_authors(repo_path): |
| 31 | + return len(subprocess.check_output("git shortlog -s -n".split(), |
| 32 | + cwd=repo_path).splitlines()) |
| 33 | + |
| 34 | + |
| 35 | +def git_count_commits(repo_path): |
| 36 | + return int(subprocess.check_output("git rev-list HEAD --count".split(), |
| 37 | + cwd=repo_path).strip()) |
| 38 | + |
| 39 | + |
| 40 | +def git_last_commit_date(repo_path): |
| 41 | + return subprocess.check_output('git log -1 --format="%ad"'.split(), |
| 42 | + cwd=repo_path).strip()[1:-1] |
| 43 | + |
| 44 | + |
| 45 | +def github_list_repositories(page, query='language:python', sort='stars'): |
| 46 | + # We're using the legacy search api |
| 47 | + # (http://developer.github.com/v3/search/legacy/), maybe we should use the |
| 48 | + # preview of the new api |
| 49 | + # (http://developer.github.com/changes/2013-07-19-preview-the-new-search-api/ |
| 50 | + # https://gist.github.com/jasonrudolph/6065289) |
| 51 | + search_url = "https://api.github.com/legacy/repos/search/{}" |
| 52 | + params['start_page'] = page |
| 53 | + response = requests.get(search_url.format(query), params=params) |
| 54 | + |
| 55 | + projects = [] |
| 56 | + for repo in response.json()['repositories']: |
| 57 | + project_name = repo["name"] |
| 58 | + project_url = repo["url"] |
| 59 | + projects.append({'name': project_name, 'url': project_url}) |
| 60 | + |
| 61 | + return projects |
0 commit comments