ghn 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 7b93cf1ccda9576a2bfc0e29b6a8a8049f5c40f0
4
+ data.tar.gz: c410e0b9c368e80f6f455393d2e2a81b87ca2d25
5
+ SHA512:
6
+ metadata.gz: 113f7e9856ec04f81446a581233aa2f6c421a65b35725a33d1d067266e9f1566238f49c6aa07e013c7dc86ba361226429ab016d1da1ad50b9c75d7503e6868be
7
+ data.tar.gz: 1b5e77e6973b1a7d17ce11b8ac2b8b990053b10a829a1f3ef9ee49416b7f433042537974bce4add5ea879bc64e7337964069114a96bf9b0f4251f215a7c6038f
data/.gitignore ADDED
@@ -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
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in ghn.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Kensuke Nagae
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,35 @@
1
+ # Ghn
2
+
3
+ Commandline tool for GitHub notifications.
4
+
5
+ ## Installation
6
+
7
+ $ gem install ghn
8
+
9
+ ## Usage
10
+
11
+ Run `ghn list` to show all unread notifications in terminal.
12
+
13
+ `ghn list` takes argument `user/repo` to get notifications only target repository.
14
+
15
+ If you give `--open` option, unread notifications are opened in your default browser.
16
+
17
+ If you give `--mark-as-read` option, notifications are marked as read.
18
+
19
+ You can see usage by `-h`, `--help` or `--usage` option.
20
+
21
+ ## Authentication
22
+
23
+ Please set ghn.token to your .gitconfig.
24
+
25
+ $ git config --global ghn.token [Your GitHub access token]
26
+
27
+ You can also set access token via ACCESS_TOKEN environment variable.
28
+
29
+ ## Contributing
30
+
31
+ 1. Fork it
32
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
33
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
34
+ 4. Push to the branch (`git push origin my-new-feature`)
35
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
data/bin/ghn ADDED
@@ -0,0 +1,52 @@
1
+ #!/usr/bin/env ruby
2
+ $LOAD_PATH << File.join(__dir__, '..', 'lib')
3
+ require 'ghn'
4
+ require 'optparse'
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!
28
+ end
29
+ ghn = Ghn.new(access_token)
30
+
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
40
+ end
41
+
42
+ if ARGV.first != 'list'
43
+ puts usage; exit
44
+ end
45
+
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
data/ghn.gemspec ADDED
@@ -0,0 +1,25 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'ghn/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "ghn"
8
+ spec.version = Ghn::VERSION
9
+ spec.authors = ["Kensuke Nagae"]
10
+ spec.email = ["kyanny@gmail.com"]
11
+ spec.description = %q{Commandline tool for GitHub notifications}
12
+ spec.summary = %q{Ghn is a commandline tool for GitHub notifications. You can listup all unread notifications and mark them as read.}
13
+ spec.homepage = "https://github.com/kyanny/ghn"
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_dependency "github_api"
22
+
23
+ spec.add_development_dependency "bundler", "~> 1.3"
24
+ spec.add_development_dependency "rake"
25
+ end
@@ -0,0 +1,3 @@
1
+ class Ghn
2
+ VERSION = "0.0.1"
3
+ end
data/lib/ghn.rb ADDED
@@ -0,0 +1,42 @@
1
+ require "ghn/version"
2
+ require 'github_api'
3
+
4
+ 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
+
9
+ def initialize(access_token)
10
+ @access_token = access_token
11
+ end
12
+
13
+ def client
14
+ @client ||= Github.new(oauth_token: @access_token)
15
+ end
16
+
17
+ def list(target = nil)
18
+ params = {}
19
+ unless target.nil?
20
+ params['user'], params['repo'] = target.split('/')
21
+ end
22
+
23
+ client.activity.notifications.list(params).map { |notification|
24
+ repo = notification.repository.full_name
25
+ type, number = if notification.subject.url.match(/pulls/)
26
+ ['pull', notification.subject.url.match(/[^\/]+\z/).to_a.first]
27
+ else
28
+ ['issues', notification.subject.url.match(/[^\/]+\z/).to_a.first]
29
+ end
30
+ if mark_as_read?
31
+ self.mark(notification.id)
32
+ "[x] https://github.com/#{repo}/#{type}/#{number}"
33
+ else
34
+ "https://github.com/#{repo}/#{type}/#{number}"
35
+ end
36
+ }
37
+ end
38
+
39
+ def mark(id, read = true)
40
+ client.activity.notifications.mark(thread_id: id, read: read)
41
+ end
42
+ end
metadata ADDED
@@ -0,0 +1,97 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ghn
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Kensuke Nagae
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-10-25 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: github_api
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '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'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: '1.3'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: '1.3'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description: Commandline tool for GitHub notifications
56
+ email:
57
+ - kyanny@gmail.com
58
+ executables:
59
+ - ghn
60
+ extensions: []
61
+ extra_rdoc_files: []
62
+ files:
63
+ - .gitignore
64
+ - Gemfile
65
+ - LICENSE.txt
66
+ - README.md
67
+ - Rakefile
68
+ - bin/ghn
69
+ - ghn.gemspec
70
+ - lib/ghn.rb
71
+ - lib/ghn/version.rb
72
+ homepage: https://github.com/kyanny/ghn
73
+ licenses:
74
+ - MIT
75
+ metadata: {}
76
+ post_install_message:
77
+ rdoc_options: []
78
+ require_paths:
79
+ - lib
80
+ required_ruby_version: !ruby/object:Gem::Requirement
81
+ requirements:
82
+ - - '>='
83
+ - !ruby/object:Gem::Version
84
+ version: '0'
85
+ required_rubygems_version: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - '>='
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ requirements: []
91
+ rubyforge_project:
92
+ rubygems_version: 2.0.3
93
+ signing_key:
94
+ specification_version: 4
95
+ summary: Ghn is a commandline tool for GitHub notifications. You can listup all unread
96
+ notifications and mark them as read.
97
+ test_files: []