def __init__(self, owner, repo, user, password=None, token=None, **kwargs): super(GithubWrapper, self).__init__(**kwargs) if (token is None) and (password is None): self.api = pygithub3.Github(user=owner, repo=repo, login=user) elif token is None: self.api = pygithub3.Github(user=owner, repo=repo, login=user, password=password) elif password is None: self.api = pygithub3.Github(user=owner, repo=repo, login=user, token=token) else: self.api = pygithub3.Github(user=owner, repo=repo, login=user, password=password, token=token)
def backup(user, dest): """Performs a backup of all the public repos in user's GitHub account on dest """ gh = pygithub3.Github() repos = gh.repos.list(user=user, type='all') for repo in repos.all(): repo_path = os.path.join(dest, repo.name) LOG.info("Backing up repository {}".format(repo.name)) #If the repository is present on destination, update all branches if os.path.exists(repo_path): LOG.info("The repository {} already exists on destination. Pulling " \ "all branches".format(repo.name)) with cd(repo_path): try: cl = ['git', 'up'] check_call(cl) except CalledProcessError: LOG.error("There was an error fetching the branches from " \ "the repository {}, skipping it".format(repo.name)) pass #Otherwise clone the repository and fetch all branches else: LOG.info("The repository {} does not exist on destination. " \ "Cloning it. ".format(repo.name)) try: cl1 = ['git', 'clone', '-q', repo.clone_url, repo_path] check_call(cl1) with cd(repo_path): check_call(track_all_branches, shell=True) except CalledProcessError: LOG.error('Error cloning repository {}, skipping it'.format(repo.name)) pass
def run(self, match, data, outputs): try: gh = pygithub3.Github() issue = gh.issues.get(int(match[0]), user='******', repo='yt') outputs.append([data['channel'], issue.html_url]) except pygithub3.exceptions.NotFound: pass
def fetch_commit_info(self, commit): # Get commit info gh = pygithub3.Github(user=self.username, repo=self.name) commit_info = gh.repos.commits.get(sha=commit) commit_creation_date = commit_info.commit.author.date local_timezone = pytz.timezone(settings.TIME_ZONE) commit_creation_datetime = local_timezone.localize( commit_creation_date) # Commit information return {"creation_datetime": commit_creation_datetime}
def main(): gh = pygithub3.Github(GITHUB_OAUTH_TOKEN) repos_list = [] for repo in gh.get_user().get_repos(): uname = repo.owner.login pwd = GITHUB_OAUTH_TOKEN clone_url = repo.clone_url index = clone_url.find('github.com') auth_string = uname + ':' + pwd + '@' authenticated_clone_url = clone_url[:index] + auth_string + clone_url[ index:] repos_list.append(authenticated_clone_url) print(repos_list)
def gather_repos(ghusers, no_forks=False): gh = pygithub3.Github(user=gh_user, token=token) repos = {} for user in ghusers: ghrepo = gh.repos.list(user=user).all() for r in ghrepo: repos[r.name] = { 'name': r.name, 'org': user, 'fork': r.fork, 'ssh_url': r.ssh_url } return repos
def main(branch_name=None, do_push=False): print 'Enter the urls of the pull requests, separated by newlines. EOF to finish:' urls = sys.stdin.read().strip().split('\n') if len(urls) == 0: sys.exit(0) prs = [] gh = pygithub3.Github() for url in urls: try: path = urlparse.urlparse(url).path pathkeys = path.split('/') prs.append( gh.pull_requests.get(int(pathkeys[4]), pathkeys[1], pathkeys[2])) assert pathkeys[3] == 'pull' except Exception: # pylint: disable=broad-except print url, 'is not a github pull request url' import ipdb ipdb.set_trace() sys.exit(1) if branch_name is None: branch_name = 'pr/%s-%d' % (prs[0].head['label'].replace( ':', '/'), prs[0].number) for pr in prs: repo_path = os.path.join(angr_dir, pr.base['repo']['name']) print '\x1b[32;1m$', 'git', 'checkout', '-B', branch_name, 'master', '\x1b[0m' subprocess.call(['git', 'checkout', '-B', branch_name, 'master'], cwd=repo_path) print '\x1b[32;1m$', 'git', 'pull', pr.head['repo'][ 'git_url'], pr.head['ref'], '\x1b[0m' subprocess.call( ['git', 'pull', pr.head['repo']['git_url'], pr.head['ref']], cwd=repo_path) if do_push: print '\x1b[32;1m$', 'git', 'push', '-f', '-u', 'origin', branch_name, '\x1b[0m' subprocess.call(['git', 'push', '-f', '-u', 'origin', branch_name], cwd=repo_path) repolist = ' '.join(pr.base['repo']['name'] for pr in prs) print print '\x1b[33;1mTo merge this pull request, run the following commands:\x1b[0m' print 'REPOS=%s ./git_all.sh checkout master' % repolist print 'REPOS=%s ./git_all.sh merge %s' % (repolist, branch_name) print 'REPOS=%s ./git_all.sh push' % repolist print 'REPOS=%s ./git_all.sh branch -D %s' % (repolist, branch_name)
def main(branch_name=None): print 'Enter the urls of the pull requests, separated by newlines. EOF to finish:' urls = sys.stdin.read().strip().split('\n') if len(urls) == 0: sys.exit(0) prs = [] gh = pygithub3.Github() for url in urls: try: path = urlparse.urlparse(url).path pathkeys = path.split('/') prs.append( gh.pull_requests.get(int(pathkeys[4]), pathkeys[1], pathkeys[2])) assert pathkeys[3] == 'pull' except Exception: # pylint: disable=broad-except print url, 'is not a github pull request url' import ipdb ipdb.set_trace() sys.exit(1) if branch_name is None: branch_name = 'pr/' + prs[0].head['label'].replace(':', '/') for pr in prs: repo_path = os.path.join(angr_dir, pr.base['repo']['name']) print '\x1b[32;1m$', 'git', 'checkout', '-B', branch_name, 'master', '\x1b[0m' subprocess.call(['git', 'checkout', '-B', branch_name, 'master'], cwd=repo_path) print '\x1b[32;1m$', 'git', 'pull', pr.head['repo'][ 'git_url'], pr.head['ref'], '\x1b[0m' subprocess.call( ['git', 'pull', pr.head['repo']['git_url'], pr.head['ref']], cwd=repo_path) print '\x1b[32;1m$', 'git', 'push', '-f', '-u', 'origin', branch_name, '\x1b[0m' subprocess.call(['git', 'push', '-f', '-u', 'origin', branch_name], cwd=repo_path)
def create_git_repo_init(): gh = None print "enter your username" username = raw_input() print "enter your password" password = raw_input() auth = dict(login=username, password=password) if not os.path.isdir("start/Node"): os.makedirs("start/Node") username = get_local_git_user() gh = pygithub3.Github(token='') repo_name = 'gitcoin' gh.repos.create(dict(name=repo_name, description='desc')) #repos = gh.create_repo(repo_name) #random_node = random.choice(VERIFIED_NODES) cloneUrl = 'https://github.com/karimchukfeh/gitcoin.git' localRepopath = 'start/Node/' repo = Repo.clone_from(cloneUrl, localRepopath) another_url = 'https://github.com/' + username + '/gitcoin.git' remote = repo.create_remote(repo_name, url=another_url) remote.push() create_new_node_table(username) return True
def get_github_conn(self): if self.github_conn is None: #auth = dict(login=GITHUB_LOGIN, password=GITHUB_PASSWORD_OR_PERSONAL_ACCESS_TOKEN, repo=GITHUB_TARGET_REPOSITORY, user=GITHUB_TARGET_USERNAME) self.github_conn = pygithub3.Github(**get_github_auth()) return self.github_conn
if __name__ == '__main__': args = parse_args() if args.user is not None: ghuser = args.user else: ghuser = raw_input('github username: '******'a' if args.append else 'w') else: stream = sys.stdout repo = git.Repo(args.clone if args.clone is not None else '.') api = pygithub3.Github(user='******', repo='mame', login=ghuser, password=getpass.getpass('github password: '******'0.%s' % (long(releasetag_pat.sub('\\1', tag.name)) + 1, ), 'MAMETesters Bugs Fixed', 'New working machines', 'New working clones', 'Machines promoted to working', 'Clones promoted to working', 'New machines marked as NOT_WORKING', 'New clones marked as NOT_WORKING', 'New working software list additions', 'Software list items promoted to working', 'New NOT_WORKING software list additions', 'Translations added or modified') for heading in placeholders: print_section_heading(stream, heading)
""" import sys import subprocess import pygithub3 gh = None def gather_clone_urls(organization, no_forks=True): all_repos = gh.repos.list(user=organization).all() for repo in all_repos: # Don't print the urls for repos that are forks. if no_forks and repo.fork: continue yield repo.clone_url if __name__ == '__main__': gh = pygithub3.Github() repo = sys.argv[1] lgtm_cmd = ["sudo", "lgtm-cli", "add-projects", "--anon"] print("Collecting repositories from " + repo) clone_urls = gather_clone_urls(repo) for url in clone_urls: lgtm_cmd.append(url) print url subprocess.call(lgtm_cmd)
def _init_github(self, username, password, repo=None): repo_name = self._get_repo_name(repo) return pygithub3.Github(login=username, password=password, user=username, repo=repo_name)
def __init__(self): self.gh = pygithub3.Github()
args = get_arguments() # Configure logging log_format = "%(asctime)s - %(levelname)s - %(message)s" logging.basicConfig(level=logging.WARNING, format=log_format) logger = logging.getLogger(__name__) if 'debug' in args and args['debug']: logger.setLevel(logging.DEBUG) # Configure our connection to GitHub github_token = os.environ.get('GITHUB_TOKEN') if github_token is None: logger.warning("Provide a GitHub API token via the GITHUB_TOKEN " "environment variable to avoid exceeding GitHub API " "limits.") gh = pygithub3.Github(token=github_token) # Load our Jinja templates TEMPLATE_DIR = "{0}/templates".format( os.path.dirname(os.path.abspath(__file__))) jinja_env = jinja2.Environment( loader=jinja2.FileSystemLoader(TEMPLATE_DIR), trim_blocks=True) # Store our arguments into variables to make things easier. old_commit = args['old_commit'][0] new_commit = args['new_commit'][0] # Get the first line of the commit message in the older commit logger.debug("Retrieving commit message from the older OSA commit") try: old_commit_message = get_commit_message(old_commit)
def get_github_conn(self): if self.github_conn is None: self.github_conn = pygithub3.Github(**get_github_auth()) return self.github_conn