Commit 74520f23 authored by Kamil Trzcinski's avatar Kamil Trzcinski

Encode state as base64 string

parent baef6728
class CiBuild class CiBuild
@interval: null @interval: null
@state: null
constructor: (build_url, build_status) -> constructor: (build_url, build_status, build_state) ->
clearInterval(CiBuild.interval) clearInterval(CiBuild.interval)
@state = build_state
@initScrollButtonAffix() @initScrollButtonAffix()
if build_status == "running" || build_status == "pending" if build_status == "running" || build_status == "pending"
...@@ -26,14 +29,18 @@ class CiBuild ...@@ -26,14 +29,18 @@ class CiBuild
CiBuild.interval = setInterval => CiBuild.interval = setInterval =>
if window.location.href.split("#").first() is build_url if window.location.href.split("#").first() is build_url
$.ajax $.ajax
url: build_url url: build_url + "/trace.json?state=" + encodeURIComponent(@state)
dataType: "json" dataType: "json"
success: (build) => success: (log) =>
if build.status == "running" @state = log.state
$('#build-trace code').html build.trace_html 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"/>' $('#build-trace code').append '<i class="fa fa-refresh fa-spin"/>'
@checkAutoscroll() @checkAutoscroll()
else if build.status != build_status else if log.status isnt build_status
Turbolinks.visit build_url Turbolinks.visit build_url
, 4000 , 4000
......
...@@ -41,7 +41,7 @@ class Projects::BuildsController < Projects::ApplicationController ...@@ -41,7 +41,7 @@ class Projects::BuildsController < Projects::ApplicationController
def trace def trace
respond_to do |format| respond_to do |format|
format.json do 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 end
end end
...@@ -80,13 +80,6 @@ class Projects::BuildsController < Projects::ApplicationController ...@@ -80,13 +80,6 @@ class Projects::BuildsController < Projects::ApplicationController
private private
def params_state
begin
JSON.parse(params[:state], symbolize_names: true)
rescue
end
end
def build def build
@build ||= project.builds.unscoped.find_by!(id: params[:id]) @build ||= project.builds.unscoped.find_by!(id: params[:id])
end end
......
- page_title "#{@build.name} (##{@build.id})", "Builds" - page_title "#{@build.name} (##{@build.id})", "Builds"
= render "header_title" = render "header_title"
- trace = build.trace_for_state - trace_with_state = @build.trace_with_state
.build-page .build-page
.row-content-block.top-block .row-content-block.top-block
...@@ -86,7 +86,7 @@ ...@@ -86,7 +86,7 @@
%pre.trace#build-trace %pre.trace#build-trace
%code.bash %code.bash
= preserve do = preserve do
= raw trace[:html] = raw trace_with_state[:html]
- if @build.active? - if @build.active?
%i{:class => "fa fa-refresh fa-spin"} %i{:class => "fa fa-refresh fa-spin"}
...@@ -219,4 +219,4 @@ ...@@ -219,4 +219,4 @@
:javascript :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]}")
...@@ -90,7 +90,7 @@ module Ci ...@@ -90,7 +90,7 @@ module Ci
def convert(raw, new_state) def convert(raw, new_state)
reset_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 start = @offset
ansi = raw[@offset..-1] ansi = raw[@offset..-1]
...@@ -187,15 +187,20 @@ module Ci ...@@ -187,15 +187,20 @@ module Ci
end end
def state def state
STATE_PARAMS.inject({}) do |h, param| state = STATE_PARAMS.inject({}) do |h, param|
h[param] = send(param) h[param] = send(param)
h h
end end
Base64.urlsafe_encode64(state.to_json)
end 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| STATE_PARAMS.each do |param|
send("#{param}=".to_sym, new_state[param]) send("#{param}=".to_sym, state[param])
end end
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment