本文整理汇总了Python中github.com方法的典型用法代码示例。如果您正苦于以下问题:Python github.com方法的具体用法?Python github.com怎么用?Python github.com使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github
的用法示例。
在下文中一共展示了github.com方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: gh_admin_top
# 需要导入模块: import github [as 别名]
# 或者: from github import com [as 别名]
def gh_admin_top():
stars = util.param('stars', int) or 10000
page = util.param('page', int) or 1
per_page = util.param('per_page', int) or 100
# TODO: fix formatting
result = urlfetch.fetch('https://api.github.com/search/repositories?q=stars:>=%s&sort=stars&order=asc&page=%d&per_page=%d' % (stars, page, per_page))
if result.status_code == 200:
repos = json.loads(result.content)
else:
flask.abort(result.status_code)
for repo in repos['items']:
account = repo['owner']
account_db = model.Account.get_or_insert(
account['login'],
avatar_url=account['avatar_url'].split('?')[0],
email=account['email'] if 'email' in account else '',
name=account['login'],
followers=account['followers'] if 'followers' in account else 0,
organization=account['type'] == 'Organization',
username=account['login'],
)
return 'OK %d of %d' % (len(repos['items']), repos['total_count'])
示例2: clean_github_repository
# 需要导入模块: import github [as 别名]
# 或者: from github import com [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
示例3: curr_ver
# 需要导入模块: import github [as 别名]
# 或者: from github import com [as 别名]
def curr_ver(c, tag=None):
"""Refresh CURRENT_VERSION_FILE"""
if tag is None:
tag = get_repo().get_latest_release().tag_name
content = {
"tag_name": tag,
"assets": []
}
for platform in ["Windows", "Mac"]:
name = asset_name(tag, platform)
content['assets'].append({
"browser_download_url": f"https://github.com/UncleGoogle/galaxy-integration-humblebundle/releases/download/{tag}/{name}",
"name": name
})
with open(CURRENT_VERSION_FILE, 'w') as f:
json.dump(content, f, indent=4)
示例4: test_git_remote_matching_url
# 需要导入模块: import github [as 别名]
# 或者: from github import com [as 别名]
def test_git_remote_matching_url(self):
self.assertEqual(
"origin",
gpr.git_remote_matching_url("https://github.com/jd/git-pull-request.git"),
)
self.assertEqual(
"fork",
gpr.git_remote_matching_url(
"https://github.com/Flameeyes/git-pull-request.git"
),
)
self.assertEqual(
"fork",
gpr.git_remote_matching_url(
"https://github.com/flameeyes/Git-Pull-Request.git"
),
)
示例5: test_issue_12
# 需要导入模块: import github [as 别名]
# 或者: from github import com [as 别名]
def test_issue_12(self):
e = github.GithubException(
422,
{
u"documentation_url": u"https://developer.github.com/v3/pulls/#create-a-pull-request",
u"message": u"Validation Failed",
u"errors": [
{
u"message": u"No commits between issues-221 and issues-221",
u"code": u"custom",
u"resource": u"PullRequest",
}
],
},
)
self.assertEqual(
"Unable to create pull request: Validation Failed (422)\n"
"No commits between issues-221 and issues-221\n"
"Check "
"https://developer.github.com/v3/pulls/#create-a-pull-request "
"for more information.",
gpr._format_github_exception("create pull request", e),
)
示例6: test_no_message
# 需要导入模块: import github [as 别名]
# 或者: from github import com [as 别名]
def test_no_message(self):
e = github.GithubException(
422,
{
"message": "Validation Failed",
"documentation_url": "https://developer.github.com/v3/pulls/#create-a-pull-request",
"errors": [
{"resource": "PullRequest", "field": "head", "code": "invalid"}
],
},
)
self.assertEqual(
"Unable to create pull request: Validation Failed (422)\n\n"
"Check "
"https://developer.github.com/v3/pulls/#create-a-pull-request "
"for more information.",
gpr._format_github_exception("create pull request", e),
)
示例7: test_git_clone_url
# 需要导入模块: import github [as 别名]
# 或者: from github import com [as 别名]
def test_git_clone_url(self):
expected = gpr.RepositoryId("github", "example.com", "jd", "git-pull-request")
self.assertEqual(
expected,
gpr.get_repository_id_from_url("https://example.com/jd/git-pull-request"),
)
self.assertEqual(
expected,
gpr.get_repository_id_from_url(
"https://example.com/jd/git-pull-request.git"
),
)
self.assertEqual(
expected,
gpr.get_repository_id_from_url("https://example.com/jd/git-pull-request/"),
)
示例8: get_github_token
# 需要导入模块: import github [as 别名]
# 或者: from github import com [as 别名]
def get_github_token(token_dir):
try:
github_token_filename = (token_dir / 'github.token').expanduser()
with open(github_token_filename, 'r') as fh:
github_token = fh.read().strip()
if not github_token:
raise ValueError()
return github_token
except (IOError, ValueError):
raise RuntimeError(
'No github token found for archiconda on Github. \n'
'Go to https://github.com/settings/tokens/new and generate\n'
f'a token with repo access. Put it in {github_token_filename}')
示例9: get_shippable_token
# 需要导入模块: import github [as 别名]
# 或者: from github import com [as 别名]
def get_shippable_token(token_dir):
try:
shippable_token_filename = (token_dir / 'shippable.token').expanduser()
with open(shippable_token_filename, 'r') as fh:
shippable_token = fh.read().strip()
if not shippable_token:
raise ValueError()
return shippable_token
except (IOError, ValueError):
raise RuntimeError(
'No shippable token found for archiconda on shippable. \n'
'Go to http://docs.shippable.com/platform/api/api-tokens/\n'
'and follow the instructions to get a token.\n'
f'Put it in {shippable_token_filename}')
示例10: get_shippable_project_id
# 需要导入模块: import github [as 别名]
# 或者: from github import com [as 别名]
def get_shippable_project_id(token, project_full_name):
params = {'sortBy': 'createdAt', 'sortOrder': '-1', 'projectFullNames': project_full_name}
headers = {'Authorization': 'apiToken {}'.format(token)}
url = 'https://api.shippable.com/projects'
result = requests.get(url=url, params=params, headers=headers)
n_results = len(result.json())
if not n_results:
raise RuntimeError('Could not find the activated repository. Make sure it exists on shippable.')
elif n_results > 1:
raise RuntimeError("Found multiple repositories, linking to the first one. This really shouldn't happen")
# projectId seems like a short name
# the real variable we need is id
return result.json()[0]['id']
示例11: test_shipit_removes_needs_revision
# 需要导入模块: import github [as 别名]
# 或者: from github import com [as 别名]
def test_shipit_removes_needs_revision(self):
"""
Ansibot should remove needs_revision if the same user that set it gave shipit afterwards.
https://github.com/ansible/ansibullbot/issues/994
"""
datafile = u'tests/fixtures/needs_revision/1_issue.yml'
statusfile = u'tests/fixtures/needs_revision/0_prstatus.json'
with mock.patch.multiple(IssueWrapper,
mergeable_state=mock.PropertyMock(return_value='clean'),
pullrequest_filepath_exists=mock.Mock(return_value=True)):
with get_issue(datafile, statusfile) as iw:
iw._merge_commits = []
iw._committer_emails = [u'tsdmgz@domain.example']
pullrequest = mock.Mock(spec_set=github.PullRequest.PullRequest)
pullrequest.head.repo.__return_value__ = True
iw._pr = pullrequest
with open(u'tests/fixtures/needs_revision/1_reviews.json') as reviews:
iw._pr_reviews = json.load(reviews)
iw._history.merge_reviews(iw.reviews)
self.meta[u'component_maintainers'] = [u'mkrizek']
facts = get_needs_revision_facts(AnsibleTriageMock(), iw, self.meta, ShippableRunsMock())
self.assertFalse(facts[u'is_needs_revision'])
示例12: test_shipit_removes_needs_revision_multiple_users
# 需要导入模块: import github [as 别名]
# 或者: from github import com [as 别名]
def test_shipit_removes_needs_revision_multiple_users(self):
"""
Ansibot should remove needs_revision if the same user that set it gave shipit afterwards.
https://github.com/ansible/ansibullbot/issues/994
"""
datafile = u'tests/fixtures/needs_revision/2_issue.yml'
statusfile = u'tests/fixtures/needs_revision/0_prstatus.json'
with mock.patch.multiple(IssueWrapper,
mergeable_state=mock.PropertyMock(return_value='clean'),
pullrequest_filepath_exists=mock.Mock(return_value=True)):
with get_issue(datafile, statusfile) as iw:
iw._merge_commits = []
iw._committer_emails = [u'tsdmgz@domain.example']
pullrequest = mock.Mock(spec_set=github.PullRequest.PullRequest)
pullrequest.head.repo.__return_value__ = True
iw._pr = pullrequest
with open(u'tests/fixtures/needs_revision/1_reviews.json') as reviews:
iw._pr_reviews = json.load(reviews)
iw._history.merge_reviews(iw.reviews)
self.meta[u'component_maintainers'] = [u'mkrizek', u'jctanner']
facts = get_needs_revision_facts(AnsibleTriageMock(), iw, self.meta, ShippableRunsMock())
self.assertTrue(facts[u'is_needs_revision'])
示例13: get_download_url
# 需要导入模块: import github [as 别名]
# 或者: from github import com [as 别名]
def get_download_url(full_name, path):
url = content_url % (full_name, default_branch, path)
if github.test_url(url): return url
# didn't work, need to get the branch name
response = requests.get("https://api.github.com/repos/%s/branches" % full_name).json()
for attempt in response:
branch = attempt['name']
url = content_url % (full_name, branch, path)
if github.test_url(url): return url
raise githubException('No available download link')
示例14: file_repo_gen
# 需要导入模块: import github [as 别名]
# 或者: from github import com [as 别名]
def file_repo_gen(repo_file, g):
with open(repo_file, 'r') as f:
for line in f:
repo_str = line.rstrip().split('github.com/')[-1]
yield g.get_repo(repo_str)
示例15: download_files
# 需要导入模块: import github [as 别名]
# 或者: from github import com [as 别名]
def download_files(args, g, repo_gen):
file_counter = 0
for repo in repo_gen:
try:
logging.info('Fetching repository: %s (id: %i)' % (repo.full_name, repo.id))
tree = repo.get_git_tree('master', recursive=True)
files_to_download = []
for file in tree.tree:
if fnmatch.fnmatch(file.path, args.wildcard):
files_to_download.append('https://github.com/%s/raw/master/%s' % (repo.full_name, file.path))
for file in files_to_download:
logging.info('Downloading %s' % file)
file = quote(file)
file_counter += 1
filename = posixpath.basename(urlparse.urlsplit(file).path)
output_path = os.path.join(args.output_dir, filename)
if os.path.exists(output_path):
output_path += "-" + str(file_counter)
try:
urlretrieve(file, output_path)
except Exception:
logging.exception('Error downloading %s.' % file)
except Exception:
logging.exception('Error fetching repository.')
args.yara_meta = os.path.join(args.output_dir, args.yara_meta)
with open(args.yara_meta, 'w') as f:
for i in os.listdir(args.output_dir):
try:
f.write("include \"" + i + "\"\n")
except Exception:
logging.exception('Couldn\'t write to %s.' % args.yara_meta)