From 1315cac7c303429bdfc56ef061d98b158bf67b4d Mon Sep 17 00:00:00 2001 From: Jeremy Attali Date: Sat, 25 Jan 2014 23:57:37 +0100 Subject: add error string when widget not rendered This prevents the cryptic ruby raw string being printed if no rendering template were found. Closes: #307 --- lib/dashing/app.rb | 1 + 1 file changed, 1 insertion(+) (limited to 'lib') diff --git a/lib/dashing/app.rb b/lib/dashing/app.rb index 033849c..933ef5b 100644 --- a/lib/dashing/app.rb +++ b/lib/dashing/app.rb @@ -117,6 +117,7 @@ get '/views/:widget?.html' do file = File.join(settings.root, "widgets", params[:widget], "#{params[:widget]}.#{suffix}") return engines.first.new(file).render if File.exist? file end + "Drats! Unable to find a widget file named: #{params[:widget]} to render." end def send_event(id, body, target=nil) -- cgit v1.2.3 From 27c6007b0101695241b38853aa60da6ec899fc9f Mon Sep 17 00:00:00 2001 From: David Bishop Date: Mon, 13 Mar 2017 16:06:38 -0600 Subject: Use old-style hash syntax to enable compatibility with ruby 1.8.7 --- lib/dashing/app.rb | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'lib') diff --git a/lib/dashing/app.rb b/lib/dashing/app.rb index 0ff3085..5ee085f 100644 --- a/lib/dashing/app.rb +++ b/lib/dashing/app.rb @@ -34,16 +34,18 @@ set :root, Dir.pwd set :sprockets, Sprockets::Environment.new(settings.root) set :assets_prefix, '/assets' set :digest_assets, false -set server: 'thin', connections: [], history_file: 'history.yml' +set :server, 'thin' +set :connections, [] +set :history_file, 'history.yml' set :public_folder, File.join(settings.root, 'public') set :views, File.join(settings.root, 'dashboards') set :default_dashboard, nil set :auth_token, nil if File.exists?(settings.history_file) - set history: YAML.load_file(settings.history_file) + set :history, YAML.load_file(settings.history_file) else - set history: {} + set :history, {} end %w(javascripts stylesheets fonts images).each do |path| @@ -55,7 +57,7 @@ end end not_found do - send_file File.join(settings.public_folder, '404.html'), status: 404 + send_file File.join(settings.public_folder, '404.html'), :status => 404 end at_exit do @@ -70,7 +72,7 @@ get '/' do redirect "/" + dashboard end -get '/events', provides: 'text/event-stream' do +get '/events', :provides => 'text/event-stream' do protected! response.headers['X-Accel-Buffering'] = 'no' # Disable buffering for nginx stream :keep_open do |out| -- cgit v1.2.3 From 515b1fd3bd1c4f3c782bf81a32435b336f335f80 Mon Sep 17 00:00:00 2001 From: jackhold Date: Sun, 2 Apr 2017 22:32:54 +0200 Subject: Change update time on events Changing from epoch in sec to epoch in milisec --- lib/dashing/app.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/dashing/app.rb b/lib/dashing/app.rb index 0ff3085..7f8a745 100644 --- a/lib/dashing/app.rb +++ b/lib/dashing/app.rb @@ -136,7 +136,7 @@ end def send_event(id, body, target=nil) body[:id] = id - body[:updatedAt] ||= Time.now.to_i + body[:updatedAt] ||= (Time.now.to_f * 1000.0).to_i event = format_event(body.to_json, target) Sinatra::Application.settings.history[id] = event unless target == 'dashboards' Sinatra::Application.settings.connections.each { |out| out << event } -- cgit v1.2.3 From 058ec527a3ce722031cdb301dba6950cab85e859 Mon Sep 17 00:00:00 2001 From: "Bruno P. Kinoshita" Date: Mon, 29 May 2017 18:52:03 +1200 Subject: Capture Interrupt error (Ctrl+c) and cleanly exit --- lib/dashing/cli.rb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/dashing/cli.rb b/lib/dashing/cli.rb index 4b93f89..57d48d0 100644 --- a/lib/dashing/cli.rb +++ b/lib/dashing/cli.rb @@ -86,7 +86,11 @@ module Dashing private def run_command(command) - system(command) + begin + system(command) + rescue Interrupt => e + say "Exiting..." + end end def install_widget_from_gist(gist, skip_overwrite) -- cgit v1.2.3 From 11d443664b7a785b42cbbd5b96347bafa5ad273a Mon Sep 17 00:00:00 2001 From: varac Date: Wed, 13 Jul 2016 20:07:09 +0200 Subject: initial commit, import from pixelated_dashboard --- lib/ccmenu.rb | 57 ++++++++++++++++++++++++ lib/github.rb | 123 ++++++++++++++++++++++++++++++++++++++++++++++++++++ lib/weekly_goals.rb | 22 ++++++++++ 3 files changed, 202 insertions(+) create mode 100644 lib/ccmenu.rb create mode 100644 lib/github.rb create mode 100644 lib/weekly_goals.rb (limited to 'lib') diff --git a/lib/ccmenu.rb b/lib/ccmenu.rb new file mode 100644 index 0000000..90257f5 --- /dev/null +++ b/lib/ccmenu.rb @@ -0,0 +1,57 @@ +require 'crack' +require 'open-uri' +require 'json' + +class CCMenu + + def initialize(url) + @data = Crack::XML.parse(open(url))['Projects']['Project'] + @data=@data.select{ |i| i['name'][/^[^\:\:]*\:\:[^\:\:]*$/]} + puts @data + end + + def json + @data.to_json + end + + def status + overall = 'Success' + @data.each do |step| + if step['lastBuildStatus'] != 'Success' + overall = step['lastBuildStatus'] + end + end + return overall + end + def failed + list = Array.new + @data.each do |step| + puts step + list << step['name'] if step['lastBuildStatus'] == 'Failure' + end + return list + end + + def num_total + @data.length + end + + def num_failed + self.failed.length + end + + def color + case status + when 'Failure' then 'red' + when 'Exception' then 'orange' + when 'Unknown' then 'orange' + else 'green' + end + end + + + def data + @data + end + +end diff --git a/lib/github.rb b/lib/github.rb new file mode 100644 index 0000000..77d765e --- /dev/null +++ b/lib/github.rb @@ -0,0 +1,123 @@ +require 'date' +require 'open-uri' +require 'json' + +class Github + + def initialize(orgname) + url='https://api.github.com/orgs/'+orgname + @headers={'User-Agent' => 'LEAP Dashboard'} + if ENV.has_key?('GITHUB_AUTH_TOKEN') + @headers['Authorization'] = "token "+ENV['GITHUB_AUTH_TOKEN'] + end + @org=JSON.parse(open(url,@headers).read) + @repos=JSON.parse(open(@org['repos_url'],@headers).read) + end + + def repocount + @repos.count + end + + def prcount + count=0 + @repos.each do |r| + count+=JSON.parse(open(r['url']+'/pulls',@headers).read).count + end + return count + end + + def recent_open_issues + count=0 + @repos.each do |r| + url=r['url']+'/issues?state=open&since='+(Time.new().to_datetime << 1).to_time.strftime("%Y-%m-%dT%H:%M:%SZ") + count+=JSON.parse(open(url,@headers).read).count + end + return count + end + def recent_issues + count=0 + @repos.each do |r| + url=r['url']+'/issues?state=all&since='+(Time.new().to_datetime << 1).to_time.strftime("%Y-%m-%dT%H:%M:%SZ") + count+=JSON.parse(open(url,@headers).read).count + end + return count + end + def open_pull_requests + count=0 + @repos.each do |r| + url=r['url']+'/pulls?state=open' + count+=JSON.parse(open(url,@headers).read).count + end + return count + end + def pull_requests + count=0 + @repos.each do |r| + url=r['url']+'/pulls?state=all' + count+=JSON.parse(open(url,@headers).read).count + end + return count + end + def forks + count=0 + @repos.each do |r| + url=r['url']+'/forks' + count+=JSON.parse(open(url,@headers).read).count + end + return count + end + def issues_in_development + count=0 + @repos.each do |r| + url=r['url']+'/issues?labels=2%20-%20Development' + count+=JSON.parse(open(url,@headers).read).count + end + return count + end + def prlist + prlist=[] + @repos.each do |r| + JSON.parse(open(r['url']+'/pulls',@headers).read).each do |pr| + prlist<<{'label'=>pr['title'], 'pr_url'=>pr['html_url']} + end + end + return prlist + end + + def stargazers + @repos.inject(0) {|sum,hash| sum + hash['stargazers_count']} + end + def epic_issues + count=0 + @repos.each do |r| + url=r['url']+'/issues?labels=UA%20multiuser' + count+=JSON.parse(open(url,@headers).read).count + end + return count + end + def all_epic_issues + count=0 + @repos.each do |r| + url=r['url']+'/issues?labels=UA%20multiuser&state=all' + count+=JSON.parse(open(url,@headers).read).count + end + return count + end + + def action_items + issues=[] + @repos.each do |r| + url=r['url']+'/issues?labels=Action+item' + JSON.parse(open(url,@headers).read).each do |issue| + title=issue['title'] + if issue.has_key?('assignee') and not issue['assignee'].nil? + assignee=issue['assignee']['login'] + else + assignee='None' + end + issues<<{'label' => title, 'value' => assignee} + end + end + issues + end +end diff --git a/lib/weekly_goals.rb b/lib/weekly_goals.rb new file mode 100644 index 0000000..1a263bc --- /dev/null +++ b/lib/weekly_goals.rb @@ -0,0 +1,22 @@ +require 'time' + +class WeeklyGoals + def initialize + @goals = [ + "Remove docker: Finish the load test report comparing the new and the old archicteture", + "Modularize stylesheet: ", + "Fix bug: Error running functionals on vagrant", + "Fix bug: Fix Feedback Form", + "Fix bug: Minify JS"] + end + + def rotating_goal + min = Time.new.min + idx = min % @goals.length + @goals[idx] + end + + def all_goals + @goals + end +end -- cgit v1.2.3 From b207ea5f24cb52d5818d04d2b0c872cc8598628e Mon Sep 17 00:00:00 2001 From: Azul Date: Tue, 18 Jul 2017 12:57:44 +0200 Subject: refactor: GitlabStats to collect stats from gitlab Want to add stats about merge requests in the future while still fetching each project once. --- lib/gitlab_stats.rb | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 lib/gitlab_stats.rb (limited to 'lib') diff --git a/lib/gitlab_stats.rb b/lib/gitlab_stats.rb new file mode 100644 index 0000000..5b41263 --- /dev/null +++ b/lib/gitlab_stats.rb @@ -0,0 +1,42 @@ +require 'gitlab' +require 'date' + +Gitlab.configure do |config| + # API endpoint URL, default + config.endpoint = ENV['GITLAB_ENDPOINT'] + + # User's private token or OAuth2 access token + config.private_token = ENV['GITLAB_TOKEN'] +end + +module GitlabStats + # get a list of all projects + def self.projects + Gitlab.group(ENV['GITLAB_GROUP_ID']).projects.map do |proj| + { :id => proj['id'], :name => proj['name'], :path => proj['path_with_namespace'], + :default_branch => proj['default_branch']} + end + end + + def self.add_pipeline_stats_to(proj) + pipelines = Gitlab.pipelines(proj[:id], { per_page: 10 }) + #pp pipeline[0] + pipeline = pipelines.find{|p| p.ref == proj[:default_branch]} + if pipeline.nil? + if pipelines.any? + proj[:status] = 'No builds run for default branch lately' + else + proj[:status] = 'No builds configured' + end + return + end + proj[:status] = pipeline.status + proj[:pipeline_id] = pipeline.id + proj[:ref] = pipeline.ref + date = DateTime.parse(pipeline.updated_at).strftime("%F %T") + proj[:date] = date + rescue e + proj[:status] = "Error: #{e}" + end + +end -- cgit v1.2.3 From fc531b2895eb57d675c0037cc5d3381ff664f5d4 Mon Sep 17 00:00:00 2001 From: Azul Date: Tue, 18 Jul 2017 14:13:16 +0200 Subject: feat: only check builds where enabled and not archived also reduced time between checks to 2 minutes and looking at last 50 builds. --- lib/gitlab_stats.rb | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'lib') diff --git a/lib/gitlab_stats.rb b/lib/gitlab_stats.rb index 5b41263..20b040a 100644 --- a/lib/gitlab_stats.rb +++ b/lib/gitlab_stats.rb @@ -13,13 +13,17 @@ module GitlabStats # get a list of all projects def self.projects Gitlab.group(ENV['GITLAB_GROUP_ID']).projects.map do |proj| - { :id => proj['id'], :name => proj['name'], :path => proj['path_with_namespace'], + { :id => proj['id'], + :name => proj['name'], + :path => proj['path_with_namespace'], + :archived => proj['archived'], + :builds_enabled => proj['builds_enabled'], :default_branch => proj['default_branch']} end end def self.add_pipeline_stats_to(proj) - pipelines = Gitlab.pipelines(proj[:id], { per_page: 10 }) + pipelines = Gitlab.pipelines(proj[:id], { per_page: 50 }) #pp pipeline[0] pipeline = pipelines.find{|p| p.ref == proj[:default_branch]} if pipeline.nil? -- cgit v1.2.3