hackathon_drone 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +29 -0
- data/Rakefile +1 -0
- data/bin/hackathon_drone +8 -0
- data/hackathon_drone.gemspec +22 -0
- data/lib/hackathon_drone/cli.rb +114 -0
- data/lib/hackathon_drone/configuration.rb +39 -0
- data/lib/hackathon_drone/rest.rb +38 -0
- data/lib/hackathon_drone/version.rb +3 -0
- data/lib/hackathon_drone.rb +1 -0
- metadata +91 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 François-Pierre Bouchard
|
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.
|
data/README.md
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# HackathonDrone
|
2
|
+
|
3
|
+
TODO: Write a gem description
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'hackathon_drone'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install hackathon_drone
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
TODO: Write usage instructions here
|
22
|
+
|
23
|
+
## Contributing
|
24
|
+
|
25
|
+
1. Fork it
|
26
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
27
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
28
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
29
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/bin/hackathon_drone
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'hackathon_drone/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |gem|
|
7
|
+
gem.name = "hackathon_drone"
|
8
|
+
gem.version = HackathonDrone::VERSION
|
9
|
+
gem.authors = ["François-Pierre Bouchard"]
|
10
|
+
gem.email = ["fpbouchard@gmail.com"]
|
11
|
+
gem.description = %q{Script that runs in the background, analyzing your branch and uploading stats to a hackathon-dashboard backend.}
|
12
|
+
gem.summary = %q{Follow your hackathon!}
|
13
|
+
gem.homepage = ""
|
14
|
+
|
15
|
+
gem.add_dependency "git-branch_stats"
|
16
|
+
gem.add_dependency "thor"
|
17
|
+
|
18
|
+
gem.files = `git ls-files`.split($/)
|
19
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
20
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
21
|
+
gem.require_paths = ["lib"]
|
22
|
+
end
|
@@ -0,0 +1,114 @@
|
|
1
|
+
require 'thor'
|
2
|
+
require 'curses'
|
3
|
+
require 'git-branch_stats'
|
4
|
+
require 'yaml'
|
5
|
+
|
6
|
+
require 'hackathon_drone/configuration'
|
7
|
+
require 'hackathon_drone/rest'
|
8
|
+
|
9
|
+
VENUES_PATH = "/venues.json"
|
10
|
+
TEAMS_PATH = "/venues/:venue_id/teams.json"
|
11
|
+
VENUE_PATH = "/venues/:id.json"
|
12
|
+
TEAM_PATH = "/venues/:venue_id/teams/:id.json"
|
13
|
+
|
14
|
+
module HackathonDrone
|
15
|
+
|
16
|
+
class CLI < Thor
|
17
|
+
|
18
|
+
def initialize(*)
|
19
|
+
super
|
20
|
+
|
21
|
+
project = `git rev-parse --show-toplevel`.strip.split('/').last
|
22
|
+
@config = HackathonDrone::Configuration.new(project)
|
23
|
+
end
|
24
|
+
|
25
|
+
desc "subscribe TEAM_NAME [HOST] [PORT]", "Subscribe the team named TEAM_NAME for the currently active venue and current working tree."
|
26
|
+
def subscribe(team_name, host = "hackathon-dashboard.herokuapp.com", port = 80)
|
27
|
+
if @config.get('team')
|
28
|
+
puts "Already subscribed as #{@config.get('team')['name']}"
|
29
|
+
exit
|
30
|
+
end
|
31
|
+
|
32
|
+
# 1. Get the venues
|
33
|
+
venues = HackathonDrone::REST.get(host, port, VENUES_PATH)
|
34
|
+
# 2. Find the first open venue
|
35
|
+
open_venue = venues.find {|venue| venue['state'] == 'open'}
|
36
|
+
# 3. Bail out if no open venue is found
|
37
|
+
unless open_venue
|
38
|
+
puts "No open venue yet, wait until the organizer opens the venue!"
|
39
|
+
exit
|
40
|
+
end
|
41
|
+
|
42
|
+
team = HackathonDrone::REST.post(host, port, TEAMS_PATH.gsub(/:venue_id/, open_venue['id'].to_s), {:name => team_name})
|
43
|
+
|
44
|
+
if team
|
45
|
+
@config.set('team', team)
|
46
|
+
@config.set('host', host)
|
47
|
+
@config.set('port', port)
|
48
|
+
|
49
|
+
puts "Your team has been subscribed!"
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
desc "monitor", "Start monitoring the current repository"
|
54
|
+
def monitor
|
55
|
+
unless team = @config.get('team')
|
56
|
+
puts "You first need to subscribe!"
|
57
|
+
exit
|
58
|
+
end
|
59
|
+
|
60
|
+
|
61
|
+
Curses.noecho
|
62
|
+
Curses.curs_set(0)
|
63
|
+
Curses.init_screen
|
64
|
+
begin
|
65
|
+
Curses.setpos(0,0)
|
66
|
+
Curses.addstr "Monitoring #{@config.project}"
|
67
|
+
Curses.refresh
|
68
|
+
while true
|
69
|
+
# Validate that the venue is in progress
|
70
|
+
venue = HackathonDrone::REST.get(@config.get('host'), @config.get('port'), VENUE_PATH.gsub(/:id/, team['venue_id'].to_s))
|
71
|
+
if venue and venue['state'] == 'started'
|
72
|
+
team_stats = Git::BranchStats.analyze
|
73
|
+
team = @config.set('team', HackathonDrone::REST.put(@config.get('host'), @config.get('port'), TEAM_PATH.gsub(/:id/, team['id'].to_s).gsub(/:venue_id/, team['venue_id'].to_s), team_stats))
|
74
|
+
Curses.setpos(2,0)
|
75
|
+
Curses.addstr(YAML.dump(team))
|
76
|
+
else
|
77
|
+
if venue
|
78
|
+
if venue['state'] == "open"
|
79
|
+
Curses.setpos(2,0)
|
80
|
+
Curses.addstr('Venue is still open, waiting for venue to start...')
|
81
|
+
else
|
82
|
+
puts "This venue is '#{venue['state']}'! It is not in progress."
|
83
|
+
exit
|
84
|
+
end
|
85
|
+
else
|
86
|
+
puts "Venue #{team['venue_id']} was not found"
|
87
|
+
exit
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
Curses.refresh
|
92
|
+
|
93
|
+
# Re-analyze in x seconds
|
94
|
+
sleep 5
|
95
|
+
end
|
96
|
+
ensure
|
97
|
+
Curses.close_screen
|
98
|
+
end
|
99
|
+
|
100
|
+
end
|
101
|
+
|
102
|
+
desc "reset", "Reset your settings for this repository"
|
103
|
+
def reset
|
104
|
+
@config.reset
|
105
|
+
end
|
106
|
+
|
107
|
+
desc "analyze", "Just show the stats of your repository without sending anything"
|
108
|
+
def analyze
|
109
|
+
puts Git::BranchStats.analyze
|
110
|
+
end
|
111
|
+
|
112
|
+
end
|
113
|
+
|
114
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
require 'yaml'
|
2
|
+
|
3
|
+
module HackathonDrone
|
4
|
+
|
5
|
+
class Configuration
|
6
|
+
|
7
|
+
CONFIG_FILE = File.expand_path('~/.hackathon_drone')
|
8
|
+
|
9
|
+
attr_reader :project
|
10
|
+
|
11
|
+
# ----- Configuration file management -----
|
12
|
+
def initialize(project)
|
13
|
+
@project = project
|
14
|
+
@config = File.exists?(CONFIG_FILE) ? YAML.load_file(CONFIG_FILE) : {}
|
15
|
+
@config[@project] ||= {}
|
16
|
+
end
|
17
|
+
|
18
|
+
def reset
|
19
|
+
@config.delete(@project)
|
20
|
+
save
|
21
|
+
end
|
22
|
+
|
23
|
+
def save
|
24
|
+
File.open(CONFIG_FILE, 'w+') {|f| f.write(@config.to_yaml) }
|
25
|
+
end
|
26
|
+
|
27
|
+
def get(key)
|
28
|
+
@config[@project][key]
|
29
|
+
end
|
30
|
+
|
31
|
+
def set(key, value)
|
32
|
+
@config[@project][key] = value
|
33
|
+
save
|
34
|
+
value
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
require 'net/http'
|
2
|
+
require 'json'
|
3
|
+
|
4
|
+
module HackathonDrone
|
5
|
+
|
6
|
+
module REST
|
7
|
+
|
8
|
+
def self.do_request(host, port, request)
|
9
|
+
response = Net::HTTP.new(host, port).start {|http| http.request(request)}
|
10
|
+
if response.is_a?(Net::HTTPSuccess)
|
11
|
+
response.body ? JSON.parse(response.body) : nil
|
12
|
+
else
|
13
|
+
puts "Error: #{response.code} #{response.message}: #{response.body}"
|
14
|
+
exit
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.post(host, port, path, payload = nil)
|
19
|
+
request = Net::HTTP::Post.new(path, {"Content-Type" => "application/json"})
|
20
|
+
request.body = payload.to_json if payload
|
21
|
+
self.do_request(host, port, request)
|
22
|
+
end
|
23
|
+
|
24
|
+
def self.get(host, port, path)
|
25
|
+
request = Net::HTTP::Get.new(path, {"Content-Type" => "application/json"})
|
26
|
+
self.do_request(host, port, request)
|
27
|
+
end
|
28
|
+
|
29
|
+
def self.put(host, port, path, payload = nil)
|
30
|
+
request = Net::HTTP::Put.new(path, {"Content-Type" => "application/json"})
|
31
|
+
request.body = payload.to_json if payload
|
32
|
+
self.do_request(host, port, request)
|
33
|
+
end
|
34
|
+
|
35
|
+
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
require "hackathon_drone/version"
|
metadata
ADDED
@@ -0,0 +1,91 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: hackathon_drone
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- François-Pierre Bouchard
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-05-16 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: git-branch_stats
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: thor
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :runtime
|
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: Script that runs in the background, analyzing your branch and uploading
|
47
|
+
stats to a hackathon-dashboard backend.
|
48
|
+
email:
|
49
|
+
- fpbouchard@gmail.com
|
50
|
+
executables:
|
51
|
+
- hackathon_drone
|
52
|
+
extensions: []
|
53
|
+
extra_rdoc_files: []
|
54
|
+
files:
|
55
|
+
- .gitignore
|
56
|
+
- Gemfile
|
57
|
+
- LICENSE.txt
|
58
|
+
- README.md
|
59
|
+
- Rakefile
|
60
|
+
- bin/hackathon_drone
|
61
|
+
- hackathon_drone.gemspec
|
62
|
+
- lib/hackathon_drone.rb
|
63
|
+
- lib/hackathon_drone/cli.rb
|
64
|
+
- lib/hackathon_drone/configuration.rb
|
65
|
+
- lib/hackathon_drone/rest.rb
|
66
|
+
- lib/hackathon_drone/version.rb
|
67
|
+
homepage: ''
|
68
|
+
licenses: []
|
69
|
+
post_install_message:
|
70
|
+
rdoc_options: []
|
71
|
+
require_paths:
|
72
|
+
- lib
|
73
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
74
|
+
none: false
|
75
|
+
requirements:
|
76
|
+
- - ! '>='
|
77
|
+
- !ruby/object:Gem::Version
|
78
|
+
version: '0'
|
79
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
80
|
+
none: false
|
81
|
+
requirements:
|
82
|
+
- - ! '>='
|
83
|
+
- !ruby/object:Gem::Version
|
84
|
+
version: '0'
|
85
|
+
requirements: []
|
86
|
+
rubyforge_project:
|
87
|
+
rubygems_version: 1.8.23
|
88
|
+
signing_key:
|
89
|
+
specification_version: 3
|
90
|
+
summary: Follow your hackathon!
|
91
|
+
test_files: []
|