dashing-semaphore 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
@@ -0,0 +1,3 @@
1
+ ## 1.0.0
2
+
3
+ First stable version
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in dashing-semaphore.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Pierre-Louis Gottfrois
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,73 @@
1
+ # Dashing::Semaphore
2
+
3
+ [Dashing-Rails](https://github.com/gottfrois/dashing-rails) widget that display build status of project on Semaphore CI.
4
+
5
+ <img src="https://dl.dropbox.com/u/5802579/semaphore-dashing.png" width="600">
6
+
7
+ ## Installation
8
+
9
+ Add this line to your [Dashing-Rails](https://github.com/gottfrois/dashing-rails) application's Gemfile:
10
+
11
+ gem 'dashing-semaphore'
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ ## Getting Started
18
+
19
+ Follow the following steps in order to make it work on your dashing-rails project:
20
+
21
+ 1. Add the following line to your `app/assets/javascripts/dashing/widgets/index.js` file:
22
+
23
+ //= require semaphore
24
+
25
+ 2. Add the following line to your `app/assets/stylesheets/dashing/widgets/index.css` file:
26
+
27
+ *= require semaphore
28
+
29
+ 3. Add the following html to your dashboard:
30
+
31
+ <li data-row="1" data-col="1" data-sizex="1" data-sizey="1">
32
+ <div data-id="project_id" data-view="Semaphore" data-unordered="true" data-title="ProjectTitle"></div>
33
+ </li>
34
+
35
+ 4. Run
36
+
37
+ rails g dashing:semaphore:install
38
+
39
+ 5. Edit `config/initializers/dashing-semaphore.rb.rb` with your semaphore crendentials and project name as follow:
40
+
41
+ Dashing::Semaphore.configure do |config|
42
+ config.auth_token = 'your_auth_token_from_semaphore'
43
+ config.projects = [
44
+ { widget_id: 'project_name/branch_name' },
45
+ { 'dashing-rails' => 'dashing-rails/master' } # For example
46
+ ]
47
+ end
48
+
49
+ *Note: the branch name is optional*
50
+
51
+ *Note: the paths to index files may have changed depending on your Dashing-Rails configuration.*
52
+
53
+ ## Fields
54
+
55
+ ### Required
56
+
57
+ * `data-id`: Like all widgets, you must include an identifier so that your jobs can update the value. It is the same that the key value of the hash in `config/initializers/dashing-semaphore.rb.rb`.
58
+
59
+ ## Contributing
60
+
61
+ 1. Fork it
62
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
63
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
64
+ 4. Push to the branch (`git push origin my-new-feature`)
65
+ 5. Create new Pull Request
66
+
67
+ ## Author
68
+
69
+ Full credits for this widget should go to [Aleksandar Diklic](https://github.com/rastasheep).
70
+
71
+ ## License
72
+
73
+ dashing-semaphore is released under the MIT License. Developed by [rastasheep](https://github.com/rastasheep). Adapted by [gottfrois](https://github.com/gottfrois).
@@ -0,0 +1 @@
1
+ require 'bundler/gem_tasks'
@@ -0,0 +1,114 @@
1
+ require 'delegate'
2
+ require 'net/http'
3
+ require 'uri'
4
+
5
+ module Dashing
6
+ module Semaphore
7
+ class Scheduler < ::SimpleDelegator
8
+
9
+ include ActionView::Helpers::DateHelper
10
+
11
+ attr_reader :config, :frequence
12
+
13
+ def initialize(frequence)
14
+ @config = Dashing::Semaphore.config
15
+ @frequence = frequence
16
+ super(config)
17
+ end
18
+
19
+ def call
20
+ schedule if valid?
21
+ end
22
+
23
+ private
24
+
25
+ def schedule
26
+ Dashing.scheduler.every frequence, first_in: 1.second.since do
27
+ projects.each do |project|
28
+ key = project.keys.first.to_s
29
+ item = update_builds(project.values.first.to_s)
30
+ Dashing.send_event(key, items: [item])
31
+ end
32
+ end
33
+ end
34
+
35
+ def valid?
36
+ true
37
+ end
38
+
39
+ def update_builds(project)
40
+ query = project.split('/')
41
+ project = search_project(json_response, query.first)
42
+
43
+ raise "no project with name #{query.first}" unless project
44
+
45
+ branch = search_branch(project, query)
46
+
47
+ raise "no branch with name #{query[1]} for project #{query[0]}" unless branch
48
+
49
+ build_info(branch)
50
+ end
51
+
52
+ def build_info(branch)
53
+ info = OpenStruct.new
54
+ info.label = branch['branch_name']
55
+ info.value = "Build #{branch['build_number']}, #{branch['result']}"
56
+ info.time = calculate_time(branch['finished_at'])
57
+ info.state = branch['result']
58
+
59
+ info
60
+ end
61
+
62
+ def calculate_time(time)
63
+ time ? time_ago_in_words(Time.parse(time)) : 'Not built yet'
64
+ end
65
+
66
+ def search_branch(project, query)
67
+ query.size > 1 ? search_by_branch_name(project, query) : search_within_last_build(project)
68
+ end
69
+
70
+ def search_by_branch_name(project, branch)
71
+ project['branches'].find { |b| b['branch_name'] == branch[1] } if project['branches']
72
+ end
73
+
74
+ def search_within_last_build(project)
75
+ project['branches'].last if project['branches']
76
+ end
77
+
78
+ def search_project(json, project)
79
+ json.find { |p| p['name'] == project }
80
+ end
81
+
82
+ def http
83
+ @http ||= ::Net::HTTP.new(uri.host, uri.port)
84
+ @http.use_ssl = true
85
+ @http
86
+ end
87
+
88
+ def request
89
+ @request ||= ::Net::HTTP::Get.new(uri.request_uri)
90
+ end
91
+
92
+ def response
93
+ @response ||= http.request(request)
94
+ end
95
+
96
+ def json_response
97
+ JSON.parse(response.body)
98
+ end
99
+
100
+ def uri
101
+ @uri ||= ::URI.parse("https://semaphoreapp.com/api/v1/projects?auth_token=#{auth_token}")
102
+ end
103
+
104
+ def projects
105
+ config.projects
106
+ end
107
+
108
+ def auth_token
109
+ config.auth_token
110
+ end
111
+
112
+ end
113
+ end
114
+ end
@@ -0,0 +1,21 @@
1
+ <h1 class="title" data-bind="title"></h1>
2
+
3
+ <img src="/assets/semaphore-logo.png" data-addclass-ok="item.table.state">
4
+
5
+ <ol>
6
+ <li data-foreach-item="items">
7
+ <span class="label" data-bind="item.table.label"></span>
8
+ <span class="value" data-bind="item.table.value"></span>
9
+ </li>
10
+ </ol>
11
+
12
+ <ul class="list-nostyle">
13
+ <li data-foreach-item="items">
14
+ <span class="label" data-bind="item.table.label"></span>
15
+ <span class="value" data-bind="item.table.value"></span>
16
+ <span class="label" data-bind="item.table.time"></span>
17
+ </li>
18
+ </ul>
19
+
20
+ <p class="more-info" data-bind="moreinfo"></p>
21
+ <p class="updated-at" data-bind="updatedAtMessage"></p>
@@ -0,0 +1,23 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'dashing/semaphore/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "dashing-semaphore"
8
+ spec.version = Dashing::Semaphore::VERSION
9
+ spec.authors = ["Pierre-Louis Gottfrois"]
10
+ spec.email = ["pierrelouis.gottfrois@gmail.com"]
11
+ spec.description = %q{Dashing widget that display build status of project on Semaphore CI}
12
+ spec.summary = %q{Dashing widget that display build status of project on Semaphore CI}
13
+ spec.homepage = "https://github.com/gottfrois/dashing-semaphore"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency 'bundler', '~> 1.3'
22
+ spec.add_development_dependency 'rake'
23
+ end
@@ -0,0 +1,21 @@
1
+ require 'dashing/semaphore/version'
2
+
3
+ module Dashing
4
+ module Semaphore
5
+ class << self
6
+
7
+ attr_accessor :configuration
8
+
9
+ def config
10
+ self.configuration ||= Configuration.new
11
+ end
12
+
13
+ def configure
14
+ yield config if block_given?
15
+ end
16
+ end
17
+ end
18
+ end
19
+
20
+ require 'dashing/semaphore/configuration'
21
+ require 'dashing/semaphore/engine'
@@ -0,0 +1,14 @@
1
+ module Dashing
2
+ module Semaphore
3
+ class Configuration
4
+
5
+ attr_accessor :auth_token, :projects
6
+
7
+ def initialize
8
+ @auth_token = ''
9
+ @projects = []
10
+ end
11
+
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,16 @@
1
+ module Dashing
2
+ module Semaphore
3
+ class Engine < ::Rails::Engine
4
+
5
+ config.assets.paths.unshift Dashing::Semaphore::Engine.root.join('vendor', 'assets', 'javascripts', 'dashing')
6
+ config.assets.paths.unshift Dashing::Semaphore::Engine.root.join('vendor', 'assets', 'stylesheets', 'dashing')
7
+ config.assets.paths.unshift Dashing::Semaphore::Engine.root.join('vendor', 'assets', 'images')
8
+ config.paths['app/views'].unshift Dashing::Semaphore::Engine.root.join('app', 'views', 'dashing', 'semaphore')
9
+
10
+ initializer 'require dashing semaphore jobs' do
11
+ Dir[Dashing::Semaphore::Engine.root.join('app', 'jobs', '**', '*.rb')].each { |file| require file }
12
+ end
13
+
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,5 @@
1
+ module Dashing
2
+ module Semaphore
3
+ VERSION = '1.0.0'
4
+ end
5
+ end
@@ -0,0 +1,21 @@
1
+ module Dashing
2
+ module Semaphore
3
+ module Generators
4
+ class InstallGenerator < ::Rails::Generators::Base
5
+
6
+ source_root File.expand_path('../../../templates', __FILE__)
7
+
8
+ desc 'Creates semaphore.rb initializer for your application.'
9
+
10
+ def copy_initializer
11
+ template 'initializer.rb', 'config/initializers/dashing-semaphore.rb'
12
+ end
13
+
14
+ def copy_job
15
+ template 'jobs/semaphore.rb', 'app/jobs/semaphore.rb'
16
+ end
17
+
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,11 @@
1
+ # Use this hook to configure Dashing-Semaphore bahaviors.
2
+ Dashing::Semaphore.configure do |config|
3
+ # You semaphore auth token.
4
+ # config.auth_token = 'your_auth_token_from_semaphore'
5
+
6
+ # A list of hash where the key is the widget_id and the value is your
7
+ # semaphore project name and an optional branch name.
8
+ # config.projects = [
9
+ # { widget_id: 'project_name/branch_name'}
10
+ # ]
11
+ end
@@ -0,0 +1,2 @@
1
+ # You can set the frequency here.
2
+ Dashing::Semaphore::Scheduler.new('10s').call
@@ -0,0 +1,13 @@
1
+ // This is a manifest file that'll be compiled into application.js, which will include all the files
2
+ // listed below.
3
+ //
4
+ // Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
5
+ // or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path.
6
+ //
7
+ // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
8
+ // the compiled file.
9
+ //
10
+ // WARNING: THE FIRST BLANK LINE MARKS THE END OF WHAT'S TO BE PROCESSED, ANY BLANK LINE SHOULD
11
+ // GO AFTER THE REQUIRES BELOW.
12
+ //
13
+ //= require_tree .
@@ -0,0 +1,15 @@
1
+ class Dashing.Semaphore extends Dashing.Widget
2
+ ready: ->
3
+ @get('unordered')
4
+ if @get('unordered')
5
+ $(@node).find('ol').remove()
6
+ else
7
+ $(@node).find('ul').remove()
8
+ @_checkStatus(@items[0].table.state)
9
+
10
+ onData: (data) ->
11
+ @_checkStatus(data.items[0].table.state)
12
+
13
+ _checkStatus: (status) ->
14
+ $(@node).removeClass('failed pending passed')
15
+ $(@node).addClass(status)
@@ -0,0 +1,12 @@
1
+ /*
2
+ * This is a manifest file that'll be compiled into application.css, which will include all the files
3
+ * listed below.
4
+ *
5
+ * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
6
+ * or vendor/assets/stylesheets of plugins, if any, can be referenced here using a relative path.
7
+ *
8
+ * You're free to add application-wide styles to this file and they'll appear at the top of the
9
+ * compiled file, but it's generally better to create a new file per style scope.
10
+ *
11
+ *= require_tree .
12
+ */
@@ -0,0 +1,83 @@
1
+ $value-color: #FFF;
2
+ $background-color: #8fb347;
3
+ $background-error-color: #ad3b0e;
4
+ $background-passed-color: #8fb347;
5
+ $background-pending-color: #47bbb3;
6
+
7
+ $title-color: rgba(255, 255, 255, 0.7);
8
+ $label-color: rgba(255, 255, 255, 0.7);
9
+ $moreinfo-color: rgba(255, 255, 255, 0.7);
10
+
11
+ .widget-semaphore{
12
+
13
+ background-color: $background-color;
14
+ vertical-align: top;
15
+
16
+ img {
17
+ width: 100% !important;
18
+ position: absolute;
19
+ left: 0;
20
+ top: 30px;
21
+ opacity: 0.05;
22
+ }
23
+
24
+ .title {
25
+ color: $title-color;
26
+ }
27
+
28
+ ol, ul {
29
+ margin: 0 15px;
30
+ text-align: left;
31
+ color: $label-color;
32
+ }
33
+
34
+ ol {
35
+ list-style-position: inside;
36
+ }
37
+
38
+ li {
39
+ margin-bottom: 5px;
40
+ }
41
+
42
+ .list-nostyle {
43
+ list-style: none;
44
+ }
45
+
46
+ .label {
47
+ text-align: center;
48
+ display: block;
49
+ color: $label-color;
50
+ font-size: 24px;
51
+ word-wrap: break-word;
52
+ }
53
+
54
+ .value {
55
+ text-align: center;
56
+ display: block;
57
+ font-weight: 600;
58
+ color: $value-color;
59
+ font-size: 24px;
60
+ word-wrap: break-word;
61
+ }
62
+
63
+ .updated-at {
64
+ color: rgba(0, 0, 0, 0.3);
65
+ }
66
+
67
+ .more-info {
68
+ color: $moreinfo-color;
69
+ }
70
+
71
+ &.failed {
72
+ background-color: $background-error-color;
73
+ }
74
+
75
+ &.pending {
76
+ background-color: $background-pending-color;
77
+ }
78
+
79
+ &.passed {
80
+ background-color: $background-passed-color;
81
+ }
82
+
83
+ }
metadata ADDED
@@ -0,0 +1,105 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: dashing-semaphore
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Pierre-Louis Gottfrois
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-11-01 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: bundler
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: '1.3'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: '1.3'
30
+ - !ruby/object:Gem::Dependency
31
+ name: rake
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ description: Dashing widget that display build status of project on Semaphore CI
47
+ email:
48
+ - pierrelouis.gottfrois@gmail.com
49
+ executables: []
50
+ extensions: []
51
+ extra_rdoc_files: []
52
+ files:
53
+ - .gitignore
54
+ - CHANGELOG.md
55
+ - Gemfile
56
+ - LICENSE.txt
57
+ - README.md
58
+ - Rakefile
59
+ - app/jobs/dashing/semaphore/scheduler.rb
60
+ - app/views/dashing/semaphore/semaphore.html
61
+ - dashing-semaphore.gemspec
62
+ - lib/dashing/semaphore.rb
63
+ - lib/dashing/semaphore/configuration.rb
64
+ - lib/dashing/semaphore/engine.rb
65
+ - lib/dashing/semaphore/version.rb
66
+ - lib/generators/dashing/semaphore/install_generator.rb
67
+ - lib/generators/templates/initializer.rb
68
+ - lib/generators/templates/jobs/semaphore.rb
69
+ - vendor/assets/images/semaphore-logo.png
70
+ - vendor/assets/javascripts/dashing/semaphore/index.js
71
+ - vendor/assets/javascripts/dashing/semaphore/semaphore.coffee
72
+ - vendor/assets/stylesheets/dashing/semaphore/index.css
73
+ - vendor/assets/stylesheets/dashing/semaphore/semaphore.scss
74
+ homepage: https://github.com/gottfrois/dashing-semaphore
75
+ licenses:
76
+ - MIT
77
+ post_install_message:
78
+ rdoc_options: []
79
+ require_paths:
80
+ - lib
81
+ required_ruby_version: !ruby/object:Gem::Requirement
82
+ none: false
83
+ requirements:
84
+ - - ! '>='
85
+ - !ruby/object:Gem::Version
86
+ version: '0'
87
+ segments:
88
+ - 0
89
+ hash: 247761134562443647
90
+ required_rubygems_version: !ruby/object:Gem::Requirement
91
+ none: false
92
+ requirements:
93
+ - - ! '>='
94
+ - !ruby/object:Gem::Version
95
+ version: '0'
96
+ segments:
97
+ - 0
98
+ hash: 247761134562443647
99
+ requirements: []
100
+ rubyforge_project:
101
+ rubygems_version: 1.8.25
102
+ signing_key:
103
+ specification_version: 3
104
+ summary: Dashing widget that display build status of project on Semaphore CI
105
+ test_files: []