ghn 0.0.1 → 0.0.2

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7b93cf1ccda9576a2bfc0e29b6a8a8049f5c40f0
4
- data.tar.gz: c410e0b9c368e80f6f455393d2e2a81b87ca2d25
3
+ metadata.gz: bc3b7051906643d8a41a23a0d870b1a3aa398711
4
+ data.tar.gz: 28946552fecd43795a28bcb8f1b8a96d8246cf0c
5
5
  SHA512:
6
- metadata.gz: 113f7e9856ec04f81446a581233aa2f6c421a65b35725a33d1d067266e9f1566238f49c6aa07e013c7dc86ba361226429ab016d1da1ad50b9c75d7503e6868be
7
- data.tar.gz: 1b5e77e6973b1a7d17ce11b8ac2b8b990053b10a829a1f3ef9ee49416b7f433042537974bce4add5ea879bc64e7337964069114a96bf9b0f4251f215a7c6038f
6
+ metadata.gz: 4cfba176f4db94be5cda8b7ee7c309f0271b8c686598b4299493d4f8c90dacf10d5ffda16f185f94e1fac5096b1be9c6f4b6a2303b7bdb8b08570da6a11e0e2b
7
+ data.tar.gz: a2f5c8ef56b473919dcd932f1e50ca47eb23729a9d09796a84f0c8396da451e11b791369f8fd41f8a5030a7b4d2f2a6ef4a27487bcc1d438a30431714a1ca419
data/.coveralls.yml ADDED
@@ -0,0 +1 @@
1
+ service_name: travis-ci
data/.travis.yml ADDED
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.9.3
4
+ - 2.0.0
data/CHANGELOG.md ADDED
@@ -0,0 +1,11 @@
1
+ # Changelog
2
+
3
+ ## v0.0.1
4
+
5
+ * Initial release; Implement basic feature
6
+ * `ghi list`
7
+ * `ghi list user/repo`
8
+ * `ghi --open list` open notifications in browser
9
+ * `ghi --mark-as-read` mark notifications as read
10
+ * `ghi --help` show help message
11
+ * Create project page
data/README.md CHANGED
@@ -1,5 +1,7 @@
1
1
  # Ghn
2
2
 
3
+ [![Build Status](https://travis-ci.org/kyanny/ghn.png?branch=master)](https://travis-ci.org/kyanny/ghn) [![Coverage Status](https://coveralls.io/repos/kyanny/ghn/badge.png?branch=master)](https://coveralls.io/r/kyanny/ghn?branch=master) [![Code Climate](https://codeclimate.com/github/kyanny/ghn.png)](https://codeclimate.com/github/kyanny/ghn)
4
+
3
5
  Commandline tool for GitHub notifications.
4
6
 
5
7
  ## Installation
data/Rakefile CHANGED
@@ -1 +1,5 @@
1
1
  require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new("spec")
5
+ task :default => :spec
data/bin/ghn CHANGED
@@ -3,50 +3,21 @@ $LOAD_PATH << File.join(__dir__, '..', 'lib')
3
3
  require 'ghn'
4
4
  require 'optparse'
5
5
 
6
- auth_error_message = <<EOM
7
- Authorization required.
8
-
9
- Please set ghn.token to your .gitconfig.
10
- $ git config --global ghn.token [Your GitHub access token]
11
- EOM
12
-
13
- usage = <<USAGE
14
- Usage: #{File.basename $0} [options] [command] [user/repo]
15
- options: --open Open notifications in browser
16
- --mark-as-read Mark as read listed notifications
17
-
18
- command: list List unread notifications
19
-
20
- user/repo: GitHub user and repository (e.g. github/hubot)
21
- You can specify it to narrow down target notifications
22
-
23
- USAGE
24
-
25
- access_token = ENV['ACCESS_TOKEN'] || `git config ghn.token`.chomp
26
- if access_token.nil? || access_token.empty?
27
- puts auth_error_message; exit!
6
+ token = Ghn::Token.new
7
+ unless token.valid?
8
+ token.print_no_access_token_exit!
28
9
  end
29
- ghn = Ghn.new(access_token)
30
10
 
31
- opts = OptionParser.new
32
- opts.on('--open', 'Open notifications in browser') { |v| ghn.open_browser = true }
33
- opts.on('--mark-as-read', 'Mark as read notifications') { |v| ghn.mark_as_read = true }
34
- opts.on('-h', '--help') { puts usage; exit }
35
- opts.on('--usage') { puts usage; exit}
36
- opts.parse!
37
-
38
- if ghn.open_browser?
39
- ghn.mark_as_read = false
11
+ options = Ghn::Options.new(ARGV.getopts(Ghn::Options.short_options, *Ghn::Options.long_options))
12
+ if options.open_browser?
13
+ options.mark_as_read = false
40
14
  end
41
15
 
42
- if ARGV.first != 'list'
43
- puts usage; exit
16
+ command = Ghn::Command.new(ARGV)
17
+ unless command.valid?
18
+ command.print_invalid
19
+ Ghn::Options.print_usage_exit
44
20
  end
45
21
 
46
- ghn.send(*ARGV).each do |notification|
47
- if ghn.open_browser?
48
- system "open #{notification}"
49
- else
50
- puts notification
51
- end
52
- end
22
+ ghn = Ghn.new(token, command, options)
23
+ ghn.run_print
data/ghn.gemspec CHANGED
@@ -22,4 +22,6 @@ Gem::Specification.new do |spec|
22
22
 
23
23
  spec.add_development_dependency "bundler", "~> 1.3"
24
24
  spec.add_development_dependency "rake"
25
+ spec.add_development_dependency "rspec"
26
+ spec.add_development_dependency "coveralls"
25
27
  end
@@ -0,0 +1,46 @@
1
+ class Ghn
2
+ class Command
3
+ def self.commands
4
+ ['list']
5
+ end
6
+
7
+ attr_reader :command
8
+ attr_reader :args
9
+
10
+ def initialize(argv)
11
+ @argv = argv
12
+ @valid = false
13
+ process!
14
+ end
15
+
16
+ def process!
17
+ @command = @argv.first
18
+ if self.class.commands.include?(@command)
19
+ @valid = true
20
+ @args = @argv.drop(1)
21
+ else
22
+ @valid = false
23
+ end
24
+ end
25
+
26
+ def valid?
27
+ !!@valid
28
+ end
29
+
30
+ def print_invalid
31
+ if @command.nil? || @command.empty?
32
+ print_empty_command
33
+ else
34
+ print_invalid_command
35
+ end
36
+ end
37
+
38
+ def print_empty_command
39
+ puts "** No command"
40
+ end
41
+
42
+ def print_invalid_command
43
+ puts "** Invalid command `#{@command}`"
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,58 @@
1
+ require 'hashie/mash'
2
+
3
+ class Ghn
4
+ class Options < Hashie::Mash
5
+ def open_browser=(bool)
6
+ @open_browser = bool
7
+ end
8
+
9
+ def open_browser?
10
+ !!(@open_browser || self['o'] || self['open'])
11
+ end
12
+
13
+ def mark_as_read=(bool)
14
+ @mark_as_read = bool
15
+ end
16
+
17
+ def mark_as_read?
18
+ !!(@mark_as_read || self['m'] || self['mark-as-read'])
19
+ end
20
+
21
+ def help?
22
+ !!(self['h'] || self['help'])
23
+ end
24
+
25
+ class << self
26
+ def short_options
27
+ 'omnh'
28
+ end
29
+
30
+ def long_options
31
+ ['open', 'mark-as-read']
32
+ end
33
+
34
+ def usage
35
+ <<-USAGE
36
+ Usage: #{File.basename $0} [options] [command] [user/repo]
37
+ options: --open Open notifications in browser
38
+ --mark-as-read Mark as read listed notifications
39
+
40
+ command: list List unread notifications
41
+
42
+ user/repo: GitHub user and repository (e.g. github/hubot)
43
+ You can specify it to narrow down target notifications
44
+
45
+ USAGE
46
+ end
47
+
48
+ def print_usage
49
+ puts usage
50
+ end
51
+
52
+ def print_usage_exit
53
+ print_usage
54
+ exit
55
+ end
56
+ end
57
+ end
58
+ end
data/lib/ghn/token.rb ADDED
@@ -0,0 +1,39 @@
1
+ class Ghn
2
+ class Token
3
+ attr_reader :token
4
+
5
+ def initialize
6
+ @valid = false
7
+ process!
8
+ end
9
+
10
+ def process!
11
+ @token = ENV['ACCESS_TOKEN'] || `git config ghn.token`.chomp
12
+
13
+ if @token.nil? || @token.empty?
14
+ @valid = false
15
+ else
16
+ @valid = true
17
+ end
18
+ end
19
+
20
+ def valid?
21
+ !!@valid
22
+ end
23
+
24
+ def print_no_access_token
25
+ puts <<MESSAGE
26
+ ** Authorization required.
27
+
28
+ Please set ghn.token to your .gitconfig.
29
+ $ git config --global ghn.token [Your GitHub access token]
30
+
31
+ MESSAGE
32
+ end
33
+
34
+ def print_no_access_token_exit!
35
+ print_no_access_token
36
+ exit!
37
+ end
38
+ end
39
+ end
data/lib/ghn/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  class Ghn
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
data/lib/ghn.rb CHANGED
@@ -1,17 +1,32 @@
1
- require "ghn/version"
1
+ require 'ghn/version'
2
+ require 'ghn/token'
3
+ require 'ghn/options'
4
+ require 'ghn/command'
2
5
  require 'github_api'
3
6
 
4
7
  class Ghn
5
- attr_accessor :open_browser, :mark_as_read
6
- alias_method :open_browser?, :open_browser
7
- alias_method :mark_as_read?, :mark_as_read
8
+ def initialize(token, command, options)
9
+ @token = token
10
+ @command = command
11
+ @options = options
12
+ end
13
+
14
+ def run
15
+ send(@command.command, *@command.args)
16
+ end
8
17
 
9
- def initialize(access_token)
10
- @access_token = access_token
18
+ def run_print
19
+ run.each do |notification|
20
+ if @options.open_browser?
21
+ system "open #{notification}"
22
+ else
23
+ puts notification
24
+ end
25
+ end
11
26
  end
12
27
 
13
28
  def client
14
- @client ||= Github.new(oauth_token: @access_token)
29
+ @client ||= Github.new(oauth_token: @token.token)
15
30
  end
16
31
 
17
32
  def list(target = nil)
@@ -27,7 +42,7 @@ class Ghn
27
42
  else
28
43
  ['issues', notification.subject.url.match(/[^\/]+\z/).to_a.first]
29
44
  end
30
- if mark_as_read?
45
+ if @options.mark_as_read?
31
46
  self.mark(notification.id)
32
47
  "[x] https://github.com/#{repo}/#{type}/#{number}"
33
48
  else
@@ -0,0 +1,21 @@
1
+ require 'spec_helper'
2
+
3
+ describe Ghn do
4
+ let(:token) { double }
5
+ let(:command) { double }
6
+ let(:options) { double }
7
+
8
+ describe '#initialize' do
9
+ context 'if no arguments is passed' do
10
+ it 'should raise error' do
11
+ expect { described_class.new }.to raise_error
12
+ end
13
+ end
14
+
15
+ context 'if token, command and options argument is passed' do
16
+ it 'should not raise error' do
17
+ expect { described_class.new(token, command, options) }.to_not raise_error
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,19 @@
1
+ require 'rspec'
2
+
3
+ require 'simplecov'
4
+ require 'coveralls'
5
+
6
+ SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
7
+ SimpleCov::Formatter::HTMLFormatter,
8
+ Coveralls::SimpleCov::Formatter
9
+ ]
10
+ SimpleCov.start do
11
+ add_filter '.bundle/'
12
+ end
13
+
14
+ require 'securerandom'
15
+
16
+ require 'ghn'
17
+
18
+ RSpec.configure do |config|
19
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ghn
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kensuke Nagae
@@ -52,6 +52,34 @@ dependencies:
52
52
  - - '>='
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: coveralls
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
55
83
  description: Commandline tool for GitHub notifications
56
84
  email:
57
85
  - kyanny@gmail.com
@@ -60,7 +88,10 @@ executables:
60
88
  extensions: []
61
89
  extra_rdoc_files: []
62
90
  files:
91
+ - .coveralls.yml
63
92
  - .gitignore
93
+ - .travis.yml
94
+ - CHANGELOG.md
64
95
  - Gemfile
65
96
  - LICENSE.txt
66
97
  - README.md
@@ -68,7 +99,12 @@ files:
68
99
  - bin/ghn
69
100
  - ghn.gemspec
70
101
  - lib/ghn.rb
102
+ - lib/ghn/command.rb
103
+ - lib/ghn/options.rb
104
+ - lib/ghn/token.rb
71
105
  - lib/ghn/version.rb
106
+ - spec/lib/ghn_spec.rb
107
+ - spec/spec_helper.rb
72
108
  homepage: https://github.com/kyanny/ghn
73
109
  licenses:
74
110
  - MIT
@@ -94,4 +130,6 @@ signing_key:
94
130
  specification_version: 4
95
131
  summary: Ghn is a commandline tool for GitHub notifications. You can listup all unread
96
132
  notifications and mark them as read.
97
- test_files: []
133
+ test_files:
134
+ - spec/lib/ghn_spec.rb
135
+ - spec/spec_helper.rb