github3.py
Python library for interfacing with the GitHub APIv3
github3.py — github3.py 0.9.3 documentation
github provides a "Revert" button in it's web interface, which allow us to revert a pull request that was already merged.
This always involves, to the best of my knowledge, creating a new pull request to revert the changes.
Is it possible to replicate this functionality easily using the API? Is it possible to do it without having to create a new Pull Request?
Just to clarify more, the PR is from branch A to branch B - If I undo the changes in branch B using underlying git commands, what will happen to the PR?
Source: (StackOverflow)
I use github3.py
library in order to create and update Gist on github.com
I can access an existing gist and get all information except content of the file:
for g in gh.iter_gists():
if g.id == content[0]:
f = g.iter_files().next()
print g.files #1
print f.raw_url
old_content = f.content #Returns None
Any hint why does it return None
in the last line?
Source: (StackOverflow)
I'm using https://github.com/sigmavirus24/github3.py
and I'm having problem with getting issue_comments from PR.
for pr in repo.iter_pulls():
for comment in pr.issue_comments():
print comment
I'm getting
AttributeError: 'PullRequest' object has no attribute
'issue_comments'
What I'm doing wrong here? review_comments for example is working just fine
Source: (StackOverflow)
I'm using the github3 python library and am trying to find all public repos that users from our organization have contributed to (to reward the support of open source!).
I've got the list of users for the organization, but now what?
Can I use the public events iterator to find repos?
#!/usr/bin/env python
import argparse
import github3
def get_organization(github, name):
for organization in github.iter_orgs():
if organization.login == name:
return organization
def main(args):
github = github3.login(args.github_username, password=args.github_password)
organization = get_organization(github, args.organization)
# Get a list of all current organization contributors
orgMembers = [member.login for member in organization.iter_members()]
# now what?
Source: (StackOverflow)
I am trying to get the email addresses of the committers of a project to specific files. After creating a query that finds the code files in a list of repos matching specific criteria, I get the correct results in the form of code_results (of type CodeSearchResult). Now to try access the commit information, I do the following
for code_result in code_results:
repository = code_result.repository
file_path = code_result.path
commits = repository.commits(path=file_path)
for commit in commits:
if commit.committer is not None:
print commit.committer
The problem is that trying to get the email through commit.committer.email always returns None even though the documentation says that a commit contains the committer's email. I also tried author instead of committer since the documentation says the author is a dict containing the email, but I'm not sure what the dict keys are.
Thanks!
Source: (StackOverflow)
According to this question a PR is just an issue with some things on top.
How to get the associated issue id?
I just saw issue_url as attribute for the pull request object.
Also, PR has the method create_review_comment
but no method create_issue_comment
.
How would such a method look like?
How to create an issue comment in the Pull Request?
Source: (StackOverflow)
I developing a web service which uses some Github info. I need to get a list of files which changed with a commit. I found a list of libraries. I tried all 3 Java libraries and github3.py
. And all these libraries returns me a commit info with an empy list of affected files(or null
for Java libs). The code for getting list of affected files is really easy so I have no idea why it happens.
from github3 import login, repository
repo = repository('sigmavirus24', 'github3.py')
commits = repo.iter_commits()
for commit in commits:
print len(commit.files) #prints 0
UPD: How I can get a list of files changed by specific commit?
Source: (StackOverflow)
Hey I've been reading up on the github3.py, but can't find a clear explanation of how to retrieve a list of a user's repositories.
It seems that there should be a simple solution like a method or a attribute to the user object. I just can't seem to find it on the docs, can anyone help?
Thanks,
Van
Source: (StackOverflow)
This question already has an answer here:
I'm trying to list the title and number on a pull request in a repository. I would like to return the JSON as a dict and print the title and number of the pull request.
If I just print the title or number alone, I get the expected output, but if combine the values to print, I get TypeError: string indices must be integers
.
#!/usr/bin/env python
import github3
from github3 import login, GitHub
import requests
import json
import sys
auth = dict(username="xxxxxxxxx",token="xxxxxxxxx")
gh = login(**auth)
result = gh.repository(owner="xxx", repository="xxxx").pull_request(x)
data = result.as_dict()
print data['title']['number']
Source: (StackOverflow)
I'm looking through some of the user documentation for github3.py library.
I'm trying to list all of a user's repos.
If I use the code below, with gr = gh.repos.list().all()
, I get the expected results.
But, if I use gr = gh.repos.list(user='username',type='all')
, I get this error: <pygithub3.core.result.smart.Result object at 0x00000000033728D0>
Looking at the docs, this should work, but I'm new to Python and this library so I may be missing something??
#!/usr/bin/env python
from pygithub3 import Github
import requests
auth = dict(login="xxxx", user = "xxxx", token="xxxxx", repo="my-repo")
gh = Github(**auth)
gr = gh.repos.list().all()
print gr
Source: (StackOverflow)
Currently I am trying to get all Github user location. I am using github3 python library to get the location. But it gives me over-API usage error when my api calls are more than 5K. Here is my code.
import github3
from datetime import datetime
import sys
def main(pswd):
g = github3.login(username="rakeshcusat", password=pswd)
current_time = datetime.now()
fhandler = open("githubuser_"+current_time.strftime("%d-%m-%y-%H:%M:%S"), "w")
for user in g.iter_all_users():
user.refresh()
try:
fhandler.write(" user: {0}, email: {1}, location: {2}\n".format(str(user), str(user.email), str(user.location)))
except:
print "Something wrong, user id : {0}".format(user.id);
fhandler.close()
if __name__ == "__main__":
if len(sys.argv) == 2:
main(sys.argv[1])
else:
print "Please provide your password"
I can do this by downloading all username first which will be only single API call. And then iteratively download the user location. If hit over-usage then wait for one hour and resume the api call where it was left. But this seems like a lame solution and definitely it will take more time(almost 25+ hours). Can some one provide me better way of doing this?
Source: (StackOverflow)
I have been playing with the parameters for awhile now but I continue to get the same 422 Validation Error. I am using runscope to test if my webhooks work.
url_path = "https://k1lavjuzlcvj.runscope.net"
repo.create_hook(name="testhook",config={"url":url_path, "content_type":"json"})
This is the stack output that I receive from this call
09-29 13:35 github3 DEBUG POST https://github.umn.edu/api/v3/repos/umn-csci-2041F14/testbalas/hooks with {"name": "testhook", "active": true, "config": {"content_type": "json", "url": "https://k1lavjuzlcvj.runscope.net"}, "events": ["push"]}, {}
09-29 13:35 requests.packages.urllib3.connectionpool DEBUG "POST /api/v3/repos/umn-csci-2041F14/testbalas/hooks HTTP/1.1" 422 113
09-29 13:35 logger ERROR Failure while setting hook for testbalas:
Traceback (most recent call last):
File "./createurlhooksbyuid", line 107, in <module>
repo.create_hook(name="testhook",config={"url":args.url, "content_type":"json"})
File "/Users/nate/Git-Projects/administration/dependencies/github3.py/github3/decorators.py", line 38, in auth_wrapper
return func(self, *args, **kwargs)
File "/Users/nate/Git-Projects/administration/dependencies/github3.py/github3/repos/repo.py", line 613, in create_hook
json = self._json(self._post(url, data=data), 201)
File "/Users/nate/Git-Projects/administration/dependencies/github3.py/github3/models.py", line 100, in _json
if self._boolean(response, status_code, 404) and response.content:
File "/Users/nate/Git-Projects/administration/dependencies/github3.py/github3/models.py", line 121, in _boolean
raise GitHubError(response)
github3.models.GitHubError: 422 Validation Failed
Any help would be appreciated, thank you!
Source: (StackOverflow)
From a post on another stackoverflow, the following was recommended.
Is there a way to avoid using cleartext, maybe supply an existing admin ssh key instead?
from github3 import login
g = login('abcd', password)
with open('~/.ssh/temp.k.pub', 'r') as fd:
key = g.create_key('abcd', fd)
print("Created {0}".format(key.title))`
Source: (StackOverflow)
From the docs of github3.py, I see that it's offering a session
attribute, and it seems that I can do
g = github.GitHub(token=authentication_token)
g.session = cachecontrol.CacheControl(g.session)
but in fact it's _session
, i.e. not a public API so I shouldn't use it.
Now I'm wondering how I'm supposed to inject cachecontrol?
Source: (StackOverflow)
I wonder if this has ever come up before?
I have an app that downloads tons of information from our GitHub Enterprise instance (not currently using github3.py but I am thinking of converting it over to use github3.py). Basically, it crawls 189 repos and then for each repo, it pulls branches, tags, and commits. This is obviously pretty slow, because it has to do so many HTTP requests serially.
I wonder if github3.py could be made to return grequest objects so that I could have grequests do the requests in parallel? Or perhaps an alternative would be to wrap and hide grequests by having the ability to set a "concurrency level" in github3.py and have it take care of doing requests in parallel. Or maybe a context manager:
with github3.parallel():
tags = pull_tags(git_repo)
branches = pull_branches(git_repo)
I recognize that it could be quite challenging to come up with an API that works well with parallelization since it's such a different paradigm. Which is why I didn't want to clutter up the issue tracker with this.
Source: (StackOverflow)