wo 0.0.1

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,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 0231e2df6888b01ab099ea0209ae957033e22fa3
4
+ data.tar.gz: 5c1d24eef720dee589091603cdf3df32d95959e7
5
+ SHA512:
6
+ metadata.gz: 98d58568e99218faf9c5a36aaf4c724ba992fc655889ff4c0aff9eaf59b5259acf0cc31ff37d62ecea25f7417402e3a8f7acb403f527c372acf2c45530bfd9b4
7
+ data.tar.gz: ae51e8edead3291519c8a0dd211f55d173ee00ef441102c231a8a032ff95961dd2c7051c8a60f32cfadac34802f902473922f8e6d8a4ad991856595aa0e1d8e7
@@ -0,0 +1,3 @@
1
+ /Gemfile.lock
2
+ /coverage
3
+ *swp
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --require spec_helper
@@ -0,0 +1,7 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.9.3
4
+ - 2.0.0
5
+ - 2.1.0
6
+ - 2.2.0
7
+ script: bundle exec rspec
data/.wo ADDED
@@ -0,0 +1,2 @@
1
+ url: http://wo-app.herokuapp.com
2
+ token: dfddda19-e44d-4f9f-8e51-8eeb9df9fa1e
data/Gemfile ADDED
@@ -0,0 +1,13 @@
1
+ source 'https://rubygems.org'
2
+
3
+ group :development do
4
+ gem 'pry'
5
+ end
6
+
7
+ group :test do
8
+ gem 'rspec', '~> 3.0'
9
+ gem 'simplecov', require: false
10
+ gem "codeclimate-test-reporter", require: nil
11
+ end
12
+
13
+ gemspec
@@ -0,0 +1,53 @@
1
+ # wo
2
+
3
+ CLI and Ruby client for [wo server](https://github.com/wo-app/wo-server)
4
+
5
+ Instration
6
+ ----------
7
+
8
+ Add this line to your application's Gemfile:
9
+
10
+ gem 'wo'
11
+
12
+ And then execute:
13
+
14
+ $ bundle
15
+
16
+ Or install it yourself as:
17
+
18
+ $ gem install wo
19
+
20
+ Also, copy following
21
+
22
+ #### case of zsh
23
+
24
+ ```
25
+ eval "$(wo hook zsh)"
26
+ ```
27
+
28
+ #### case of bash
29
+
30
+ TODO
31
+
32
+ Usage
33
+ -----
34
+
35
+ ```sh
36
+ # Create a .wo file in current repository
37
+ wo init
38
+
39
+ # Print doings in organization
40
+ wo doings
41
+ ```
42
+
43
+ Screen shot
44
+ -----------
45
+
46
+ ![1__tmux](https://cloud.githubusercontent.com/assets/189824/8511157/c318f19c-2345-11e5-9c10-6dfceeeffd62.png)
47
+
48
+ Test
49
+ ----
50
+
51
+ ```
52
+ bundle exec rspec
53
+ ```
data/bin/wo ADDED
@@ -0,0 +1,55 @@
1
+ #!/usr/bin/env ruby
2
+ require "wo"
3
+
4
+ module WO
5
+ class Command < Thor
6
+ desc "init", "Initialize configure file"
7
+ def init(url = nil)
8
+ url = url || WO::Client::API_URL
9
+ token = Client.new(url: url).create_organization.to_json["organization"]["token"]
10
+
11
+ File.open(loader.file_full_path, "w") do |f|
12
+ f.puts "url: #{url}"
13
+ f.puts "token: #{token}"
14
+ end
15
+
16
+ puts "Created #{loader.file_full_path}"
17
+ end
18
+
19
+ desc "hook", "Print hook sh"
20
+ def hook(sh)
21
+ puts Hook.new(sh).hook
22
+ end
23
+
24
+ desc "doing", "Update working on"
25
+ def doing(repo, branch, user_name)
26
+ Client.new(url: url).create_doing(
27
+ token: token,
28
+ user_name: user_name,
29
+ repo: repo,
30
+ branch: branch,
31
+ )
32
+ end
33
+
34
+ desc "doings", "Show working on in organization"
35
+ def doings
36
+ puts Client.new(url: url).doings(token: token).to_timeline
37
+ end
38
+
39
+ private
40
+
41
+ def url
42
+ loader.to_h[:url]
43
+ end
44
+
45
+ def token
46
+ loader.to_h[:token]
47
+ end
48
+
49
+ def loader
50
+ @loader ||= Loader.new(ENV["WO_FILE_PATH"])
51
+ end
52
+ end
53
+ end
54
+
55
+ WO::Command.start(ARGV)
@@ -0,0 +1,13 @@
1
+ require 'faraday'
2
+ require 'json'
3
+ require 'yaml'
4
+ require 'thor'
5
+
6
+ require 'wo/client'
7
+ require 'wo/configure'
8
+ require 'wo/response/format/timeline'
9
+ require 'wo/response'
10
+ require 'wo/loader'
11
+ require 'wo/hook'
12
+ require 'wo/hook/zsh'
13
+ require 'wo/version'
@@ -0,0 +1,28 @@
1
+ module WO
2
+ class Client
3
+ API_URL = "http://wo-app.herokuapp.com"
4
+
5
+ def initialize(options = {})
6
+ @api_url = options[:url] ? options[:url] : API_URL
7
+ end
8
+
9
+ def doings(options = {})
10
+ request(:get, "#{@api_url}/users", Configure.new(options).to_h)
11
+ end
12
+
13
+ def create_doing(options = {})
14
+ request(:post, "#{@api_url}/doings", Configure.new(options).to_h)
15
+ end
16
+
17
+ def create_organization
18
+ request(:post, "#{@api_url}/organizations")
19
+ end
20
+
21
+ private
22
+
23
+ def request(method, path, options = {})
24
+ faraday_response = Faraday.send(method, *[path, options])
25
+ Response.new(faraday_response)
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,19 @@
1
+ module WO
2
+ class Configure
3
+ def initialize(options = {})
4
+ [:token, :repo, :branch, :user_name].each do |key|
5
+ next unless value = options[key]
6
+ instance_variable_set(:"@#{key}", value)
7
+ end
8
+ end
9
+
10
+ def to_h
11
+ {
12
+ "organization[token]": @token,
13
+ "doing[repo]": @repo,
14
+ "doing[branch]": @branch,
15
+ "user[name]": @user_name,
16
+ }
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,19 @@
1
+ module WO
2
+ class Hook
3
+ attr_reader :sh
4
+
5
+ def initialize(sh)
6
+ @sh = sh
7
+ end
8
+
9
+ def hook
10
+ constantize.new.hook
11
+ end
12
+
13
+ private
14
+
15
+ def constantize
16
+ Kernel.const_get("WO").const_get("Hook").const_get(@sh.capitalize)
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,34 @@
1
+ module WO
2
+ class Hook
3
+ class Zsh
4
+ def hook
5
+ %(
6
+ _wo_hook() {
7
+ repo_path=`git rev-parse --show-toplevel 2>&1`
8
+
9
+ if [[ "$?" == 0 ]] ; then
10
+ token=`cat ${repo_path}/.wo 2>&1`
11
+
12
+ if [[ "$?" == 0 ]] ; then
13
+ repo=`basename ${repo_path}`
14
+ branch=`git rev-parse --abbrev-ref HEAD`
15
+ user_name=`git config user.name`
16
+
17
+ wo doing ${repo} ${branch} ${user_name}
18
+ fi
19
+ fi
20
+ }
21
+
22
+ _wo_hook_background() {
23
+ (_wo_hook &)
24
+ }
25
+
26
+ typeset -ag precmd_functions
27
+ if [[ -z $precmd_functions[(r)_wo_hook_background] ]]; then
28
+ precmd_functions+=_wo_hook_background;
29
+ fi
30
+ )
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,26 @@
1
+ module WO
2
+ class Loader
3
+ WO_FILE_NAME = ".wo"
4
+
5
+ attr_reader :file_path, :file_full_path
6
+
7
+ def initialize(wo_file_path = nil)
8
+ @file_path = wo_file_path || repo_path
9
+ @file_full_path = "#{@file_path}/#{WO_FILE_NAME}"
10
+ end
11
+
12
+ def config
13
+ @config ||= YAML.load_file(@file_full_path)
14
+ end
15
+
16
+ def to_h
17
+ { url: config["url"], token: config["token"] }
18
+ end
19
+
20
+ private
21
+
22
+ def repo_path
23
+ `git rev-parse --show-toplevel`.chomp
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,14 @@
1
+ module WO
2
+ class Response
3
+ include Format::Timeline
4
+ attr_reader :result
5
+
6
+ def initialize(result)
7
+ @result = result
8
+ end
9
+
10
+ def to_json
11
+ JSON.parse(@result.body)
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,58 @@
1
+ module WO
2
+ class Response
3
+ module Format
4
+ module Timeline
5
+ # TODO: refactor
6
+ # TODO: handle colorize
7
+
8
+ def to_timeline
9
+ to_json["users"].map do |user|
10
+ user_name = user["name"]
11
+ repo_branch = "#{user["recent_repo"]}/#{user["recent_branch"]}"
12
+ time = user["time_ago"]
13
+
14
+ sprintf(format, user_name, repo_branch, time)
15
+ end
16
+ end
17
+
18
+ private
19
+
20
+ def format
21
+ "#{bold}#{green}%#{max_length_user_name}s: #{white}%#{max_length_branch}s #{black}%#{max_length_time_ago}s#{clear}"
22
+ end
23
+
24
+ def max_length_user_name
25
+ @max_length_user_name ||= to_json["users"].map { |user| user["name"].length }.max
26
+ end
27
+
28
+ def max_length_branch
29
+ @max_length_branch ||= to_json["users"].map { |user| "#{user["recent_repo"]}/#{user["recent_branch"]}".length }.max
30
+ end
31
+
32
+ def max_length_time_ago
33
+ @max_length_time_ago ||= to_json["users"].map { |user| "#{user["time_ago"]}".length }.max
34
+ end
35
+
36
+ def bold
37
+ "\e[1m"
38
+ end
39
+
40
+ def green
41
+ "\e[32m"
42
+ end
43
+
44
+ def white
45
+ "\e[37m"
46
+ end
47
+
48
+ def black
49
+ "\e[30m"
50
+ end
51
+
52
+ def clear
53
+ "\e[0m"
54
+ end
55
+ end
56
+ end
57
+ end
58
+ end
@@ -0,0 +1,6 @@
1
+ module WO
2
+ MAJOR = 0
3
+ MINOR = 0
4
+ PATCH = 1
5
+ VERSION = [MAJOR, MINOR, PATCH].join('.').freeze
6
+ end
@@ -0,0 +1,11 @@
1
+ $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
2
+
3
+ require "codeclimate-test-reporter"
4
+ CodeClimate::TestReporter.start
5
+
6
+ require 'simplecov'
7
+ SimpleCov.start do
8
+ add_filter "spec"
9
+ end
10
+
11
+ require 'wo'
@@ -0,0 +1,20 @@
1
+ $:.push File.expand_path('../lib', __FILE__)
2
+ require 'wo/version'
3
+
4
+ Gem::Specification.new do |s|
5
+ s.name = 'wo'
6
+ s.version = WO::VERSION
7
+ s.authors = ['Masahiro Saito']
8
+ s.email = ['camelmasa@gmail.com']
9
+ s.summary = 'Ruby client for wo server'
10
+ s.description = 'Ruby client for wo server'
11
+ s.homepage = 'https://github.com/wo-app/wo'
12
+ s.license = 'MIT'
13
+
14
+ s.files = `git ls-files`.split($/)
15
+ s.executables = %w(wo)
16
+ s.require_paths = ['lib']
17
+
18
+ s.add_runtime_dependency 'faraday', '~> 0.9.0'
19
+ s.add_runtime_dependency 'thor', '~> 0.19.1'
20
+ end
metadata ADDED
@@ -0,0 +1,91 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: wo
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Masahiro Saito
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-07-05 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: faraday
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 0.9.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 0.9.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: thor
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 0.19.1
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 0.19.1
41
+ description: Ruby client for wo server
42
+ email:
43
+ - camelmasa@gmail.com
44
+ executables:
45
+ - wo
46
+ extensions: []
47
+ extra_rdoc_files: []
48
+ files:
49
+ - ".gitignore"
50
+ - ".rspec"
51
+ - ".travis.yml"
52
+ - ".wo"
53
+ - Gemfile
54
+ - README.md
55
+ - bin/wo
56
+ - lib/wo.rb
57
+ - lib/wo/client.rb
58
+ - lib/wo/configure.rb
59
+ - lib/wo/hook.rb
60
+ - lib/wo/hook/zsh.rb
61
+ - lib/wo/loader.rb
62
+ - lib/wo/response.rb
63
+ - lib/wo/response/format/timeline.rb
64
+ - lib/wo/version.rb
65
+ - spec/spec_helper.rb
66
+ - wo.gemspec
67
+ homepage: https://github.com/wo-app/wo
68
+ licenses:
69
+ - MIT
70
+ metadata: {}
71
+ post_install_message:
72
+ rdoc_options: []
73
+ require_paths:
74
+ - lib
75
+ required_ruby_version: !ruby/object:Gem::Requirement
76
+ requirements:
77
+ - - ">="
78
+ - !ruby/object:Gem::Version
79
+ version: '0'
80
+ required_rubygems_version: !ruby/object:Gem::Requirement
81
+ requirements:
82
+ - - ">="
83
+ - !ruby/object:Gem::Version
84
+ version: '0'
85
+ requirements: []
86
+ rubyforge_project:
87
+ rubygems_version: 2.4.5
88
+ signing_key:
89
+ specification_version: 4
90
+ summary: Ruby client for wo server
91
+ test_files: []