Adapt to new Gitaly commit message format
This commit is contained in:
parent
7ee7d3f979
commit
90f8feae46
3 changed files with 59 additions and 4 deletions
|
@ -210,6 +210,8 @@ module Gitlab
|
||||||
init_from_hash(raw_commit)
|
init_from_hash(raw_commit)
|
||||||
elsif raw_commit.is_a?(Rugged::Commit)
|
elsif raw_commit.is_a?(Rugged::Commit)
|
||||||
init_from_rugged(raw_commit)
|
init_from_rugged(raw_commit)
|
||||||
|
elsif raw_commit.is_a?(Gitaly::GitCommit)
|
||||||
|
init_from_gitaly(raw_commit)
|
||||||
else
|
else
|
||||||
raise "Invalid raw commit type: #{raw_commit.class}"
|
raise "Invalid raw commit type: #{raw_commit.class}"
|
||||||
end
|
end
|
||||||
|
@ -371,6 +373,24 @@ module Gitlab
|
||||||
@parent_ids = commit.parents.map(&:oid)
|
@parent_ids = commit.parents.map(&:oid)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def init_from_gitaly(commit)
|
||||||
|
@raw_commit = commit
|
||||||
|
@id = commit.id
|
||||||
|
# NOTE: For ease of parsing in Gitaly, we have only the subject of
|
||||||
|
# the commit and not the full message.
|
||||||
|
# TODO: Once gitaly "takes over" Rugged consider separating the
|
||||||
|
# subject from the message to make it clearer when there's one
|
||||||
|
# available but not the other.
|
||||||
|
@message = commit.subject.dup
|
||||||
|
@authored_date = Time.at(commit.author.date.seconds)
|
||||||
|
@author_name = commit.author.name.dup
|
||||||
|
@author_email = commit.author.email.dup
|
||||||
|
@committed_date = Time.at(commit.committer.date.seconds)
|
||||||
|
@committer_name = commit.committer.name.dup
|
||||||
|
@committer_email = commit.committer.email.dup
|
||||||
|
@parent_ids = commit.parent_ids
|
||||||
|
end
|
||||||
|
|
||||||
def serialize_keys
|
def serialize_keys
|
||||||
SERIALIZE_KEYS
|
SERIALIZE_KEYS
|
||||||
end
|
end
|
||||||
|
|
|
@ -96,11 +96,11 @@ module Gitlab
|
||||||
id: response.commit_id,
|
id: response.commit_id,
|
||||||
message: message,
|
message: message,
|
||||||
authored_date: Time.at(response.commit_author.date.seconds),
|
authored_date: Time.at(response.commit_author.date.seconds),
|
||||||
author_name: response.commit_author.name,
|
author_name: response.commit_author.name.dup,
|
||||||
author_email: response.commit_author.email,
|
author_email: response.commit_author.email.dup,
|
||||||
committed_date: Time.at(response.commit_committer.date.seconds),
|
committed_date: Time.at(response.commit_committer.date.seconds),
|
||||||
committer_name: response.commit_committer.name,
|
committer_name: response.commit_committer.name.dup,
|
||||||
committer_email: response.commit_committer.email
|
committer_email: response.commit_committer.email.dup
|
||||||
}
|
}
|
||||||
|
|
||||||
Gitlab::Git::Commit.decorate(hash)
|
Gitlab::Git::Commit.decorate(hash)
|
||||||
|
|
|
@ -64,6 +64,41 @@ describe Gitlab::Git::Commit, seed_helper: true do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe "Commit info from gitaly commit" do
|
||||||
|
let(:id) { 'f00' }
|
||||||
|
let(:subject) { "My commit".force_encoding('ASCII-8BIT') }
|
||||||
|
let(:committer) do
|
||||||
|
Gitaly::CommitAuthor.new(
|
||||||
|
name: generate(:name),
|
||||||
|
email: generate(:email),
|
||||||
|
date: Google::Protobuf::Timestamp.new(seconds: 123)
|
||||||
|
)
|
||||||
|
end
|
||||||
|
let(:author) do
|
||||||
|
Gitaly::CommitAuthor.new(
|
||||||
|
name: generate(:name),
|
||||||
|
email: generate(:email),
|
||||||
|
date: Google::Protobuf::Timestamp.new(seconds: 456)
|
||||||
|
)
|
||||||
|
end
|
||||||
|
let(:gitaly_commit) do
|
||||||
|
Gitaly::GitCommit.new(
|
||||||
|
id: id, subject: subject, author: author, committer: committer
|
||||||
|
)
|
||||||
|
end
|
||||||
|
let(:commit) { described_class.new(gitaly_commit) }
|
||||||
|
|
||||||
|
it { expect(commit.short_id).to eq(id[0..10]) }
|
||||||
|
it { expect(commit.id).to eq(id) }
|
||||||
|
it { expect(commit.sha).to eq(id) }
|
||||||
|
it { expect(commit.safe_message).to eq(subject) }
|
||||||
|
it { expect(commit.created_at).to eq(Time.at(committer.date.seconds)) }
|
||||||
|
it { expect(commit.author_email).to eq(author.email) }
|
||||||
|
it { expect(commit.author_name).to eq(author.name) }
|
||||||
|
it { expect(commit.committer_name).to eq(committer.name) }
|
||||||
|
it { expect(commit.committer_email).to eq(committer.email) }
|
||||||
|
end
|
||||||
|
|
||||||
context 'Class methods' do
|
context 'Class methods' do
|
||||||
describe '.find' do
|
describe '.find' do
|
||||||
it "should return first head commit if without params" do
|
it "should return first head commit if without params" do
|
||||||
|
|
Loading…
Reference in a new issue