本文整理匯總了Python中travispy.TravisPy.github_auth方法的典型用法代碼示例。如果您正苦於以下問題:Python TravisPy.github_auth方法的具體用法?Python TravisPy.github_auth怎麽用?Python TravisPy.github_auth使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類travispy.TravisPy
的用法示例。
在下文中一共展示了TravisPy.github_auth方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: checktravis
# 需要導入模塊: from travispy import TravisPy [as 別名]
# 或者: from travispy.TravisPy import github_auth [as 別名]
def checktravis():
try:
if not session.get('fork') or not session.get('username'):
return redirect(url_for('.github'))
token = session['oauth_token']['access_token']
travis = TravisPy.github_auth(token)
username = session['username']
user = travis.user()
session['useremail'] = user.email
repos = travis.repos(member=username)
verified = False
for repo in repos:
if session['fork'].lower() == repo.slug.lower():
verified = True
break
if verified:
return redirect(url_for('.dashboard'))
else:
return redirect(url_for('.asktravis'))
except:
exc_type, exc_value, exc_traceback = sys.exc_info()
if 'Forbidden' in str(exc_value):
session['username'] = None
return redirect(url_for('.asktravis'))
return 'checktravis: %s\n%s\n%s' % (exc_type, exc_value, exc_traceback)
示例2: __init__
# 需要導入模塊: from travispy import TravisPy [as 別名]
# 或者: from travispy.TravisPy import github_auth [as 別名]
def __init__(self, username, password, repo_name, repo_owner,
update_travis_commit_msg,
tag_commit_message, github_token=None, access_token=None, repo_token=None):
super(GitenbergTravisJob, self).__init__(username, password, repo_name, repo_owner,
update_travis_commit_msg,
tag_commit_message)
self.username = username
self.password = password
self._github_token = github_token
self._access_token = access_token
# if access_token is given, use it
if access_token is not None:
self.travis = TravisPy(access_token)
else:
self.travis = TravisPy.github_auth(self.github_token())
self._repo_token = repo_token
self._travis_repo_public_key = None
if self.gh_repo is not None:
self.travis_repo = self.travis.repo(self.repo_slug)
示例3: get_repo_slug
# 需要導入模塊: from travispy import TravisPy [as 別名]
# 或者: from travispy.TravisPy import github_auth [as 別名]
def get_repo_slug(travis_job_id):
current_app.logger.info('getting repo slug, contacting travis...')
travis = TravisPy.github_auth(os.environ["GITHUB_TOKEN"])
job = travis.job(travis_job_id)
repo = travis.repo(job.repository_id)
current_app.logger.info('returning slug: '+repo.slug)
return repo.slug
示例4: __init__
# 需要導入模塊: from travispy import TravisPy [as 別名]
# 或者: from travispy.TravisPy import github_auth [as 別名]
def __init__(self):
token = os.environ.get('GITHUB_TOKEN', None)
if token is None:
raise SystemExit(
'Please export your GitHub PAT as the "GITHUB_TOKEN" env var'
)
logger.debug('Connecting to TravisCI API...')
self._travis = TravisPy.github_auth(token)
示例5: loadtravis
# 需要導入模塊: from travispy import TravisPy [as 別名]
# 或者: from travispy.TravisPy import github_auth [as 別名]
def loadtravis():
if not session.get('username') or not session.get('fork'):
return None
travis = None
try:
token = session['oauth_token']['access_token']
travis = TravisPy.github_auth(token)
except:
return None
return travis
示例6: loadapis
# 需要導入模塊: from travispy import TravisPy [as 別名]
# 或者: from travispy.TravisPy import github_auth [as 別名]
def loadapis():
if not session.get('username') or not session.get('fork'):
return None, None
token = session['oauth_token']['access_token']
github, travis = None, None
try:
github = Github(token)
travis = TravisPy.github_auth(token)
except:
return None, None
return github, travis
示例7: travis
# 需要導入模塊: from travispy import TravisPy [as 別名]
# 或者: from travispy.TravisPy import github_auth [as 別名]
def travis(test_settings):
token = test_settings.get('github_token', '')
if not token.strip():
pytest.skip('TRAVISPY_TEST_SETTINGS has no "github_token" value')
try:
result = TravisPy.github_auth(token)
except TravisError:
pytest.skip('Provided "github_token" value is invalid')
return result
示例8: enable_travis
# 需要導入模塊: from travispy import TravisPy [as 別名]
# 或者: from travispy.TravisPy import github_auth [as 別名]
def enable_travis(token, slug, log):
"""
Enable Travis automatically for the given repo.
this need to have access to the GitHub token.
"""
# Done with github directly. Login to travis
travis = TravisPy.github_auth(token, uri='https://api.travis-ci.org')
user = travis.user()
log.info('============= Configuring Travis.... ===========')
log.info('Travis user: %s', user.name)
# Ask travis to sync with github, try to fetch created repo with exponentially decaying time.
last_sync = user.synced_at
log.info('syncing Travis with Github, this can take a while...')
repo = travis._session.post(travis._session.uri+'/users/sync')
import time
for i in range(10):
try:
time.sleep((1.5)**i)
repo = travis.repo(slug)
if travis.user().synced_at == last_sync:
raise ValueError('synced not really done, travis.repo() can be a duplicate')
log.info('\nsyncing done')
break
# TODO: find the right exception here
except Exception:
pass
## todo , warn if not found
# Enable travis hook for this repository
log.info('Enabling Travis-CI hook for this repository')
resp = travis._session.put(travis._session.uri+"/hooks/",
json={
"hook": {
"id": repo.id ,
"active": True
}
},
)
if resp.json()['result'] is True:
log.info('Travis hook for this repository is now enabled.')
log.info('Continuous integration test should be triggered every time you push code to github')
else:
log.info("I was not able to set up Travis hooks... something went wrong.")
log.info('========== Done configuring Travis.... =========')
return repo, user
示例9: before_request
# 需要導入模塊: from travispy import TravisPy [as 別名]
# 或者: from travispy.TravisPy import github_auth [as 別名]
def before_request():
from travispy import TravisPy
from database import users
g.user = None
g.travispy = None
if 'user_id' in session:
g.user = users.find_one({'_id': ObjectId(session['user_id'])})
if g.user is not None:
g.travispy = TravisPy.github_auth(g.user['github_access_token'])
示例10: travis
# 需要導入模塊: from travispy import TravisPy [as 別名]
# 或者: from travispy.TravisPy import github_auth [as 別名]
def travis(self, irc, msg, args, optrepo):
"""<repo>
Run test on repo.
"""
ght = self.registryValue('GitHubToken')
t = TravisPy.github_auth(ght)
user = t.user()
irc.reply("user.login {0}".format(user.login))
repos = t.repos(member=user.login)
irc.reply("Member Repos: {0}".format(" | ".join([i.slug for i in repos])))
repo = t.repo(optrepo)
build = t.build(repo.last_build_id)
irc.reply("BUILD: {0}".format(build))
build.restart()
irc.reply("BUILD RESTART: {0}".format(build))
示例11: checkAuthorization
# 需要導入模塊: from travispy import TravisPy [as 別名]
# 或者: from travispy.TravisPy import github_auth [as 別名]
def checkAuthorization(self):
"""Check Travis Auth."""
if self.travisAuth:
pass
else:
GitHubToken = self.registryValue('GitHubToken')
if not GitHubToken:
self.log.info("ERROR :: You need to set GitHubToken in the config values for Travis.")
self.travisAuth = False
else: # we have key.
try: # we're good. authed.
t = TravisPy.github_auth(GitHubToken)
self.travisAuth = t
self.log.info("I have successfully logged into Travis using your credentials.")
except Exception as e:
self.log.info("ERROR :: I could not auth with Travis :: {0}".format(e))
self.travisAuth = False
示例12: setup_platform
# 需要導入模塊: from travispy import TravisPy [as 別名]
# 或者: from travispy.TravisPy import github_auth [as 別名]
def setup_platform(hass, config, add_devices, discovery_info=None):
"""Set up the Travis CI sensor."""
from travispy import TravisPy
from travispy.errors import TravisError
token = config.get(CONF_API_KEY)
repositories = config.get(CONF_REPOSITORY)
branch = config.get(CONF_BRANCH)
try:
travis = TravisPy.github_auth(token)
user = travis.user()
except TravisError as ex:
_LOGGER.error("Unable to connect to Travis CI service: %s", str(ex))
hass.components.persistent_notification.create(
'Error: {}<br />'
'You will need to restart hass after fixing.'
''.format(ex),
title=NOTIFICATION_TITLE,
notification_id=NOTIFICATION_ID)
return False
sensors = []
# non specific repository selected, then show all associated
if not repositories:
all_repos = travis.repos(member=user.login)
repositories = [repo.slug for repo in all_repos]
for repo in repositories:
if '/' not in repo:
repo = "{0}/{1}".format(user.login, repo)
for sensor_type in config.get(CONF_MONITORED_CONDITIONS):
sensors.append(
TravisCISensor(travis, repo, user, branch, sensor_type))
add_devices(sensors, True)
return True
示例13: old_logic
# 需要導入模塊: from travispy import TravisPy [as 別名]
# 或者: from travispy.TravisPy import github_auth [as 別名]
def old_logic(gh_token):
t = TravisPy.github_auth(gh_token)
user = t.user()
repos = t.repos(member=user.login)
print "found", len(repos), "repositories:"
for r in repos:
print r.slug
repo = t.repo('FITeagle/integration-test')
branch_bin = t.branch(repo_id_or_slug=repo.slug,name='binary-only')
branch_master = t.branch(repo_id_or_slug=repo.slug,name='master')
print "bin:", branch_bin.repository_id, branch_bin.number
print "master:", branch_master.repository_id, branch_master.number
builds_master = t.builds(repository_id=branch_master.repository_id,number=branch_master.number)
builds_bin = t.builds(repository_id=branch_bin.repository_id,number=branch_bin.number)
print "Branch >>binary-only<< has", len(builds_bin), "Builds"
print "Branch >>master<< has", len(builds_master), "Builds"
build_master=builds_master[0]
build_bin=builds_bin[0]
示例14: main
# 需要導入模塊: from travispy import TravisPy [as 別名]
# 或者: from travispy.TravisPy import github_auth [as 別名]
def main(username):
github_access_token = vault.get_key('github_access_token')
if github_access_token != None:
# Use the username variable to do some stuff and return the data
token = TravisPy.github_auth(github_access_token)
q=urllib2.urlopen("https://api.travis-ci.org/repos/%s" % username)
jsondata=json.loads(q.read())
details=[]
if jsondata:
for data in jsondata:
builds=token.builds(slug=data["slug"])
for bd in builds:
bid=token.build(bd.id)
details.append((bid.commit.author_name,bid.commit.author_email))
details.append((bid.commit.committer_name,bid.commit.committer_email))
details=list(set(details))
return details
else:
return [ colored(style.BOLD +
'[!] Error: No github token for Travis CI found. Skipping' +
style.END, 'red') ]
示例15: len
# 需要導入模塊: from travispy import TravisPy [as 別名]
# 或者: from travispy.TravisPy import github_auth [as 別名]
parser.add_argument('--username', type=str, default='',
help='Set name of the repository for automatic push')
parser.add_argument('--token', type=str, default='',
help='Set token of the repository for automatic push')
args = parser.parse_args()
github_credentials = ''
if len(args.username) > 0:
github_credentials = args.username + ':' + args.token + '@'
# Fork and clone the repository YangModles/yang
reponse = requests.post('https://' + github_credentials + 'api.github.com/repos/YangModels/yang/forks')
repo = repoutil.RepoUtil('https://github.com/' + args.username + '/yang.git')
repo.clone()
travis = TravisPy.github_auth(args.token)
# Download all the latest yang modules out of http://www.claise.be/IETFYANGDraft.json and store them in tmp folder
ietf_draft_json = load_json_from_url('http://www.claise.be/IETFYANGDraft.json')
try:
os.makedirs(repo.localdir + '/experimental/ietf-extracted-YANG-modules/')
except OSError as e:
# be happy if someone already created the path
if e.errno != errno.EEXIST:
raise
for key in ietf_draft_json:
yang_file = open(repo.localdir + '/experimental/ietf-extracted-YANG-modules/' + key, 'w+')
yang_download_link = ietf_draft_json[key][2].split('href="')[1].split('">Download')[0]
try:
yang_raw = urllib2.urlopen(yang_download_link).read()
yang_file.write(yang_raw)
except: