本文整理汇总了Python中reviewboard.scmtools.core.Commit类的典型用法代码示例。如果您正苦于以下问题:Python Commit类的具体用法?Python Commit怎么用?Python Commit使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Commit类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_commits
def get_commits(self, repository, start=None):
results = []
resource = 'commits'
url = self._build_api_url(self._get_repo_api_url(repository), resource)
if start:
url += '&sha=%s' % start
try:
rsp = self._api_get(url)
except Exception as e:
logging.warning('Failed to fetch commits from %s: %s',
url, e)
return results
for item in rsp:
commit = Commit(
item['commit']['author']['name'],
item['sha'],
item['commit']['committer']['date'],
item['commit']['message'])
if item['parents']:
commit.parent = item['parents'][0]['sha']
results.append(commit)
return results
示例2: get_change
def get_change(self, revision):
"""Get an individual change.
This returns a Commit object containing the details of the commit.
"""
revision = int(revision)
commits = self.client.get_log('/', start=revision, limit=2)
commit = commits[0]
message = commit.get('message', b'').decode('utf-8', 'replace')
author_name = commit.get('author', b'').decode('utf-8', 'replace')
date = commit['date'].isoformat()
if len(commits) > 1:
base_revision = commits[1]['revision']
else:
base_revision = 0
try:
enc, diff = convert_to_unicode(
self.client.diff(base_revision, revision),
self.repository.get_encoding_list())
except Exception as e:
raise self.normalize_error(e)
commit = Commit(author_name, six.text_type(revision), date,
message, six.text_type(base_revision))
commit.diff = diff
return commit
示例3: get_commits
def get_commits(self, repository, branch=None, start=None):
url = self._build_repository_api_url(repository,
'changesets/?limit=20')
start = start or branch
if start:
url += '&start=%s' % start
results = []
# The API returns them in order from oldest to newest.
for changeset in reversed(self._api_get(url)['changesets']):
commit = Commit(
author_name=changeset['author'],
id=changeset['raw_node'],
date=self._parse_timestamp(changeset['utctimestamp']),
message=changeset['message'],
base_commit_id=changeset['raw_node'])
if changeset['parents']:
commit.parent = changeset['parents'][0]
results.append(commit)
return results
示例4: _parse_commit
def _parse_commit(self, meta, diff=None):
"""Parse and return the meta response and return a Commit.
Args:
meta (dict):
A member of the JSON response from the ``all-commits``
endpoint corresponding to a single commit.
diff (bytes, optional):
The diff corresponding to the commit.
Returns:
reviewboard.scmtools.core.Commit:
The parsed commit.
"""
commit = Commit(
author_name=meta['author'],
id=meta['revision'],
date=meta['time'],
message=meta['message'],
diff=diff
)
if meta['parents']:
commit.parent = meta['parents'][0]
return commit
示例5: get_commits
def get_commits(self, repository, start=None):
results = []
resource = "commits"
url = self._build_api_url(self._get_repo_api_url(repository), resource)
if start:
url += "&sha=%s" % start
try:
rsp = self._api_get(url)
except Exception as e:
logging.warning("Failed to fetch commits from %s: %s", url, e)
return results
for item in rsp:
commit = Commit(
item["commit"]["author"]["name"],
item["sha"],
item["commit"]["committer"]["date"],
item["commit"]["message"],
)
if item["parents"]:
commit.parent = item["parents"][0]["sha"]
results.append(commit)
return results
示例6: get_change
def get_change(self, revision, cache_key):
"""Get an individual change.
This returns a tuple with the commit message and the diff contents.
"""
revision = int(revision)
commit = cache.get(cache_key)
if commit:
message = commit.message
author_name = commit.author_name
date = commit.date
base_revision = commit.parent
else:
commits = list(self.ra.iter_log(None, revision, 0, limit=2))
rev, props = commits[0][1:3]
message = props[SVN_LOG]
author_name = props[SVN_AUTHOR]
date = props[SVN_DATE]
if len(commits) > 1:
base_revision = commits[1][1]
else:
base_revision = 0
out, err = self.client.diff(base_revision, revision, self.repopath,
self.repopath, diffopts=DIFF_UNIFIED)
commit = Commit(author_name, six.text_type(revision), date,
message, six.text_type(base_revision))
commit.diff = out.read()
return commit
示例7: get_change
def get_change(repository, commit_to_get):
commit = Commit(
message='* This is a summary\n\n* This is a description.')
diff_filename = os.path.join(self.testdata_dir, 'git_readme.diff')
with open(diff_filename, 'r') as f:
commit.diff = f.read()
return commit
示例8: get_change
def get_change(self, revision):
"""Get an individual change.
This returns a tuple with the commit message and the diff contents.
"""
cache_key = self.repository.get_commit_cache_key(revision)
revision = int(revision)
head_revision = Revision(opt_revision_kind.number, revision)
commit = cache.get(cache_key)
if commit:
message = commit.message
author_name = commit.author_name
date = commit.date
base_revision = Revision(opt_revision_kind.number, commit.parent)
else:
commits = self.client.log(
self.repopath,
revision_start=head_revision,
limit=2)
commit = commits[0]
message = commit['message']
author_name = commit['author']
date = datetime.datetime.utcfromtimestamp(commit['date']).\
isoformat()
try:
commit = commits[1]
base_revision = commit['revision']
except IndexError:
base_revision = Revision(opt_revision_kind.number, 0)
tmpdir = mkdtemp(prefix='reviewboard-svn.')
diff = self.client.diff(
tmpdir,
self.repopath,
revision1=base_revision,
revision2=head_revision,
diff_options=['-u'])
rmtree(tmpdir)
commit = Commit(author_name, six.text_type(head_revision.number), date,
message, six.text_type(base_revision.number))
commit.diff = diff
return commit
示例9: get_commits
def get_commits(self, repository, branch=None, start=None):
repo_api_url = self._get_repo_api_url(repository)
commits = self.client.api_get_commits(repo_api_url, start=start)
results = []
for item in commits:
commit = Commit(
item['commit']['author']['name'],
item['sha'],
item['commit']['committer']['date'],
item['commit']['message'])
if item['parents']:
commit.parent = item['parents'][0]['sha']
results.append(commit)
return results
示例10: get_commits
def get_commits(self, repository, branch=None, start=None):
repo_api_url = self._get_repo_api_url(repository)
commits = self.client.api_get_commits(repo_api_url, start=start)
results = []
for item in commits:
commit = Commit(
item["commit"]["author"]["name"],
item["sha"],
item["commit"]["committer"]["date"],
item["commit"]["message"],
)
if item["parents"]:
commit.parent = item["parents"][0]["sha"]
results.append(commit)
return results
示例11: get_commits
def get_commits(self, repository, start=None):
resource = 'commits'
url = self._build_api_url(repository, resource)
if start:
url += '&sha=%s' % start
rsp = self._api_get(url)
results = []
for item in rsp:
commit = Commit(
item['commit']['author']['name'],
item['sha'],
item['commit']['committer']['date'],
item['commit']['message'])
if item['parents']:
commit.parent = item['parents'][0]['sha']
results.append(commit)
return results
示例12: _build_commit_from_rsp
def _build_commit_from_rsp(self, commit_rsp):
"""Return a Commit from an API reesponse.
This will parse a response from the API and return a structured
commit.
Args:
commit_rsp (dict):
The API payload for a commit.
Returns:
reviewboard.scmtools.core.Commit:
A commit based on the payload.
"""
commit = Commit(
author_name=commit_rsp['author']['raw'],
id=commit_rsp['hash'],
date=commit_rsp['date'],
message=commit_rsp['message'])
if commit_rsp['parents']:
commit.parent = commit_rsp['parents'][0]['hash']
return commit
示例13: get_change
def get_change(self, repository, revision):
repo_api_url = self._get_repo_api_url(repository)
# Step 1: fetch the commit itself that we want to review, to get
# the parent SHA and the commit message. Hopefully this information
# is still in cache so we don't have to fetch it again.
commit = cache.get(repository.get_commit_cache_key(revision))
if commit:
author_name = commit.author_name
date = commit.date
parent_revision = commit.parent
message = commit.message
else:
url = self._build_api_url(repo_api_url, "commits")
url += "&sha=%s" % revision
commit = self._api_get(url)[0]
author_name = commit["commit"]["author"]["name"]
date = (commit["commit"]["committer"]["date"],)
parent_revision = commit["parents"][0]["sha"]
message = commit["commit"]["message"]
# Step 2: fetch the "compare two commits" API to get the diff.
url = self._build_api_url(repo_api_url, "compare/%s...%s" % (parent_revision, revision))
comparison = self._api_get(url)
tree_sha = comparison["base_commit"]["commit"]["tree"]["sha"]
files = comparison["files"]
# Step 3: fetch the tree for the original commit, so that we can get
# full blob SHAs for each of the files in the diff.
url = self._build_api_url(repo_api_url, "git/trees/%s" % tree_sha)
url += "&recursive=1"
tree = self._api_get(url)
file_shas = {}
for file in tree["tree"]:
file_shas[file["path"]] = file["sha"]
diff = []
for file in files:
filename = file["filename"]
status = file["status"]
patch = file["patch"]
diff.append("diff --git a/%s b/%s" % (filename, filename))
if status == "modified":
old_sha = file_shas[filename]
new_sha = file["sha"]
diff.append("index %s..%s 100644" % (old_sha, new_sha))
diff.append("--- a/%s" % filename)
diff.append("+++ b/%s" % filename)
elif status == "added":
new_sha = file["sha"]
diff.append("new file mode 100644")
diff.append("index %s..%s" % ("0" * 40, new_sha))
diff.append("--- /dev/null")
diff.append("+++ b/%s" % filename)
elif status == "removed":
old_sha = file_shas[filename]
diff.append("deleted file mode 100644")
diff.append("index %s..%s" % (old_sha, "0" * 40))
diff.append("--- a/%s" % filename)
diff.append("+++ /dev/null")
diff.append(patch)
diff = "\n".join(diff)
# Make sure there's a trailing newline
if not diff.endswith("\n"):
diff += "\n"
commit = Commit(author_name, revision, date, message, parent_revision)
commit.diff = diff
return commit
示例14: get_change
def get_change(self, repository, revision):
# Step 1: fetch the commit itself that we want to review, to get
# the parent SHA and the commit message. Hopefully this information
# is still in cache so we don't have to fetch it again.
commit = cache.get(repository.get_commit_cache_key(revision))
if commit:
author_name = commit.author_name
date = commit.date
parent_revision = commit.parent
message = commit.message
else:
url = self._build_api_url(repository, 'commits')
url += '&sha=%s' % revision
commit = self._api_get(url)[0]
author_name = commit['commit']['author']['name']
date = commit['commit']['committer']['date'],
parent_revision = commit['parents'][0]['sha']
message = commit['commit']['message']
# Step 2: fetch the "compare two commits" API to get the diff.
url = self._build_api_url(
repository, 'compare/%s...%s' % (parent_revision, revision))
comparison = self._api_get(url)
tree_sha = comparison['base_commit']['commit']['tree']['sha']
files = comparison['files']
# Step 3: fetch the tree for the original commit, so that we can get
# full blob SHAs for each of the files in the diff.
url = self._build_api_url(repository, 'git/trees/%s' % tree_sha)
url += '&recursive=1'
tree = self._api_get(url)
file_shas = {}
for file in tree['tree']:
file_shas[file['path']] = file['sha']
diff = []
for file in files:
filename = file['filename']
status = file['status']
patch = file['patch']
diff.append('diff --git a/%s b/%s' % (filename, filename))
if status == 'modified':
old_sha = file_shas[filename]
new_sha = file['sha']
diff.append('index %s..%s 100644' % (old_sha, new_sha))
diff.append('--- a/%s' % filename)
diff.append('+++ b/%s' % filename)
elif status == 'added':
new_sha = file['sha']
diff.append('new file mode 100644')
diff.append('index %s..%s' % ('0' * 40, new_sha))
diff.append('--- /dev/null')
diff.append('+++ b/%s' % filename)
elif status == 'removed':
old_sha = file_shas[filename]
diff.append('deleted file mode 100644')
diff.append('index %s..%s' % (old_sha, '0' * 40))
diff.append('--- a/%s' % filename)
diff.append('+++ /dev/null')
diff.append(patch)
diff = '\n'.join(diff)
# Make sure there's a trailing newline
if not diff.endswith('\n'):
diff += '\n'
commit = Commit(author_name, revision, date, message, parent_revision)
commit.diff = diff
return commit
示例15: Commit
resource = 'commits'
url = self._build_api_url(repository, resource)
if start:
url += '&sha=%s' % start
try:
rsp = self._api_get(url)
except Exception, e:
logging.warning('Failed to fetch commits from %s: %s',
url, e)
return results
for item in rsp:
commit = Commit(
item['commit']['author']['name'],
item['sha'],
item['commit']['committer']['date'],
item['commit']['message'])
if item['parents']:
commit.parent = item['parents'][0]['sha']
results.append(commit)
return results
def get_change(self, repository, revision):
# Step 1: fetch the commit itself that we want to review, to get
# the parent SHA and the commit message. Hopefully this information
# is still in cache so we don't have to fetch it again.
commit = cache.get(repository.get_commit_cache_key(revision))
if commit: