Skip to content

Commit

Permalink
Add title property to tasks to control the task will be displayed i…
Browse files Browse the repository at this point in the history
…n the timeline
  • Loading branch information
byroot committed May 28, 2018
1 parent 51b9f9a commit ccfed09
Show file tree
Hide file tree
Showing 12 changed files with 83 additions and 2 deletions.
3 changes: 3 additions & 0 deletions .rubocop.yml
Expand Up @@ -171,3 +171,6 @@ Style/PercentLiteralDelimiters:

Style/FrozenStringLiteralComment:
Enabled: false

Style/FormatStringToken:
Enabled: false
1 change: 1 addition & 0 deletions CHANGELOG.md
@@ -1,5 +1,6 @@
# Unreleased

* Add `title` property to tasks to control the task will be displayed in the timeline.
* Allow to configure the merge method used by the merge queue.
* Fix compatibility with GitHub Enterprise installations.

Expand Down
13 changes: 13 additions & 0 deletions README.md
Expand Up @@ -503,6 +503,19 @@ tasks:
default: 0
```

You can also make these variables appear in the task title:

```yml
tasks:
failover:
action: "Failover a pod"
title: "Failover Pod %{POD_ID}"
steps:
- script/failover $POD_ID
variables:
- name: POD_ID
```

<h3 id="review-process">Review process</h3>

You can display review elements, such as monitoring data or a pre-deployment checklist, on the deployment page in Shipit:
Expand Down
4 changes: 4 additions & 0 deletions app/models/shipit/deploy.rb
Expand Up @@ -79,6 +79,10 @@ def trigger_revert
rollback
end

def title
I18n.t("#{self.class.name.demodulize.underscore.pluralize}.description", sha: until_commit.short_sha)
end

def rollback?
false
end
Expand Down
4 changes: 4 additions & 0 deletions app/models/shipit/task.rb
Expand Up @@ -212,6 +212,10 @@ def supports_rollback?
false
end

def title
definition.render_title(env)
end

def author
user || AnonymousUser.new
end
Expand Down
10 changes: 10 additions & 0 deletions app/models/shipit/task_definition.rb
Expand Up @@ -26,6 +26,15 @@ def initialize(id, config)
@variables = task_variables(config['variables'] || [])
@checklist = config['checklist'] || []
@allow_concurrency = config['allow_concurrency'] || false
@title = config['title']
end

def render_title(env)
if @title
@title % env.symbolize_keys
else
action
end
end

def allow_concurrency?
Expand All @@ -36,6 +45,7 @@ def as_json
{
id: id,
action: action,
title: @title,
description: description,
steps: steps,
variables: variables.map(&:to_h),
Expand Down
1 change: 1 addition & 0 deletions app/serializers/shipit/task_serializer.rb
Expand Up @@ -13,6 +13,7 @@ class TaskSerializer < ActiveModel::Serializer
type
status
action
title
description
started_at
ended_at
Expand Down
2 changes: 1 addition & 1 deletion app/views/shipit/tasks/_task.html.erb
Expand Up @@ -13,7 +13,7 @@
<div class="commit-details">
<span class="commit-title">
<a href="<%= stack_task_path(@stack, task) %>">
<%= task.definition.action %>
<%= task.title %>
</a>
</span>
<p class="commit-meta">
Expand Down
2 changes: 1 addition & 1 deletion app/views/shipit/tasks/_task_output.html.erb
Expand Up @@ -8,7 +8,7 @@
<div class="sidebar-plugins"></div>
</div>

<div class="deploy-main" data-task="<%= {repo: @stack.github_repo_name, description: task_description(task)}.to_json %>">
<div class="deploy-main" data-task="<%= {repo: @stack.github_repo_name, description: task.title}.to_json %>">
<span class="deploy-tasks"></span>
<div class="deploy-banner" data-status="<%= task.status %>">
<div class="deploy-banner-status"></div>
Expand Down
27 changes: 27 additions & 0 deletions test/fixtures/shipit/tasks.yml
Expand Up @@ -134,3 +134,30 @@ soc_deploy:
created_at: <%= (60 - 1).minutes.ago.to_s(:db) %>
started_at: <%= (60 - 1).minutes.ago.to_s(:db) %>
ended_at: <%= (60 - 3).minutes.ago.to_s(:db) %>

shipit_rendered_failover:
id: 10
user: walrus
since_commit_id: 2 # second
until_commit_id: 2 # second
type: Shipit::Task
stack: shipit
status: success
definition: >
{
"id": "failover",
"action": "Failover a pod",
"title": "Failover pod %{POD_ID}",
"description": "Restart app and job servers",
"variables": [
{"name": "POD_ID", "title": "Id of the pod to failover"}
],
"steps": [
"cap $ENVIRONMENT pod:failover"
]
}
env:
POD_ID: "12"
created_at: <%= (60 - 3).minutes.ago.to_s(:db) %>
started_at: <%= (60 - 3).minutes.ago.to_s(:db) %>
ended_at: <%= (60 - 4).minutes.ago.to_s(:db) %>
2 changes: 2 additions & 0 deletions test/models/task_definitions_test.rb
Expand Up @@ -6,6 +6,7 @@ class TaskDefinitionsTest < ActiveSupport::TestCase
@definition = TaskDefinition.new(
'restart',
'action' => 'Restart application',
'title' => 'Restart application %{FOO}',
'description' => 'Restart app and job servers',
'steps' => ['touch tmp/restart'],
'allow_concurrency' => true,
Expand Down Expand Up @@ -36,6 +37,7 @@ class TaskDefinitionsTest < ActiveSupport::TestCase
as_json = {
id: 'restart',
action: 'Restart application',
title: "Restart application %{FOO}",
description: 'Restart app and job servers',
steps: ['touch tmp/restart'],
checklist: [],
Expand Down
16 changes: 16 additions & 0 deletions test/models/tasks_test.rb
@@ -0,0 +1,16 @@
require 'test_helper'

module Shipit
class TasksTest < ActiveSupport::TestCase
test "#title interpolates env" do
task = shipit_tasks(:shipit_rendered_failover)
assert_equal({'POD_ID' => '12'}, task.env)
assert_equal 'Failover pod 12', task.title
end

test "#title returns the task action if title is not defined" do
task = shipit_tasks(:shipit_restart)
assert_equal 'Restart application', task.title
end
end
end

0 comments on commit ccfed09

Please sign in to comment.