From b4bd0d648ad3c36b19e15c66c74ed303c25a4574 Mon Sep 17 00:00:00 2001 From: Nathan Broadbent Date: Wed, 31 Aug 2011 12:14:09 +0800 Subject: [PATCH] Added 'short_revision' method to Deploy. 7 character SHAs are enough --- app/models/deploy.rb | 5 +++++ app/views/apps/index.html.haml | 2 +- app/views/apps/show.html.haml | 2 +- spec/models/deploy_spec.rb | 4 ++++ 4 files changed, 11 insertions(+), 2 deletions(-) diff --git a/app/models/deploy.rb b/app/models/deploy.rb index 3747293..49e0bc5 100644 --- a/app/models/deploy.rb +++ b/app/models/deploy.rb @@ -25,6 +25,10 @@ class Deploy app.errs.unresolved.in_env(environment).each {|err| err.resolve!} end + def short_revision + revision.to_s[0,7] + end + protected def should_notify? @@ -36,3 +40,4 @@ class Deploy end end + diff --git a/app/views/apps/index.html.haml b/app/views/apps/index.html.haml index 56fc27f..0f49ba7 100644 --- a/app/views/apps/index.html.haml +++ b/app/views/apps/index.html.haml @@ -12,7 +12,7 @@ - @apps.each do |app| %tr %td.name= link_to app.name, app_path(app) - %td.deploy= app.last_deploy_at ? link_to( app.last_deploy_at.to_s(:micro) << " (#{app.deploys.last.revision.to_s[0,7]})", app_deploys_path(app)) : 'n/a' + %td.deploy= app.last_deploy_at ? link_to( app.last_deploy_at.to_s(:micro) << " (#{app.deploys.last.short_revision})", app_deploys_path(app)) : 'n/a' %td.count - if app.errs.count > 0 = link_to app.errs.unresolved.count, app_path(app) diff --git a/app/views/apps/show.html.haml b/app/views/apps/show.html.haml index 65ba034..5ba3050 100644 --- a/app/views/apps/show.html.haml +++ b/app/views/apps/show.html.haml @@ -77,7 +77,7 @@ %td.who #{deploy.username} %td.message #{deploy.message} %td.repository #{deploy.repository} - %td.revision #{deploy.revision} + %td.revision #{deploy.short_revision} = link_to "All Deploys (#{@app.deploys.count})", app_deploys_path(@app), :class => 'button' - else %h3 No deploys diff --git a/spec/models/deploy_spec.rb b/spec/models/deploy_spec.rb index 131419b..1908bfb 100644 --- a/spec/models/deploy_spec.rb +++ b/spec/models/deploy_spec.rb @@ -51,4 +51,8 @@ describe Deploy do end end + it "should produce a shortened revision with 7 characters" do + Deploy.new(:revision => "1234567890abcdef").short_revision.should == "1234567" + end end + -- libgit2 0.21.2