本文整理汇总了Python中github.Github方法的典型用法代码示例。如果您正苦于以下问题:Python github.Github方法的具体用法?Python github.Github怎么用?Python github.Github使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github
的用法示例。
在下文中一共展示了github.Github方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: import github [as 别名]
# 或者: from github import Github [as 别名]
def __init__(self, user, repo, subdir=None, sha=None, prov=None):
"""Create a new GithubLoader.
Keyword arguments:
user -- Github user name of the target github repo.
repo -- Repository name of the target github repo.
subdir -- Target subdirectory within the given repo. (default: None).
sha -- Github commit identifier hash (default: None).
prov -- grlcPROV object for tracking provenance (default: None)."""
self.user = user
self.repo = repo
self.subdir = subdir
self.sha = sha
self.prov = prov
gh = Github(static.ACCESS_TOKEN)
try:
self.gh_repo = gh.get_repo(user + '/' + repo, lazy=False)
except BadCredentialsException:
raise Exception('BadCredentials: have you set up github_access_token on config.ini ?')
except Exception:
raise Exception('Repo not found: ' + user + '/' + repo)
示例2: CreateGitHubRepo
# 需要导入模块: import github [as 别名]
# 或者: from github import Github [as 别名]
def CreateGitHubRepo():
global repoName
global private
global username
global password
GetCredentials()
try:
user = Github(username, password).get_user()
user.create_repo(repoName, private=private)
return True
except Exception as e:
repoName = ""
username = ""
password = ""
private = ""
print(Fore.RED + str(e) + Fore.WHITE)
return False
示例3: __init__
# 需要导入模块: import github [as 别名]
# 或者: from github import Github [as 别名]
def __init__(self, token):
"""
GitHub engine
"""
self.token = token
self.g = Github(login_or_token=token, per_page=per_page)
self.rule_object = None
self.code = ''
# jquery/jquery
self.full_name = ''
self.sha = ''
self.url = ''
# src/attributes/classes.js
self.path = ''
self.result = None
# 被排除掉的结果,为防止误报,将发送邮件人工核查
self.exclude_result = None
self.hash_list = None
self.processed_count = None
self.next_count = None
示例4: connect
# 需要导入模块: import github [as 别名]
# 或者: from github import Github [as 别名]
def connect(self, params={}):
self.logger.info("Connect: Connecting..")
try:
self.username = params.get('credentials').get("username")
self.secret = params.get("credentials").get('password')
self.basic_auth = (self.username, self.secret)
self.github_session = requests.Session()
self.github_user = github.Github(self.username, self.secret)
user_info = self.github_user.get_user()
self.user = self.github_user.get_user(self.username)
self.github_session_user = requests.get(self.api_prefix, auth=(self.username, self.secret), verify=True)
if str(self.github_session_user.status_code).startswith('2'):
self.logger.info('Connect: Login successful')
else:
self.logger.info('Connect: Login unsuccessful')
except github.GithubException as err:
self.logger.error('Github: Connect: error %s', err.data)
raise Exception('Github: Connect: user could not be authenticated please try again.')
except requests.exceptions.RequestException as e:
raise e
示例5: clean_github_repository
# 需要导入模块: import github [as 别名]
# 或者: from github import Github [as 别名]
def clean_github_repository(repo):
"""
get the username/repository from a Github url
:param repo:str the Github url of the repository
:return: username/repository
"""
if repo is None:
return None
repo = repo.replace("http://github.com/", "") \
.replace("https://github.com/", "")
if repo[-1] == '/':
repo = repo[:-1]
split_repo = repo.split("/")
(username, repository) = split_repo[0:2]
branch = "master"
if len(split_repo) > 2:
if split_repo[2] == "tree":
branch = split_repo[3]
return username, repository, branch
示例6: __init__
# 需要导入模块: import github [as 别名]
# 或者: from github import Github [as 别名]
def __init__(self,
github_token,
host="127.0.0.1",
port=5000,
config_dir='./repositories',
secret_key=None,
client_id=None,
client_secret=None):
self.github_token = github_token if github_token != "" else os.environ["GITHUB_AUTH_TOKEN"]
self.secret_key = secret_key if secret_key != "" else os.environ["SECRET_KEY"]
self.client_id = client_id if client_id != "" else os.environ["GITHUB_CLIENT_ID"]
self.client_secret = client_secret if client_secret != "" else os.environ["GITHUB_CLIENT_SECRET"]
self.host = host
self.port = port
self.config_dir = config_dir
if config_dir[0:2] == "./":
self.config_dir = os.path.join(os.path.dirname(os.path.realpath(__file__)), config_dir[2:])
if not os.path.exists(self.config_dir):
os.makedirs(self.config_dir)
self.application = self.create_flask_application()
self.set_public_url()
self.github = github.Github(login_or_token=self.github_token)
示例7: pandas_table_to_nested_list
# 需要导入模块: import github [as 别名]
# 或者: from github import Github [as 别名]
def pandas_table_to_nested_list(df):
"""
Converts pandas table df to nested list
"""
table_data = [["" for x in range(df.shape[1])] for y in range(df.shape[0]+1)]
# Columns names
for i in range(df.shape[1]):
table_data[0][i] = df.columns[i]
for i in range(df.shape[0]):
for j in range(df.shape[1]):
table_data[i+1][j] = df.iat[i, j]
return table_data
# Github object
示例8: mock_pr_comment_functionality
# 需要导入模块: import github [as 别名]
# 或者: from github import Github [as 别名]
def mock_pr_comment_functionality(request):
packit_yaml = (
"{'specfile_path': '', 'synced_files': [], 'jobs': " + str(request.param) + "}"
)
flexmock(
GithubProject,
full_repo_name="packit-service/hello-world",
get_file_content=lambda path, ref: packit_yaml,
get_web_url=lambda: "https://github.com/the-namespace/the-repo",
get_pr=lambda pr_id: flexmock(head_commit="12345"),
)
flexmock(Github, get_repo=lambda full_name_or_id: None)
config = ServiceConfig()
config.command_handler_work_dir = SANDCASTLE_WORK_DIR
flexmock(ServiceConfig).should_receive("get_service_config").and_return(config)
trigger = flexmock(
job_config_trigger_type=JobConfigTriggerType.pull_request, id=123
)
flexmock(AddPullRequestDbTrigger).should_receive("db_trigger").and_return(trigger)
flexmock(PullRequestModel).should_receive("get_by_id").with_args(123).and_return(
trigger
)
flexmock(LocalProject, refresh_the_arguments=lambda: None)
flexmock(Whitelist, check_and_report=True)
示例9: fork_repo
# 需要导入模块: import github [as 别名]
# 或者: from github import Github [as 别名]
def fork_repo(gh, *, org, package_name, source_org):
repo_full_name = f'{org.login}/{package_name}-feedstock'
forked_repo = gh.get_repo(repo_full_name)
print(f'Checking to see if {repo_full_name} exists on Github')
try:
# Check that the repo actually exists
# Printing the name or any property of the repo issues this check
print(f'{forked_repo.full_name} already exists, not forking it again.')
return forked_repo
except UnknownObjectException:
print(f'{repo_full_name} does not exists on Github, will fork')
pass
# Else, now try to fork it from the origin
feedstock_repo = gh.get_repo(f'{source_org}/{package_name}-feedstock')
try:
org.create_fork(feedstock_repo)
except UnknownObjectException as e:
if e.status == 404:
raise RuntimeError(f'Repository not found: {e.data["message"]}')
else:
raise e
示例10: _get_github_credentials
# 需要导入模块: import github [as 别名]
# 或者: from github import Github [as 别名]
def _get_github_credentials():
if not env.tag_deploy_commits:
return (None, None)
try:
from .config import GITHUB_APIKEY
except ImportError:
print((
"You can add a config file to automate this step:\n"
" $ cp {project_root}/config.example.py {project_root}/config.py\n"
"Then edit {project_root}/config.py"
).format(project_root=PROJECT_ROOT))
username = input('Github username (leave blank for no auth): ') or None
password = getpass('Github password: ') if username else None
return (username, password)
else:
return (GITHUB_APIKEY, None)
示例11: getRepos
# 需要导入模块: import github [as 别名]
# 或者: from github import Github [as 别名]
def getRepos(self):
"""Get repos for user and add them in a combobox."""
if self.ght.text() is not "":
if self.parent is not None:
self.parent.statusBar().showMessage('Fetching repos...')
self.lbl.show()
self.movie.start()
self.ght.setStyleSheet(self.ght_original_style)
token = self.ght.text()
self.g = Github(token)
try:
if self.workThread is not None and self.workThread.isRunning():
return
except AttributeError:
pass
finally:
self.workThread = ConnectionThread(self, self.g, self.sig)
self.workThread.start()
else:
self.ght.setStyleSheet("QLineEdit { border: 2px solid red; }")
示例12: get_pending_builds
# 需要导入模块: import github [as 别名]
# 或者: from github import Github [as 别名]
def get_pending_builds(history):
comments = {}
repo = Github(get_token()).get_repo(GITHUB_REPO_NAME)
prs = repo.get_pulls(state="open")
for pr in prs:
if pr.base.ref != "master":
continue
for comment in pr.get_issue_comments():
if comment.id in history:
continue
if not comment_is_command(comment.body):
continue
if comment.user.login not in MAINTAINERS:
LOG.warning(f"{comment.user.login} is not listed as a maintainer")
continue
if pr.number in comments:
comments[pr.number]["comment_ids"].add(comment.id)
continue
comments[pr.number] = {
"comment_ids": {comment.id},
"pr_repo_name": pr.head.repo.full_name.split("/")[1],
"pr_github_org": pr.head.repo.full_name.split("/")[0],
"pr_branch": pr.head.ref,
}
return comments
示例13: __init__
# 需要导入模块: import github [as 别名]
# 或者: from github import Github [as 别名]
def __init__(self):
# Authentication for user filing issue (must have read/write access to
# repository to add issue to)
try:
self.token = os.environ['GITHUB_TOKEN']
except KeyError:
print("Make sure that you've GITHUB_TOKEN exported")
exit(1)
# First create a Github instance:
# or using an access token
self.g = Github(self.token)
# def __init__(self, user, password):
# # TODO
# username = os.environ['GITHUB_USER']
# password = os.environ['GITHUB_USER']
示例14: ontologies_for_repo
# 需要导入模块: import github [as 别名]
# 或者: from github import Github [as 别名]
def ontologies_for_repo(repo):
"""
:param repo: repo string as "user/reponame"
:return: ontologies list
"""
g = Github(os.environ['github_username'], os.environ['github_password'])
try:
repo = g.get_repo(repo)
files_and_dirs = repo.get_file_contents('/')
files_and_dirs = [fd for fd in files_and_dirs if fd.name != 'OnToology']
# for fd in files_and_dirs:
# print fd.name + ' => ' + fd.type
ontologies = []
for fd in files_and_dirs:
ontos = get_ontologies(fd, repo)
ontologies += ontos
return ontologies
except Exception as e:
print str(e)
return []
示例15: fork_repo
# 需要导入模块: import github [as 别名]
# 或者: from github import Github [as 别名]
def fork_repo(target_repo):
"""
:param target_repo: username/reponame
:return: forked repo (e.g. OnToologyUser/reponame)
"""
# the wait time to give github sometime so the repo can be forked
# successfully
time.sleep(sleeping_time)
# this is a workaround and not a proper way to do a fork
# comm = "curl --user \"%s:%s\" --request POST --data \'{}\' https://api.github.com/repos/%s/forks" % (
# username, password, target_repo)
# if not settings.test_conf['local']:
# comm += ' >> "' + log_file_dir + '"'
# dolog(comm)
# call(comm, shell=True)
username = os.environ['github_username']
password = os.environ['github_password']
gg = Github(username, password)
repo = gg.get_repo(target_repo)
user = gg.get_user()
forked_repo = user.create_fork(repo)
dolog('forked to: ' + forked_repo.name)
return forked_repo