def test_auth(self): service = github.GitHub('a-token') service.user().get() self.expect('GET', '/user', {}, {'Authorization': 'token a-token'}) service = github.GitHub('user', 'password') service.user().get() self.expect('GET', '/user', {}, {'Authorization': 'Basic dXNlcjpwYXNzd29yZA=='})
def unlink_hook(user_id, repo_name, hook_id): user = User.objects.get(pk=user_id) service = github.GitHub(user.social_auth.get().extra_data['access_token']) service.repo(user.username, repo_name) \ .hook(hook_id).delete() return True
def get_github(parse): print "INFO - Connecting to github" try: ghusername = parse.get("github", "username") ghpassword = parse.get("github", "password") return github.GitHub(ghusername, ghpassword) except Exception as details: print "Error - Connect to github failed: %s" % details
def _createGithubRelease(self, tag, changes): print "\nCreating Release %s in GitHub..." % tag gh = github.GitHub(self.ghToken) gh_repo = gh.repo(self.getGithubOrg(), self.getGithubRepo()) release = gh_repo.releases().create({ "name": tag, "tag_name": tag, "body": changes }) return release["html_url"]
def cache_repos(user_id): user = User.objects.get(pk=user_id) service = github.GitHub(user.social_auth.get().extra_data['access_token']) data = [] for git_repo in service.repos().get(): data.append({ key: value for key, value in dict(git_repo).iteritems() if key in REPO_KEYS }) cache.set('repos:%s' % user_id, data) return True
def import_repos(user_id, repo_names): user = User.objects.get(pk=user_id) service = github.GitHub(user.social_auth.get().extra_data['access_token']) for repo in Repository.objects.filter(full_name__in=repo_names): git_repo = service.repo(user.username, repo.name) for git_branch in git_repo.branches(): branch = RepositoryBranch.objects.get_or_create( repository=repo, name=git_branch['name']) commits = [] git_commits = git_repo.commits().get( sha=git_branch['name'])[:REPO_COMMITS_LIMIT] for item in git_commits: commits.append({ 'sha': item['sha'], 'html_url': item['html_url'], 'message': item['commit']['message'], 'timestamp': item['commit']['committer']['date'], 'committer': item['commit']['committer'], 'author': item['commit']['author'] }) branch[0].commits = commits branch[0].head = commits[0]['sha'] branch[0].save() git_hook = git_repo.hooks().create({ 'name': 'web', 'active': True, 'events': ['push', 'pull_request'], 'config': { 'url': '%s/hook/%s' % (settings.PROJECT_URL, repo.id), 'content_type': 'json' } }) repo.hook_id = git_hook['id'] repo.save() return True
def setUp(self): self.executor = test_executor.use() self.executor.set_response(b'{}', 200, {}) self.service = github.GitHub('my-token')
from __future__ import print_function from libsaas.services import github # use basic authentication to create a token for libsaas basic = github.GitHub('*****@*****.**', 'my-github-password') auth = basic.authorizations().create({'scopes': 'repo,gist', 'note': 'libsaas example'}) # use token authentication for the rest of the calls gh = github.GitHub(auth['token']) # go through your followers for follower in gh.user().followers(): username = follower['login'] # get the source repositories owned by each follower repos = gh.user(username).repos().get(type='owner') sources = [repo for repo in repos if not repo['fork']] # handle the case where a user has no repos if not sources: print("{0} has no repositories".format(username)) continue # print the most watched repo of each follower, excluding forks most = sorted(sources, key=lambda repo: repo['watchers'])[-1] print("{0}'s most watched repository: {1}".format(username, most['name']))
import libsaas from libsaas.executors import requests_executor from libsaas.services import github # use the Requests executor with a custom timeout and make it always send a # user agent string uastring = 'libsaas {0}'.format(libsaas.__versionstr__) requests_executor.use(timeout=5.0, config={'base_headers': { 'User-agent': uastring }}) # unstar all starred gists gh = github.GitHub('my-github-token') for gist in gh.gists().starred(): gh.gist(gist['id']).unstar()