本文整理汇总了Python中github.GitHub类的典型用法代码示例。如果您正苦于以下问题:Python GitHub类的具体用法?Python GitHub怎么用?Python GitHub使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了GitHub类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_gh_data
def get_gh_data():
gh_access_token = request.cookies.get('gh_access_token')
gh = GitHub(access_token=gh_access_token)
user_id = gh.user().get()['login']
page = 1
events = gh.users(user_id).events().get(page=page)
while True:
page += 1
new_events = gh.users(user_id).events().get(page=page)
if len(new_events) > 0:
events.extend(new_events)
else:
break
created_ats = [e['created_at'][:-1] for e in events]
timestamps = []
for ca in created_ats:
ts = time.strptime(ca, "%Y-%m-%dT%H:%M:%S")
timestamps.append((ts.tm_hour * 60 + ts.tm_min -300)%1440)
print("GH: " + str(len(timestamps)))
return json.dumps(timestamps)
示例2: get
def get(self):
user = users.get_current_user()
if not user:
self.redirect(users.create_login_url(self.request.uri))
else:
if validAdmin(user):
creds = get_githubcredentials()
self.response.write("""
<form action='%s' method="POST">
Github Repository Owner: <input name="github_owner" type="text" value="%s" /><br>
Github Repository Name: <input name="github_repo" type="text" value="%s" /><br>
Github Access Token (always hidden): <input name="github_token" type="text" placeholder="access token" /><br>
<input type="submit" />
</form>
"""%(self.request.uri, creds.owner, creds.repo))
hasAccess = False
ghcreds = get_githubcredentials()
gh = GitHub(creds.owner, creds.repo, creds.token)
try:
hasAccess = gh.hasPushAccess()
except:
pass
if hasAccess:
self.response.write("<p>Push Access Granted by GitHub.com</p>")
else:
self.response.write("<p>WARNING: No push access with the stored token and repo information. Please provide valid information</p>")
else:
self.response.headers['Content-Type'] = 'text/plain; charset=utf-8'
self.response.write("No write access for user %s"%user.email())
示例3: _make_message
def _make_message(self, message, user, repo):
github = GitHub()
try:
git_user = github.user(user)
except BadUser:
logging.error("Uh oh! {} doesn't seem to be a valid GitHub user.".format(user))
return False
try:
git_repo = github.repo(user, repo)
except BadRepo:
logging.error("Uh oh! Can't connect to {}'s repo {}.".format(user, repo))
return False
# TODO - this is ugly, setup Jinja or some other templating here instead.
message = """
**[{title}]({url})** - *A {language} repository written by [{author}]({author_url})*
> {description}
{stars} stars, {forks} forks
Clone this repository: `{clone}`
---
[I'm a bot](https://github.com/naiyt/autogithubbot) that posts info about GitHub repositories. [Create your own bot](https://github.com/naiyt/reddit-replier)! (Just be nice about it.)
""".format(title=git_repo.name, url=git_repo.url, language=git_repo.language,
description=git_repo.description, author=git_repo.author,
author_url=git_user.url,
stars=git_repo.stars, forks=git_repo.forks, clone=git_repo.clone_url)
return message
示例4: upload_to_github
def upload_to_github(file_path, nwjs_version):
github = GitHub(auth_token())
releases = github.repos(GITHUB_REPO).releases.get()
release = create_or_get_release_draft(github, releases, nwjs_version)
params = {'name': os.path.basename(file_path) }
headers = {'Content-Type': 'application/zip'}
with open(file_path, 'rb') as f:
github.repos(GITHUB_REPO).releases(release['id']).assets.post(
params=params, headers=headers, data=f, verify=False)
示例5: get_issues_api
def get_issues_api():
if app.config['REPORT_PARSING_ISSUES']:
access_token = app.config['GITHUB_ACCESS_TOKEN']
repo_owner = app.config['GITHUB_REPO_OWNER']
repo_name = app.config['GITHUB_REPO_NAME']
gh = GitHub(access_token=access_token)
return gh.repos(repo_owner)(repo_name).issues
else:
return None
示例6: main
def main():
parser = OptionParser(usage="usage: %prog [options] [pull number]")
parser.add_option("-g", "--github-user", dest="gituser",
type="string", help="github user, if not supplied no auth is used", metavar="USER")
(options, args) = parser.parse_args()
github = GitHub(options)
for pullNumber in args:
pull = github.pull("apache", "storm", pullNumber)
print "git pull "+pull.fromRepo()+" "+pull.fromBranch()
示例7: main
def main():
parser = OptionParser(usage="usage: %prog [options]")
parser.add_option("-g", "--github-user", dest="gituser",
type="string", help="github user, if not supplied no auth is used", metavar="USER")
(options, args) = parser.parse_args()
jrepo = JiraRepo("https://issues.apache.org/jira/rest/api/2")
github = GitHub(options)
openPullRequests = github.openPulls("apache","storm")
stormJiraNumber = re.compile("STORM-[0-9]+")
openJiras = jrepo.openJiras("STORM")
jira2Pulls = {}
pullWithoutJira = []
pullWithBadJira = []
for pull in openPullRequests:
found = stormJiraNumber.search(pull.title())
if found:
jiraNum = found.group(0)
if not (jiraNum in openJiras):
pullWithBadJira.append(pull)
else:
if jira2Pulls.get(jiraNum) == None:
jira2Pulls[jiraNum] = []
jira2Pulls[jiraNum].append(pull)
else:
pullWithoutJira.append(pull);
now = datetime.utcnow()
print "Pull requests that need a JIRA:"
print "Pull URL\tPull Title\tPull Age\tPull Update Age"
for pull in pullWithoutJira:
print ("%s\t%s\t%s\t%s"%(pull.html_url(), pull.title(), daydiff(now, pull.created_at()), daydiff(now, pull.updated_at()))).encode("UTF-8")
print "\nPull with bad or closed JIRA:"
print "Pull URL\tPull Title\tPull Age\tPull Update Age"
for pull in pullWithBadJira:
print ("%s\t%s\t%s\t%s"%(pull.html_url(), pull.title(), daydiff(now, pull.created_at()), daydiff(now, pull.updated_at()))).encode("UTF-8")
print "\nOpen JIRA to Pull Requests and Possible Votes, vote detection is very approximate:"
print "JIRA\tPull Requests\tJira Summary\tJIRA Age\tPull Age\tJIRA Update Age\tPull Update Age"
print "\tComment Vote\tComment Author\tPull URL\tComment Age"
for key, value in jira2Pulls.items():
print ("%s\t%s\t%s\t%s\t%s\t%s\t%s"%(key, mstr(value), openJiras[key].getSummary(),
daydiff(now, openJiras[key].getCreated()), daydiff(now, value[0].created_at()),
daydiff(now, openJiras[key].getUpdated()), daydiff(now, value[0].updated_at()))).encode("UTF-8")
for comment in openJiras[key].getComments():
#print comment.raw()
if comment.hasVote():
print (("\t%s\t%s\t%s\t%s")%(comment.getVote(), comment.getAuthor(), comment.getPull(), daydiff(now, comment.getCreated()))).encode("UTF-8")
示例8: get_token
def get_token(config):
token = config.get('token')
if token is None:
github = GitHub()
login, password = get_user_credentials()
token = github.create_token(login, password)
if token is None:
otp = raw_input('Two-factor code: ')
token = github.create_token(login, password, otp)
config.put('token', token)
config.save()
return token
示例9: cron
def cron():
from mod_ci.controllers import start_platform
from run import config, log
from database import create_session
from github import GitHub
log.info('Run the cron for kicking off CI platform(s).')
# Create session
db = create_session(config['DATABASE_URI'])
gh = GitHub(access_token=config['GITHUB_TOKEN'])
repository = gh.repos(config['GITHUB_OWNER'])(config['GITHUB_REPOSITORY'])
start_platform(db, repository)
示例10: lp_layout_list
def lp_layout_list(self, upstream=None):
"""
search_order : list layouts from upstream if mentioned
list layouts from core package
"""
if upstream is None:
l_files = list_files(self.base_path + "/inventory_layouts")
return l_files
else:
g = GitHub(upstream)
l_files = []
files = g.list_files("inventory_layouts")
return files
示例11: lp_topo_list
def lp_topo_list(self, upstream=None):
"""
search_order : list topologies from upstream if mentioned
list topologies from current folder
"""
if upstream is None:
t_files = list_files(self.base_path + "/ex_topo")
return t_files
else:
print "getting from upstream"
g = GitHub(upstream)
t_files = []
files = g.list_files("ex_topo")
return files
示例12: lp_layout_get
def lp_layout_get(self, layout, upstream=None):
"""
search_order : get layouts from upstream if mentioned
get layouts from core package
"""
if upstream is None:
get_file(self.base_path + "/inventory_layouts/" + layout,
"./layouts/")
else:
g = GitHub(upstream)
files = g.list_files("inventory_layouts")
link = filter(lambda link: link['name'] == layout, files)
link = link[0]["download_url"]
get_file(link, "./layouts", True)
return link
示例13: lp_topo_get
def lp_topo_get(self, topo, upstream=None):
"""
search_order : get topologies from upstream if mentioned
get topologies from core package
# need to add checks for ./topologies
"""
if upstream is None:
get_file(self.base_path + "/ex_topo/" + topo, "./topologies/")
else:
g = GitHub(upstream)
files = g.list_files("ex_topo")
link = filter(lambda link: link['name'] == topo, files)
link = link[0]["download_url"]
get_file(link, "./topologies", True)
return link
示例14: updatePullRequests
def updatePullRequests(self):
print 'Updating pull requests from GitHub...'
if not self.client:
self.client = GitHub(userAgent=userAgent, async=True, reuseETag=True, access_token=githubAccessToken)
gh_pullrequests = yield self.client.repos(self.username)(self.repo).pulls.get(state='open', per_page=100)
if self.client.status == 304:
print "GitHub pull requests was not changed"
defer.returnValue(None)
elif self.client.status == 200:
prs = []
for gh_pullrequest in gh_pullrequests:
pr = {}
pr['id'] = gh_pullrequest['number']
pr['branch'] = gh_pullrequest['base']['ref']
pr['author'] = gh_pullrequest['user']['login']
pr['assignee'] = gh_pullrequest['assignee']['login'] if gh_pullrequest['assignee'] else None
pr['head_user'] = gh_pullrequest['head']['repo']['owner']['login']
pr['head_repo'] = gh_pullrequest['head']['repo']['name']
pr['head_branch'] = gh_pullrequest['head']['ref']
pr['head_sha'] = gh_pullrequest['head']['sha']
pr['title'] = gh_pullrequest['title']
pr['description'] = gh_pullrequest['body']
prs.append(pr)
defer.returnValue(prs)
raise Exception('invalid status', self.client.status)
示例15: setup_repos
def setup_repos():
""" Ensure we have a matching GitHub repo for every import project
"""
github = GitHub(access_token=GITHUB_TOKEN, scope='user,repo')
#current_repos = github.users(GITHUB_USERNAME).repos.get()
current_repos = github.orgs(GITHUB_ORGANIZATION).repos.get()
repo_names = [x['name'] for x in current_repos]
for project in PROJECTS:
target_repo_name = GITHUB_REPO_NAME_FORMAT % (project['github_name'])
if target_repo_name not in repo_names:
github.orgs(GITHUB_ORGANIZATION).repos.post(
name=target_repo_name,
description='Mirrored repository') # FIXME