gipull 0.1.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,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: ca9277d037a07c18e90729640fc720358c69963b
4
+ data.tar.gz: a4184a53aba7d78e508cd08387d3e04ec3909179
5
+ SHA512:
6
+ metadata.gz: f315db7492622ed4d00e2b3c17f51007af5f02c8b722ea4172b617583eb6d62b05c3ed1f9bc35957dd26e6dd6dab6aa0484c0e0af2e2daec9f6c88d3f56827fa
7
+ data.tar.gz: 4321fc12c9b70d8483258e6225a21b67b08cf3d58819e883d31417db11b311b6c552d24d871e1c8466bcf0db54f7d1da7a89d866c1ea4096d6979c96e3afc821
@@ -0,0 +1,10 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ /vendor
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.3
4
+ before_install: gem install bundler -v 1.10.6
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in gipull.gemspec
4
+ gemspec
@@ -0,0 +1,47 @@
1
+ # Gipull
2
+
3
+ ## Installation
4
+
5
+ ```
6
+ gem i gipull
7
+ ```
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+
12
+ ```ruby
13
+ gem 'gipull'
14
+ ```
15
+
16
+ And then execute:
17
+
18
+ $ bundle
19
+
20
+ ### Init
21
+
22
+ ```
23
+ $ gipull init
24
+ AccessToken:
25
+ ```
26
+
27
+ ## Usage
28
+
29
+ ```
30
+ Commands:
31
+ gipull config # List config
32
+ gipull init # Initialized gipull
33
+ gipull list --org=one two three # List pull-requests
34
+ ```
35
+
36
+ ```
37
+ $ list --org org1 org2 --repo repo1 repo2 --since 30
38
+
39
+ $ list --org org1 --repo repo1*
40
+
41
+ $ list --org org1 --excluderepo repo1
42
+ ```
43
+
44
+ ## Contributing
45
+
46
+ Bug reports and pull requests are welcome on GitHub at https://github.com/zaru/gipull.
47
+
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "gipull"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "gipull"
4
+
5
+ Gipull::CLI.start
@@ -0,0 +1,29 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'gipull/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "gipull"
8
+ spec.version = Gipull::VERSION
9
+ spec.authors = ["zaru"]
10
+ spec.email = ["zarutofu@gmail.com"]
11
+
12
+ spec.summary = %q{To get the pull request list of GitHub}
13
+ spec.description = %q{To get the pull request list of GitHub}
14
+ spec.homepage = "https://github.com/zaru/gipull"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
17
+ spec.bindir = "exe"
18
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_dependency "thor"
22
+ spec.add_dependency "octokit"
23
+
24
+ spec.add_development_dependency "bundler", "~> 1.10"
25
+ spec.add_development_dependency "rake", "~> 10.0"
26
+ spec.add_development_dependency "rspec"
27
+ spec.add_development_dependency "pry"
28
+ spec.add_development_dependency 'pry-byebug'
29
+ end
@@ -0,0 +1,72 @@
1
+ require "gipull/version"
2
+ require "gipull/config"
3
+ require "gipull/formatter"
4
+ require "thor"
5
+ require "octokit"
6
+ require "json"
7
+ require "uri"
8
+
9
+ module Gipull
10
+ class CLI < Thor
11
+
12
+ class_options [ :config ]
13
+
14
+ def initialize(*args)
15
+ super
16
+ @config = Gipull::Config.instance
17
+ end
18
+
19
+ desc "list", "List pull-requests"
20
+ option :org, :type => :array, :required => true
21
+ option :repo, :type => :array, :default => []
22
+ option :excluderepo, :type => :array, :default => []
23
+ option :since, :type => :numeric, :default => 7
24
+ def list
25
+ init unless @config.access_token
26
+
27
+ client = Octokit::Client.new(:access_token => @config.access_token)
28
+ client.auto_paginate = true
29
+
30
+ issues = []
31
+ options[:org].each do |org|
32
+ issues.concat client.org_issues org, :filter => 'all', :state => 'open', :since => (Time.now - options[:since] * 86400).iso8601
33
+ end
34
+
35
+ prs = []
36
+ issues.each do |issue|
37
+ next if issue['pull_request'].nil?
38
+ next if !options[:repo].empty? && options[:repo].select{|r| issue['repository']['name'] =~ convert_regex(r) }.empty?
39
+ next if !options[:excluderepo].empty? && !options[:excluderepo].select{|r| issue['repository']['name'] =~ convert_regex(r) }.empty?
40
+ row = [issue['title'], issue['html_url']]
41
+ row << colored_message(issue['labels'].map{|l| l['name'] }.join(" ")) unless issue['labels'].empty?
42
+ prs << row
43
+ end
44
+
45
+ return if prs.empty?
46
+
47
+ formatter = Gipull::Formatter.new(prs)
48
+ say formatter.render
49
+ end
50
+
51
+ desc "init", "Initialized gipull"
52
+ def init
53
+ token = ask 'AccessToken:'
54
+ @config.access_token = token
55
+ end
56
+
57
+ desc "config", "List config"
58
+ def config
59
+ say @config.data
60
+ end
61
+
62
+ no_commands do
63
+ def colored_message(message)
64
+ set_color message, :white, :on_red, :bold
65
+ end
66
+
67
+ def convert_regex(str)
68
+ /\A#{str.gsub('*','.*')}\Z/
69
+ end
70
+ end
71
+ end
72
+ end
@@ -0,0 +1,43 @@
1
+ require "singleton"
2
+ require "yaml"
3
+
4
+ module Gipull
5
+ class Config
6
+ include Singleton
7
+
8
+ attr_reader :path, :data
9
+ FILE_NAME = ".gipull".freeze
10
+
11
+ def initialize
12
+ @path = File.join(File.expand_path('~'), FILE_NAME)
13
+ @data = load_file
14
+ end
15
+
16
+ def load_file
17
+ YAML.load_file(@path)
18
+ rescue Errno::ENOENT
19
+ default_structure
20
+ end
21
+
22
+ def access_token
23
+ @data["access_token"]
24
+ end
25
+
26
+ def access_token=(access_token)
27
+ @data["access_token"] = access_token
28
+ write
29
+ end
30
+
31
+ private
32
+
33
+ def default_structure
34
+ { "access_token" => nil }
35
+ end
36
+
37
+ def write
38
+ File.open(@path, File::RDWR | File::TRUNC | File::CREAT, 0600) do |file|
39
+ file.write @data.to_yaml
40
+ end
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,43 @@
1
+ module Gipull
2
+ class Formatter
3
+
4
+ def initialize(data)
5
+ @data = data
6
+ @sizes = column_size
7
+ end
8
+
9
+ def render
10
+ output = ""
11
+ @data.each do |r|
12
+ r.each_with_index do |v,i|
13
+ output += pad_to_print_size(v.to_s, @sizes[i] + 2)
14
+ end
15
+ output += "\n"
16
+ end
17
+ output
18
+ end
19
+
20
+ private
21
+
22
+ def pad_to_print_size(string, size)
23
+ padding_size = size - print_size(string)
24
+ padding_size = 0 if size < 0
25
+ string + ' ' * padding_size
26
+ end
27
+
28
+ def print_size(string)
29
+ string.each_char.map{|c| c.ascii_only? ? 1 : 2}.reduce(0, &:+)
30
+ end
31
+
32
+ def column_size
33
+ sizes = Array.new(@data[0].size, 0)
34
+ @data.each do |r|
35
+ r.each_with_index do |v,i|
36
+ size = print_size(v)
37
+ sizes[i] = size if sizes[i] < size
38
+ end
39
+ end
40
+ sizes
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,3 @@
1
+ module Gipull
2
+ VERSION = "0.1.0"
3
+ end
metadata ADDED
@@ -0,0 +1,156 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: gipull
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - zaru
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-06-14 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: thor
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: octokit
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.10'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.10'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '10.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '10.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
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'
83
+ - !ruby/object:Gem::Dependency
84
+ name: pry
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: pry-byebug
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ description: To get the pull request list of GitHub
112
+ email:
113
+ - zarutofu@gmail.com
114
+ executables:
115
+ - gipull
116
+ extensions: []
117
+ extra_rdoc_files: []
118
+ files:
119
+ - ".gitignore"
120
+ - ".rspec"
121
+ - ".travis.yml"
122
+ - Gemfile
123
+ - README.md
124
+ - Rakefile
125
+ - bin/console
126
+ - bin/setup
127
+ - exe/gipull
128
+ - gipull.gemspec
129
+ - lib/gipull.rb
130
+ - lib/gipull/config.rb
131
+ - lib/gipull/formatter.rb
132
+ - lib/gipull/version.rb
133
+ homepage: https://github.com/zaru/gipull
134
+ licenses: []
135
+ metadata: {}
136
+ post_install_message:
137
+ rdoc_options: []
138
+ require_paths:
139
+ - lib
140
+ required_ruby_version: !ruby/object:Gem::Requirement
141
+ requirements:
142
+ - - ">="
143
+ - !ruby/object:Gem::Version
144
+ version: '0'
145
+ required_rubygems_version: !ruby/object:Gem::Requirement
146
+ requirements:
147
+ - - ">="
148
+ - !ruby/object:Gem::Version
149
+ version: '0'
150
+ requirements: []
151
+ rubyforge_project:
152
+ rubygems_version: 2.4.5.1
153
+ signing_key:
154
+ specification_version: 4
155
+ summary: To get the pull request list of GitHub
156
+ test_files: []