class Gitstamp::Commit

A Gitstamp commit contains the Git commit message and relevant metadata.

Public Class Methods

from_git(git, author: nil, committer: nil, link: nil) click to toggle source

Constructs a Gitstamp commit from a Git commit.

@param [Rugged::Commit] git the Git commit object @param [URI, to_s] author an optional author URI override @param [URI, to_s] committer an optional committer URI override @param [URI, to_s] link an optional commit link URL @return [Commit]

# File lib/gitstamp/commit.rb, line 14
def self.from_git(git, author: nil, committer: nil, link: nil)
  self.new(
    id: git.oid.to_s,
    link: link&.to_s,
    author: (author || "mailto:#{git.author[:email]}").to_s,
    committer: (committer || "mailto:#{git.committer[:email]}").to_s,
    committer_date: git.committer[:time],  # preserves the timezone
    message: git.message.to_s,
  )
end

Public Instance Methods

to_tags() click to toggle source

Returns the Arweave metadata tags for this commit.

@return [Hash<String, String>]

# File lib/gitstamp/commit.rb, line 29
def to_tags
  {
    'Content-Type' => 'text/plain',
    'App-Name' => 'Gitstamp',
    'Git-Commit' => self.id.to_s,
    'Git-Commit-Link' => self.link&.to_s,
    'Git-Author' => self.author&.to_s,
    'Git-Committer' => self.committer&.to_s,
    'Git-Committer-Date' => self.committer_date&.strftime("%Y-%m-%dT%H:%M:%S%:z"),
  }.delete_if { |k, v| v.nil? }
end