Sha256: d495aa4fe5872342dfa671b71d900938b105f6c6ddd4b497c44b1c18fc8e76a4

Contents?: true

Size: 1.42 KB

Versions: 1

Compression:

Stored size: 1.42 KB

Contents

class CommitPresenter
  include UrlHelper
  
  def initialize(commits)
    @commits = OneOrMany.new(commits)
  end
  
  def as_json(*args)
    @commits.map(&method(:commit_to_json))
  end
  
  def commit_to_json(commit)
    hash = {
      id: commit.id,
      sha: commit.sha,
      message: commit.summary,
      project: commit.project.slug,
      linkTo: github_commit_url(commit.project, commit.sha), # <-- !todo: more abstract
      committer: {
        name: commit.committer,
        email: commit.committer_email } }
    
    release = commit.releases.earliest
    if release
      # NB: we want to sort these with TesterNotes
      #     by the field 'createdAt', so while this
      #     _actually_ represents 'releasedAt', we'll
      #     call it 'createdAt' for now.
      hash[:createdAt] = release.created_at
      hash[:environment] = release.environment_name
    end
    hash
  end
  
  def verbose
    @commits.map do |commit|
      commit_to_json(commit).merge({
        tag: commit.tags.first,
        hours: commit.hours_worked,
        tickets: commit.ticket_numbers,
        unreachable: commit.unreachable,
        releases: commit.releases.map { |release| {
          environment: release.environment_name,
          createdAt: release.created_at } },
        committers: commit.committers.map { |committer| {
          id: committer.id,
          email: committer.email,
          name: committer.name } } })
    end
  end
  
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
houston-core-0.5.0.beta1 app/presenters/commit_presenter.rb