def spider_repos():
    gh = Github(settings.GITHUB_TOKEN)
    for repo in gh.get_organization('ministryofjustice').get_repos():

        try:
            r = Repository.objects.get(name=repo.name)

        except Repository.DoesNotExist:
            r = Repository()
            r.name = repo.name
            r.created = set_timezone(repo.created_at)
            r.description = repo.description
            r.url = repo.html_url

        r.updated = set_timezone(repo.updated_at)
        r.private = repo.private
        r.contributors = repo.get_contributors().totalCount or 0
        r.save()
        print '\nSaving', r.name

        r.add_language_usages(repo.get_languages())

        record_gem_dependencies(repo, r)

        r.has_tests = check_for_tests(repo, r)

        r.save()
def find_python_unittests(gh_repo):
    gh = Github(settings.GITHUB_TOKEN)
    try:
        results = gh.search_code(
            'TestCase language:python repo:{repo}'.format(
                repo=gh_repo.full_name))
        return len(list(results)) > 0

    except GithubException:
        return False
Esempio n. 3
0
# coding: utf-8
import random
import time
from pygithub import Github

# Ref:
# https://pygithub.readthedocs.io/en/latest/introduction.html#very-short-tutorial
# If you are using an access token to circumvent 2FA, make sure you have
# enabled "repo" scope
g = Github("username", "password")

me = g.get_user()
starred = me.get_starred()
for repo in starred:
    print("Unstarring", repo)
    me.remove_from_starred(repo)
    time.sleep(1 + random.random())  # try to avoid rate-limit

# Troubleshooting
# https://developer.github.com/v3/activity/starring/#unstar-a-repository
# Debug using curl:
# $ curl -H "Authorization: token $INSERT_ACCESS_TOKEN" \
#    "https://api.github.com/user/starred/<owner>/<repo>" -i -s -X DELETE