Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKamil Trzcinski <ayufan@ayufan.eu>2016-05-09 20:19:27 +0300
committerKamil Trzcinski <ayufan@ayufan.eu>2016-05-09 20:19:27 +0300
commit74520f23db51c95b4aea8856fb51c4246785f776 (patch)
treeae6411f58e16b60cba1d5da3c150f07d01852852
parentbaef6728fa4e8e515ccdeba1ea54da996f322aab (diff)
Encode state as base64 string
-rw-r--r--app/assets/javascripts/ci/build.coffee21
-rw-r--r--app/controllers/projects/builds_controller.rb9
-rw-r--r--app/views/projects/builds/show.html.haml6
-rw-r--r--lib/ci/ansi2html.rb13
4 files changed, 27 insertions, 22 deletions
diff --git a/app/assets/javascripts/ci/build.coffee b/app/assets/javascripts/ci/build.coffee
index 7afe8bf79e2..fca0c3bae5c 100644
--- a/app/assets/javascripts/ci/build.coffee
+++ b/app/assets/javascripts/ci/build.coffee
@@ -1,9 +1,12 @@
class CiBuild
@interval: null
+ @state: null
- constructor: (build_url, build_status) ->
+ constructor: (build_url, build_status, build_state) ->
clearInterval(CiBuild.interval)
+ @state = build_state
+
@initScrollButtonAffix()
if build_status == "running" || build_status == "pending"
@@ -26,14 +29,18 @@ class CiBuild
CiBuild.interval = setInterval =>
if window.location.href.split("#").first() is build_url
$.ajax
- url: build_url
+ url: build_url + "/trace.json?state=" + encodeURIComponent(@state)
dataType: "json"
- success: (build) =>
- if build.status == "running"
- $('#build-trace code').html build.trace_html
- $('#build-trace code').append '<i class="fa fa-refresh fa-spin"/>'
+ success: (log) =>
+ @state = log.state
+ if log.status is "running"
+ if log.append
+ $('.fa-refresh').before log.html
+ else
+ $('#build-trace code').html log.html
+ $('#build-trace code').append '<i class="fa fa-refresh fa-spin"/>'
@checkAutoscroll()
- else if build.status != build_status
+ else if log.status isnt build_status
Turbolinks.visit build_url
, 4000
diff --git a/app/controllers/projects/builds_controller.rb b/app/controllers/projects/builds_controller.rb
index 3c9a52a5ddd..bb1f6c5e980 100644
--- a/app/controllers/projects/builds_controller.rb
+++ b/app/controllers/projects/builds_controller.rb
@@ -41,7 +41,7 @@ class Projects::BuildsController < Projects::ApplicationController
def trace
respond_to do |format|
format.json do
- render json: @build.trace_with_state(params_state).merge!(id: @build.id, status: @build.status)
+ render json: @build.trace_with_state(params[:state]).merge!(id: @build.id, status: @build.status)
end
end
end
@@ -80,13 +80,6 @@ class Projects::BuildsController < Projects::ApplicationController
private
- def params_state
- begin
- JSON.parse(params[:state], symbolize_names: true)
- rescue
- end
- end
-
def build
@build ||= project.builds.unscoped.find_by!(id: params[:id])
end
diff --git a/app/views/projects/builds/show.html.haml b/app/views/projects/builds/show.html.haml
index 0da0477bdd0..c7b9c36a3ab 100644
--- a/app/views/projects/builds/show.html.haml
+++ b/app/views/projects/builds/show.html.haml
@@ -1,6 +1,6 @@
- page_title "#{@build.name} (##{@build.id})", "Builds"
= render "header_title"
-- trace = build.trace_for_state
+- trace_with_state = @build.trace_with_state
.build-page
.row-content-block.top-block
@@ -86,7 +86,7 @@
%pre.trace#build-trace
%code.bash
= preserve do
- = raw trace[:html]
+ = raw trace_with_state[:html]
- if @build.active?
%i{:class => "fa fa-refresh fa-spin"}
@@ -219,4 +219,4 @@
:javascript
- new CiBuild("#{namespace_project_build_url(@project.namespace, @project, @build)}", "#{@build.status}", "#{trace[:state]}")
+ new CiBuild("#{namespace_project_build_url(@project.namespace, @project, @build)}", "#{@build.status}", "#{trace_with_state[:state]}")
diff --git a/lib/ci/ansi2html.rb b/lib/ci/ansi2html.rb
index d29e68570ff..5fed43aaebd 100644
--- a/lib/ci/ansi2html.rb
+++ b/lib/ci/ansi2html.rb
@@ -90,7 +90,7 @@ module Ci
def convert(raw, new_state)
reset_state
- restore_state(new_state) if new_state && new_state[:offset].to_i < raw.length
+ restore_state(raw, new_state) if new_state
start = @offset
ansi = raw[@offset..-1]
@@ -187,15 +187,20 @@ module Ci
end
def state
- STATE_PARAMS.inject({}) do |h, param|
+ state = STATE_PARAMS.inject({}) do |h, param|
h[param] = send(param)
h
end
+ Base64.urlsafe_encode64(state.to_json)
end
- def restore_state(new_state)
+ def restore_state(raw, new_state)
+ state = Base64.urlsafe_decode64(new_state)
+ state = JSON.parse(state, symbolize_names: true)
+ return if state[:offset].to_i > raw.length
+
STATE_PARAMS.each do |param|
- send("#{param}=".to_sym, new_state[param])
+ send("#{param}=".to_sym, state[param])
end
end