Skip to content

Commit

Permalink
Merge pull request #74 from alphagov/candidate-deploy-view
Browse files Browse the repository at this point in the history
Candidate deploy view
  • Loading branch information
dhwthompson committed Jan 28, 2015
2 parents 9ce61ac + 3a98e0c commit 31b8d01
Show file tree
Hide file tree
Showing 6 changed files with 177 additions and 10 deletions.
30 changes: 30 additions & 0 deletions app/assets/stylesheets/application.scss
Expand Up @@ -21,3 +21,33 @@ h1 {
@extend .text-muted;
padding-left: 1em;
}

table.commits td.hash,
.commit-hash {
font-family: monospace;
}

.deployment {
margin: 0 0 10px 0;

.env {
min-width: 8em;
}

time {
// to match `.label`
font-size: 75%;
}

&.production {
.env {
background: $production-color
}
}
}

.release-tag {
&.label a {
color: #fff;
}
}
27 changes: 23 additions & 4 deletions app/controllers/applications_controller.rb
@@ -1,6 +1,6 @@
class ApplicationsController < ApplicationController
before_filter :redirect_if_read_only_user, only: [:new, :edit, :create, :update, :update_notes]
before_filter :find_application, only: [:show, :edit, :update, :update_notes]
before_filter :find_application, only: [:show, :edit, :update, :update_notes, :deploy]

def index
@environments = ["staging", "production"]
Expand All @@ -25,11 +25,11 @@ def show
@latest_deploy_to_each_environment_by_version[deployment.version] << deployment
end

production_deploy = @application.deployments.last_deploy_to "production"
if production_deploy
@production_deploy = @application.deployments.last_deploy_to "production"
if @production_deploy
comparison = github.compare(
@application.repo,
production_deploy.version,
@production_deploy.version,
"master"
)
# The `compare` API shows commits in forward chronological order
Expand All @@ -52,6 +52,25 @@ def new
def edit
end

def deploy
@release_tag = params[:tag]

@production_deploy = @application.deployments.last_deploy_to "production"
if @production_deploy
comparison = github.compare(
@application.repo,
@production_deploy.version,
@release_tag
)
# The `compare` API shows commits in forward chronological order
@commits = comparison.commits.reverse
end
@github_available = true
rescue Octokit::NotFound => e
@github_available = false
@github_error = e
end

def create
@application = Application.new(params[:application])

Expand Down
8 changes: 8 additions & 0 deletions app/models/application.rb
Expand Up @@ -52,4 +52,12 @@ def fallback_shortname
def repo_url
"https://#{domain}/#{repo}"
end

def repo_compare_url(from, to)
"https://#{domain}/#{repo}/compare/#{from}...#{to}"
end

def repo_tag_url(tag)
"https://#{domain}/#{repo}/releases/tag/#{tag}"
end
end
105 changes: 105 additions & 0 deletions app/views/applications/deploy.html.erb
@@ -0,0 +1,105 @@
<% content_for :page_title, @application.name %>

<div class="page-header">
<h1 class="remove-bottom-margin">
<span class="name">Deploy <%= @application.name %></span>
<span class="shortname">(<%= @application.shortname %>)</span>
</h1>
<%= link_to @application.repo_url, @application.repo_url, target: "_blank" %>
</div>

<main>
<h2>Candidate Release <span class="label label-info"><%= @release_tag %></span></h2>
<p class="lead add-top-margin">Production is <span class="label label-danger"><%= @production_deploy.version %></span> &mdash; deployed at <%= human_datetime(@production_deploy.created_at) %></p>

<% unless @application.staging_and_production_in_sync? %>
<div class="callout callout-danger">
<div class="callout-title">Production and Staging are not in sync</div>
<div class="callout-body">Proceed with caution and check the <a href="<%= @application.repo_compare_url('deployed-to-production', 'deployed-to-staging') %>">differences between production and staging</a></div>
</div>
<% end %>

<p class="pull-right">
<a class="btn btn-default" href="<%= @application.repo_compare_url(@production_deploy.version, @release_tag) %>">
<i class="glyphicon glyphicon-new-window add-right-margin"></i>Show full Commit
</a>
<a class="btn btn-default" href="<%= @application.repo_compare_url(@production_deploy.version, @release_tag) %>">
<i class="glyphicon glyphicon-new-window add-right-margin"></i>Full Diff
</a>
</p>

<p class="lead"><%= @commits.length %> <%= 'commit'.pluralize(@commits.length) %></p>

<% if @github_available %>
<table class="table table-striped table-bordered table-hover commits" data-module="filterable-table">
<thead>
<tr class="table-header">
<th width="10%">Hash</th>
<th width="55%">Message</th>
<th width="20%">Author</th>
<th width="15%">Date</th>
</tr>
<tr class="if-no-js-hide table-header-secondary">
<td colspan="4">
<form>
<label for="table-filter" class="rm">Filter commits</label>
<input id="table-filter" type="text" class="form-control normal js-filter-table-input" placeholder="Filter commits">
</form>
</td>
</tr>
</thead>
<tbody>
<% @commits.each do |commit| %>
<tr>
<td class="hash">
<%= link_to commit[:sha][0..8], "#{@application.repo_url}/commit/#{commit[:sha]}", target: "_blank" %>
</td>
<td class="message">
<% summary, body = commit[:commit][:message].split(/\n/, 2) %>
<a href="<%= "#{@application.repo_url}/commit/#{commit[:sha]}" %>" target="_blank"><%= summary %></a>
</td>
<td class="">
<% if commit[:commit][:author] %>
<img height="20" width="20" class="avatar" src="<%= commit[:author][:avatar_url] %>" alt="" />
<span class="name">
<%= commit[:commit][:author][:name] %>
</span>
<% end %>
</td>
<td calss="date">
<% if commit[:commit][:author] %>
<% commit_date = commit[:commit][:author][:date] %>
<span class="date"><%= commit_date.to_date.to_s(:short) =%></span>
<span class="time"><%= commit_date.to_s(:govuk_time) =%></span>
<% end %>
</td>
</tr>
<% end %>
</tbody>
</table>
<% else %>
<div class="alert alert-error">
Couldn't get data from GitHub:
<br>
<%= @github_error %>
</div>
<% end %>
</table>

<h2>Deploy</h2>
<div class="row">
<div class="col-md-3">
<a href="https://www.flickr.com/photos/fatty/9158066939/"><img title="Obey the Badger of Deploy" src="https://farm3.staticflickr.com/2835/9158066939_374360ed56_n.jpg" alt="Obey the Badger of Deploy" width="229" height="320"></a>
</div>

<div class="col-md-9">
<h3>Test on Staging</h3>
<p>Make sure you're using the <code>govuk_select_organisation</code> script to test against the staging environment.</p>
<p><a class="btn btn-primary add-bottom-margin" href="https://deploy.staging.alphagov.co.uk/job/Staging_Deploy/parambuild?TARGET_APPLICATION=<%= @application.shortname %>&amp;TAG=<%= @release_tag %>">Deploy to Staging</a></p>

<h3>Promote to Production</h3>
<p><a class="btn btn-danger" href="https://deploy.production.alphagov.co.uk/job/Production_Deploy/parambuild?TARGET_APPLICATION=<%= @application.shortname %>&amp;TAG=<%= @release_tag %>">Deploy to Production</a></p>
</div>
</div>

</main>
13 changes: 7 additions & 6 deletions app/views/applications/show.html.erb
Expand Up @@ -37,17 +37,18 @@
<% tags.each do |tag| %>
<% if deployments = @latest_deploy_to_each_environment_by_version[tag[:name]] %>
<% deployments.each do |deployment| %>
<%= deployment.environment %>
at
<%= human_datetime(deployment.created_at) %>
<br>
<p class="deployment <%= 'production' if deployment.environment == 'production' %>">
<strong class="label label-default env"><%= deployment.environment.humanize %></strong>
<span class="rm">at</span>
<%= time_tag(deployment.created_at, human_datetime(deployment.created_at)) %>
</p>
<% end %>
<% end %>
<% end %>
</td>
<td>
<% tags.each do |tag| %>
<span class="label label-info"><%= tag[:name] %></span>
<span class="release-tag label label-info"><a href="<%= deploy_application_path(@application) %>?tag=<%= tag[:name] %>"><%= tag[:name] %></a></span>
<% end %>
</td>
<% else %>
Expand All @@ -62,7 +63,7 @@
</span>
<% end %>
<small>
<%= link_to commit[:sha], "#{@application.repo_url}/commit/#{commit[:sha]}", target: "_blank", class: "pull-right" %>
<%= link_to commit[:sha][0..8], "#{@application.repo_url}/commit/#{commit[:sha]}", target: "_blank", class: "commit-hash pull-right" %>
</small>
</td>
</tr>
Expand Down
4 changes: 4 additions & 0 deletions config/routes.rb
Expand Up @@ -8,6 +8,10 @@
put :update_notes
end

member do
get :deploy
end

resources :deployments
end

Expand Down

0 comments on commit 31b8d01

Please sign in to comment.