本文整理汇总了Python中pagure.lib.repo.PagureRepo.lookup_reference方法的典型用法代码示例。如果您正苦于以下问题:Python PagureRepo.lookup_reference方法的具体用法?Python PagureRepo.lookup_reference怎么用?Python PagureRepo.lookup_reference使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pagure.lib.repo.PagureRepo
的用法示例。
在下文中一共展示了PagureRepo.lookup_reference方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_git_tags_objects
# 需要导入模块: from pagure.lib.repo import PagureRepo [as 别名]
# 或者: from pagure.lib.repo.PagureRepo import lookup_reference [as 别名]
def get_git_tags_objects(project):
""" Returns the list of references of the tags created in the git
repositorie the specified project.
The list is sorted using the time of the commit associated to the tag """
repopath = pagure.get_repo_path(project)
repo_obj = PagureRepo(repopath)
tags = {}
for tag in repo_obj.listall_references():
if 'refs/tags/' in tag and repo_obj.lookup_reference(tag):
commit_time = ""
theobject = repo_obj[repo_obj.lookup_reference(tag).target]
objecttype = ""
if isinstance(theobject, pygit2.Tag):
commit_time = theobject.get_object().commit_time
objecttype = "tag"
elif isinstance(theobject, pygit2.Commit):
commit_time = theobject.commit_time
objecttype = "commit"
tags[commit_time] = {
"object":repo_obj[repo_obj.lookup_reference(tag).target],
"tagname":tag.replace("refs/tags/",""),
"date":commit_time,
"objecttype": objecttype
}
sorted_tags = []
for tag in sorted(tags, reverse=True):
sorted_tags.append(tags[tag])
return sorted_tags
示例2: get_git_tags_objects
# 需要导入模块: from pagure.lib.repo import PagureRepo [as 别名]
# 或者: from pagure.lib.repo.PagureRepo import lookup_reference [as 别名]
def get_git_tags_objects(project):
""" Returns the list of references of the tags created in the git
repositorie the specified project.
The list is sorted using the time of the commit associated to the tag """
repopath = pagure.get_repo_path(project)
repo_obj = PagureRepo(repopath)
tags = [
repo_obj[repo_obj.lookup_reference(tag).target]
for tag in repo_obj.listall_references()
if 'refs/tags/' in tag and repo_obj.lookup_reference(tag)
]
sorted_tags = []
tags_sort = {}
for tag in tags:
# If the object is a tag, get his associated commit time
if isinstance(tag, pygit2.Tag):
tags_sort[tag.get_object().commit_time] = tag
elif isinstance(tag, pygit2.Commit):
tags_sort[tag.commit_time] = tag
# If object is neither a tag or commit return an unsorted list
else:
return tags
for tag in sorted(tags_sort, reverse=True):
sorted_tags.append(tags_sort[tag])
return sorted_tags
示例3: get_git_tags_objects
# 需要导入模块: from pagure.lib.repo import PagureRepo [as 别名]
# 或者: from pagure.lib.repo.PagureRepo import lookup_reference [as 别名]
def get_git_tags_objects(project):
""" Returns the list of references of the tags created in the git
repositorie the specified project.
"""
repopath = pagure.get_repo_path(project)
repo_obj = PagureRepo(repopath)
tags = [
repo_obj[repo_obj.lookup_reference(tag).target]
for tag in repo_obj.listall_references()
if 'refs/tags/' in tag and repo_obj.lookup_reference(tag)
]
return tags
示例4: get_git_tags_objects
# 需要导入模块: from pagure.lib.repo import PagureRepo [as 别名]
# 或者: from pagure.lib.repo.PagureRepo import lookup_reference [as 别名]
def get_git_tags_objects(project):
""" Returns the list of references of the tags created in the git
repositorie the specified project.
The list is sorted using the time of the commit associated to the tag """
repopath = pagure.get_repo_path(project)
repo_obj = PagureRepo(repopath)
tags = {}
for tag in repo_obj.listall_references():
if 'refs/tags/' in tag and repo_obj.lookup_reference(tag):
commit_time = ""
theobject = repo_obj[repo_obj.lookup_reference(tag).target]
objecttype = ""
if isinstance(theobject, pygit2.Tag):
commit_time = theobject.get_object().commit_time
objecttype = "tag"
elif isinstance(theobject, pygit2.Commit):
commit_time = theobject.commit_time
objecttype = "commit"
tags[commit_time] = {
"object": repo_obj[repo_obj.lookup_reference(tag).target],
"tagname": tag.replace("refs/tags/",""),
"date": commit_time,
"objecttype": objecttype,
"head_msg": None,
"body_msg": None,
}
if objecttype == 'tag':
head_msg, _, body_msg = tags[commit_time][
"object"].message.partition('\n')
if body_msg.strip().endswith('\n-----END PGP SIGNATURE-----'):
body_msg = body_msg.rsplit(
'-----BEGIN PGP SIGNATURE-----', 1)[0].strip()
tags[commit_time]["head_msg"] = head_msg
tags[commit_time]["body_msg"] = body_msg
sorted_tags = []
for tag in sorted(tags, reverse=True):
sorted_tags.append(tags[tag])
return sorted_tags
示例5: test_diff_pull_request
# 需要导入模块: from pagure.lib.repo import PagureRepo [as 别名]
# 或者: from pagure.lib.repo.PagureRepo import lookup_reference [as 别名]
def test_diff_pull_request(self):
""" Test pagure.lib.git.diff_pull_request """
gitrepo = os.path.join(self.path, "repos", "test.git")
gitrepo2 = os.path.join(
self.path, "repos", "forks", "pingou", "test.git"
)
request = pagure.lib.query.search_pull_requests(
self.session, requestid=1, project_id=1
)
diff_commits, diff = pagure.lib.git.diff_pull_request(
self.session,
request=request,
repo_obj=PagureRepo(gitrepo2),
orig_repo=PagureRepo(gitrepo),
with_diff=True,
)
self.assertEqual(len(diff_commits), 2)
self.assertEqual(
diff_commits[0].message,
"Second edit on side branch of the file sources for testing",
)
self.assertEqual(
diff_commits[1].message,
"New edition on side branch of the file sources for testing",
)
# Check that the PR has its PR refs
# we don't know the task id but we'll give it 30 sec to finish
cnt = 0
repo = PagureRepo(gitrepo)
self.assertIn("refs/pull/1/head", list(repo.listall_references()))
self.assertTrue(cnt < 60)
pr_ref = repo.lookup_reference("refs/pull/1/head")
commit = pr_ref.peel()
self.assertEqual(commit.oid.hex, diff_commits[0].oid.hex)
示例6: test_two_diff_pull_request_sequentially
# 需要导入模块: from pagure.lib.repo import PagureRepo [as 别名]
# 或者: from pagure.lib.repo.PagureRepo import lookup_reference [as 别名]
def test_two_diff_pull_request_sequentially(self):
""" Test calling pagure.lib.git.diff_pull_request twice returns
the same data
"""
gitrepo = os.path.join(self.path, "repos", "test.git")
gitrepo2 = os.path.join(
self.path, "repos", "forks", "pingou", "test.git"
)
request = pagure.lib.query.search_pull_requests(
self.session, requestid=1, project_id=1
)
# Get the diff corresponding to the PR and check its ref
diff_commits, diff = pagure.lib.git.diff_pull_request(
self.session,
request=request,
repo_obj=PagureRepo(gitrepo2),
orig_repo=PagureRepo(gitrepo),
with_diff=True,
)
self.assertEqual(len(diff_commits), 2)
# Check that the PR has its PR refs
# we don't know the task id but we'll give it 30 sec to finish
cnt = 0
repo = PagureRepo(gitrepo)
self.assertIn("refs/pull/1/head", list(repo.listall_references()))
self.assertTrue(cnt < 60)
pr_ref = repo.lookup_reference("refs/pull/1/head")
commit = pr_ref.peel()
self.assertEqual(commit.oid.hex, diff_commits[0].oid.hex)
# Run diff_pull_request a second time
diff_commits2, diff = pagure.lib.git.diff_pull_request(
self.session,
request=request,
repo_obj=PagureRepo(gitrepo2),
orig_repo=PagureRepo(gitrepo),
with_diff=True,
)
self.assertEqual(len(diff_commits2), 2)
self.assertEqual(
[d.oid.hex for d in diff_commits2],
[d.oid.hex for d in diff_commits],
)
# Check that the PR has its PR refs
# we don't know the task id but we'll give it 30 sec to finish
cnt = 0
repo = PagureRepo(gitrepo)
self.assertIn("refs/pull/1/head", list(repo.listall_references()))
self.assertTrue(cnt < 60)
pr_ref = repo.lookup_reference("refs/pull/1/head")
commit2 = pr_ref.peel()
self.assertEqual(commit2.oid.hex, diff_commits[0].oid.hex)
self.assertEqual(commit.oid.hex, commit2.oid.hex)
示例7: test_diff_pull_request_updated
# 需要导入模块: from pagure.lib.repo import PagureRepo [as 别名]
# 或者: from pagure.lib.repo.PagureRepo import lookup_reference [as 别名]
def test_diff_pull_request_updated(self):
""" Test that calling pagure.lib.git.diff_pull_request on an updated
PR updates the PR reference
"""
gitrepo = os.path.join(self.path, "repos", "test.git")
gitrepo2 = os.path.join(
self.path, "repos", "forks", "pingou", "test.git"
)
request = pagure.lib.query.search_pull_requests(
self.session, requestid=1, project_id=1
)
# Get the diff corresponding to the PR and check its ref
diff_commits, diff = pagure.lib.git.diff_pull_request(
self.session,
request=request,
repo_obj=PagureRepo(gitrepo2),
orig_repo=PagureRepo(gitrepo),
with_diff=True,
)
self.assertEqual(len(diff_commits), 2)
# Check that the PR has its PR refs
# we don't know the task id but we'll give it 30 sec to finish
cnt = 0
repo = PagureRepo(gitrepo)
self.assertIn("refs/pull/1/head", list(repo.listall_references()))
self.assertTrue(cnt < 60)
pr_ref = repo.lookup_reference("refs/pull/1/head")
commit = pr_ref.peel()
self.assertEqual(commit.oid.hex, diff_commits[0].oid.hex)
# Add a new commit on the fork
repopath = os.path.join(self.path, "pingou_test2")
clone_repo = pygit2.clone_repository(
gitrepo2, repopath, checkout_branch="feature_foo"
)
with open(os.path.join(repopath, "sources"), "w") as stream:
stream.write("foo\n bar\nbaz\nhey there\n")
clone_repo.index.add("sources")
clone_repo.index.write()
last_commit = clone_repo.lookup_branch("feature_foo").peel()
# Commits the files added
tree = clone_repo.index.write_tree()
author = pygit2.Signature("Alice Author", "[email protected]")
committer = pygit2.Signature("Cecil Committer", "[email protected]")
last_commit = clone_repo.create_commit(
"refs/heads/feature_foo", # the name of the reference to update
author,
committer,
"Third edit on side branch of the file sources for testing",
# binary string representing the tree object ID
tree,
# list of binary strings representing parents of the new commit
[last_commit.oid.hex],
)
# Push to the fork repo
ori_remote = clone_repo.remotes[0]
refname = "refs/heads/feature_foo:refs/heads/feature_foo"
PagureRepo.push(ori_remote, refname)
# Get the new diff for that PR and check its new ref
diff_commits, diff = pagure.lib.git.diff_pull_request(
self.session,
request=request,
repo_obj=PagureRepo(gitrepo2),
orig_repo=PagureRepo(gitrepo),
with_diff=True,
)
self.assertEqual(len(diff_commits), 3)
# Check that the PR has its PR refs
# we don't know the task id but we'll give it 30 sec to finish
cnt = 0
repo = PagureRepo(gitrepo)
self.assertIn("refs/pull/1/head", list(repo.listall_references()))
self.assertTrue(cnt < 60)
pr_ref = repo.lookup_reference("refs/pull/1/head")
commit2 = pr_ref.peel()
self.assertEqual(commit2.oid.hex, diff_commits[0].oid.hex)
self.assertNotEqual(commit.oid.hex, commit2.oid.hex)