Commit 627330c5 authored by Candy Tsai's avatar Candy Tsai

create self service section with run test

parent 713a0b66
Pipeline #48951 passed with stage
in 10 minutes and 6 seconds
inherit_from: .rubocop_todo.yml
AllCops:
TargetRubyVersion: 2.3
......@@ -10,3 +12,8 @@ Style/FrozenStringLiteralComment:
Metrics/BlockLength:
Exclude:
- 'spec/**/*.rb'
- 'lib/debci/api.rb' # documentation
Metrics/ClassLength:
Exclude:
- 'lib/debci/api.rb' # documentation
......@@ -15,10 +15,6 @@ Style/Documentation:
Style/FrozenStringLiteralComment:
Enabled: false
Metrics/BlockLength:
Exclude:
- 'spec/**/*.rb'
# Offense count: 2
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, IndentOneStep, IndentationWidth.
......@@ -321,11 +317,16 @@ Metrics/AbcSize:
# Configuration parameters: CountComments, ExcludedMethods.
Metrics/BlockLength:
Max: 260
Exclude:
- 'spec/**/*.rb'
- 'lib/debci/api.rb'
# Offense count: 4
# Configuration parameters: CountComments.
Metrics/ClassLength:
Max: 299
Exclude:
- 'lib/debci/api.rb'
# Offense count: 2
Metrics/CyclomaticComplexity:
......
require 'debci/api'
require 'debci/self_service'
require 'sinatra/content_for'
LISTING = <<~HTMLBLOCK.freeze
<!DOCTYPE html>
......@@ -48,6 +50,9 @@ app = Rack::Builder.new do
map '/api' do
run Debci::API
end
map '/self_service' do
run Debci::SelfService
end
end
run app
......@@ -5,6 +5,7 @@ require 'rdoc'
require 'securerandom'
require 'sinatra'
require "sinatra/namespace"
require "sinatra/content_for"
require 'time'
require 'debci'
......@@ -13,6 +14,7 @@ require 'debci/key'
class SelfDocAPI < Sinatra::Base
helpers Sinatra::ContentFor
get '/doc' do
@doc = self.class.doc
erb :doc
......@@ -243,8 +245,11 @@ module Debci
data.to_json
end
before '/test/:suite/:arch*'do
authenticate!
before '/test/:suite/:arch*' do
@user = ENV['FAKE_CERTIFICATE_USER'] || env['SSL_CLIENT_S_DN_CN']
if not @user
authenticate!
end
@suite = params[:suite]
@arch = params[:arch]
if !Debci.config.arch_list.include?(arch)
......
require 'debci/api'
require 'debci/self_service'
run Debci::API
run Debci::SelfService
......@@ -123,6 +123,9 @@ module Debci
private
# yield_content should do nothing in the Debci::HTML context
def yield_content(template); end
def templates
@templates ||= {}
end
......
......@@ -38,6 +38,9 @@
<li><a href="/api/">API</a></li>
<li><a href="/data/">Data</a></li>
</ul>
<ul class="nav navbar-nav navbar-right">
<li><a href="/self_service">Self Service</a></li>
</ul>
</div><!--/.nav-collapse -->
</div>
</div>
......@@ -70,5 +73,6 @@
<script type="text/javascript" src="<%= @root %>/bootstrap/js/bootstrap.min.js"></script>
<script type="text/javascript" src="<%= @root %>/app.js"></script>
<%= @footer %>
<%= yield_content :javascript %>
</body>
</html>
<div class="col-xs-12">
<h2>Welcome <%= @user %></h2>
</div>
<div id="self-test" class="col-xs-12">
<h2>Run Tests</h2>
<div class="form-group">
<label for="suite">Suite</label>
<select class="form-control" id="suite" name="suite">
<% @suites.each do |suite| %>
<option><%= suite %></option>
<% end %>
</select>
</div>
<div class="form-group">
<label for="arch">Architecture</label>
<select class="form-control" id="arch" name="arch">
<% @archs.each do |arch| %>
<option><%= arch %></option>
<% end %>
</select>
</div>
<div class="form-group">
<label for="package">Package Name</label>
<input class="form-control" id="package" name="package">
</div>
<button type="button" id="submit" data-loading-text="Submitting..." class="btn btn-default" autocomplete="off">
Submit
</button>
</div>
<% content_for :javascript do %>
<script>
$('#submit').on('click', function () {
$btn = $(this).button('loading');
const suite = $('#suite').val();
const arch = $('#arch').val();
const name = $('#package').val();
$.post(`/api/v1/test/${suite}/${arch}/${name}`)
.done(() => {
$('#self-test').prepend(
`<div class="alert alert-success" role="alert">submit test ${suite}/${arch}/${name} success</div>`
);
})
.fail(() => {
$('#self-test').prepend(
`<div class="alert alert-danger" role="alert">submit test ${suite}/${arch}/${name} failed, please try again</div>`
);
})
.always(() => {
$('.alert').delay(4000).slideUp(200, function () {
$(this).alert('close');
});
$btn.button('reset');
})
})
</script>
<% end %>
\ No newline at end of file
require 'sinatra'
module Debci
class SelfService < Sinatra::Base
helpers Sinatra::ContentFor
set :views, File.dirname(__FILE__) + '/html'
get '/' do
@user = ENV['FAKE_CERTIFICATE_USER'] || env['SSL_CLIENT_S_DN_CN']
@suites = Debci.config.suite_list
@archs = Debci.config.arch_list
if @user
erb :self_service
else
# TODO: change to unauthenticated template
'UNAUTHENTICATED'
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