senju 0.0.1 → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c962aa99f1029b7768a90675777515bdd1b7147802c84069e63377e3bdac5cf3
4
- data.tar.gz: c43ece4850cfb002209ba121a15ff03d7585e4a19a5d280c1ff13cbab41791bd
3
+ metadata.gz: 75d31c196c9ce12d447f1bdf6ec3ce69cbc579e573d20d993175a0217d10e941
4
+ data.tar.gz: 556aceff1f2be393173c0f82a964663f589f5efcd6f974cfda5961d57d9128a0
5
5
  SHA512:
6
- metadata.gz: 2a38f3df592c4ec92fe0879492f2579beef320d7c13266293b024af37e88de945698381de903eee1cbf3aaee91f9ddfc43dd8240e957b996da1e83a8585f2675
7
- data.tar.gz: d273dfe9291732d54d7a4e27ce15b6d47738fa8ba822994dd73f9e3aeba493415dbe4163ba55dad16dd1a2ac5d6e576694d262b396ca8c521aca4490ef0fc343
6
+ metadata.gz: 0fe4c55775f59f0dac5e42439fe6123d1152fd4a6fefef974d946e3b265cc3899cd4605eda606ea072fb95706d494febaa08bff3be16beb694ef41f083338ad9
7
+ data.tar.gz: bcd4bffc541d2796db03464647d68a43d513a851b2a85f30e5fa57acd473d72c7c8295a80ea0ced84a9adc6a12610044fe3d3a1f1e493ca14b239778d53a12e8
data/.gitignore CHANGED
@@ -6,6 +6,7 @@
6
6
  /pkg/
7
7
  /spec/reports/
8
8
  /tmp/
9
+ Gemfile.lock
9
10
 
10
11
  # rspec failure tracking
11
12
  .rspec_status
data/README.md CHANGED
@@ -1,28 +1,56 @@
1
1
  # Senju
2
2
 
3
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/senju`. To experiment with that code, run `bin/console` for an interactive prompt.
4
-
5
- TODO: Delete this and the text above, and describe your gem
3
+ Listing your issues.
6
4
 
7
5
  ## Installation
8
6
 
9
- Add this line to your application's Gemfile:
7
+ $ gem install senju
10
8
 
11
- ```ruby
12
- gem 'senju'
13
- ```
9
+ ## Configuration
14
10
 
15
- And then execute:
11
+ Making `~/.senju` directory.
16
12
 
17
- $ bundle
13
+ $ mkdir ~/.senju
18
14
 
19
- Or install it yourself as:
15
+ ### Credentials
20
16
 
21
- $ gem install senju
17
+ Edit `~/.senju/credentials`.
18
+
19
+ ```
20
+ <type>: <access token>
21
+ ```
22
+
23
+ ### Repositories
24
+
25
+ Edit `~/.senju/repos`.
26
+
27
+ ```
28
+ <repository alias>:
29
+ repo: <team/repository name>
30
+ type: <repository type>
31
+ ```
22
32
 
23
33
  ## Usage
24
34
 
25
- TODO: Write usage instructions here
35
+ All repository issues.
36
+
37
+ $ senju
38
+
39
+ Repository issues.
40
+
41
+ $ senju <repository alias> [issues]
42
+
43
+ Repository Pull-Requests.
44
+
45
+ $ senju <repository alias> pr
46
+
47
+ Issue/Pull-Request detail.
48
+
49
+ $ senju <repository alias> <issue no> [-v|comments|diff]
50
+
51
+ Merge Request detail (GitLab)
52
+
53
+ $ senju <repository alias> mr <issue no> [-v|comments|diff]
26
54
 
27
55
  ## Development
28
56
 
@@ -0,0 +1,105 @@
1
+ #!/usr/bin/env ruby
2
+ require "bundler/setup"
3
+ require "senju"
4
+ require "ap"
5
+ require "colorize"
6
+ require "tty-markdown"
7
+ require "rumoji"
8
+
9
+ COLORS = %w{green blue light_blue}
10
+
11
+ def link_to(text, url)
12
+ "\e]8;;#{url}\e\\#{text}\e]8;;\e\\"
13
+ end
14
+
15
+ def print_issue(issue)
16
+ print link_to("##{issue.no} ".colorize(:blue).bold, issue.url) + issue.title + "\n"
17
+ end
18
+
19
+ def color_patch(patch)
20
+ patch.split("\n").map do |line|
21
+ case line
22
+ when /^(---|\+\+\+|\\\\)/
23
+ "\033[90m#{line.chomp}\033[0m"
24
+ when /^\+/
25
+ "\033[32m#{line.chomp}\033[0m"
26
+ when /^-/
27
+ "\033[31m#{line.chomp}\033[0m"
28
+ when /^@@/
29
+ "\033[36m#{line.chomp}\033[0m"
30
+ else
31
+ line.chomp
32
+ end
33
+ end.join("\n") + "\n"
34
+ end
35
+
36
+ def exec(repo, command, option)
37
+ puts "================= #{repo.name} ====================".colorize(:green).bold
38
+
39
+ if command.to_i != 0
40
+ issue = repo.issue(command.to_i)
41
+ print_issue issue
42
+ puts "Opened by #{issue.owner} at #{issue.created_at}"
43
+
44
+ puts "\n" + Rumoji.decode(TTY::Markdown.parse(issue.body))
45
+
46
+ if option == "-v" || option == "comments"
47
+ repo.comments(command.to_i).each do |comment|
48
+ #color = COLORS[comment.owner[0].ord % 3]
49
+ puts "\nComment: #{comment.owner} at #{comment.created_at}".bold
50
+ puts Rumoji.decode(TTY::Markdown.parse(comment.body))
51
+ end
52
+ elsif option == "diff"
53
+ repo.changes(command.to_i).each do |change|
54
+ puts "\n#{change.filename}".bold
55
+ puts color_patch(change.patch)
56
+ end
57
+ end
58
+
59
+ return
60
+ end
61
+
62
+ case command
63
+ when "issues"
64
+ repo.issues.each do |issue|
65
+ print_issue(issue)
66
+ end
67
+ when "mr"
68
+ command = option
69
+ option = ARGV[3]
70
+ issue = repo.pull_request(command.to_i)
71
+ print_issue issue
72
+ puts "Opened by #{issue.owner} at #{issue.created_at}"
73
+
74
+ puts "\n" + Rumoji.decode(TTY::Markdown.parse(issue.body))
75
+
76
+ if option == "-v" || option == "comments"
77
+ repo.comments(command.to_i).each do |comment|
78
+ #color = COLORS[comment.owner[0].ord % 3]
79
+ puts "\nComment: #{comment.owner} at #{comment.created_at}".bold
80
+ puts Rumoji.decode(TTY::Markdown.parse(comment.body))
81
+ end
82
+ elsif option == "diff"
83
+ repo.changes(command.to_i).each do |change|
84
+ puts "\n#{change.filename}".bold
85
+ puts color_patch(change.patch)
86
+ end
87
+ end
88
+ when "pr"
89
+ repo.pull_requests.each do |issue|
90
+ print_issue(issue)
91
+ end
92
+ end
93
+ end
94
+
95
+ repo = ARGV[0]
96
+ command = ARGV[1] || "issues"
97
+ option = ARGV[2]
98
+
99
+ if repo
100
+ exec(Senju::Repository.find(repo), command, option)
101
+ else
102
+ Senju::Repository.all.each do |repo|
103
+ exec(repo, command, option)
104
+ end
105
+ end
@@ -1,4 +1,11 @@
1
1
  require "senju/version"
2
+ require "senju/credentials"
3
+ require "senju/repository"
4
+ require "senju/github"
5
+ require "senju/gitlab"
6
+ require "senju/issue"
7
+ require "senju/comment"
8
+ require "senju/change"
2
9
 
3
10
  module Senju
4
11
  # Your code goes here...
@@ -0,0 +1,28 @@
1
+ class Senju::Change
2
+ attr_reader :raw, :type
3
+ def initialize(raw, type)
4
+ @raw = raw
5
+ @type = type
6
+ end
7
+
8
+ def method_missing(method, *args, &block)
9
+ case type
10
+ when "github" then @raw[method]
11
+ when "gitlab" then @raw.send(method)
12
+ end
13
+ end
14
+
15
+ def filename
16
+ case type
17
+ when "github" then super
18
+ when "gitlab" then @raw["new_path"]
19
+ end
20
+ end
21
+
22
+ def patch
23
+ case type
24
+ when "github" then super
25
+ when "gitlab" then @raw["diff"]
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,35 @@
1
+ class Senju::Comment
2
+ attr_reader :raw, :type
3
+ def initialize(raw, type)
4
+ @raw = raw
5
+ @type = type
6
+ end
7
+
8
+ def method_missing(method, *args, &block)
9
+ case type
10
+ when "github" then @raw[method]
11
+ when "gitlab" then @raw.send(method)
12
+ end
13
+ end
14
+
15
+ def no
16
+ case type
17
+ when "github" then @raw["number"]
18
+ when "gitlab" then @raw.iid
19
+ end
20
+ end
21
+
22
+ def owner
23
+ case type
24
+ when "github" then @raw["user"]["login"]
25
+ when "gitlab" then @raw.author.username
26
+ end
27
+ end
28
+
29
+ def url
30
+ case type
31
+ when "github" then @raw["html_url"]
32
+ when "gitlab" then @raw.web_url
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,22 @@
1
+ require 'yaml'
2
+ class Senju::Credentials
3
+ attr_reader :data
4
+ def initialize(filepath = nil)
5
+ filepath ||= Dir.home + '/.senju/credentials'
6
+ @data = YAML.load_file(filepath)
7
+ end
8
+
9
+ def [](conf)
10
+ @data[conf]
11
+ end
12
+ end
13
+
14
+ class Senju::Credential
15
+ def self.all
16
+ Senju::Credentials.new.data
17
+ end
18
+
19
+ def self.find(key)
20
+ all[key]
21
+ end
22
+ end
@@ -0,0 +1,12 @@
1
+ require 'octokit'
2
+ class Senju::Github
3
+ attr_reader :client
4
+
5
+ def initialize(access_token)
6
+ @client = Octokit::Client.new(access_token: access_token)
7
+ end
8
+
9
+ def method_missing(method, *args, &block)
10
+ client.send(method, *args, &block)
11
+ end
12
+ end
@@ -0,0 +1,13 @@
1
+ require 'gitlab'
2
+ class Senju::Gitlab
3
+ attr_reader :client
4
+
5
+ def initialize(access_token, endpoint = nil)
6
+ endpoint ||= "https://gitlab.com/api/v4"
7
+ @client = Gitlab.client(endpoint: endpoint, private_token: access_token)
8
+ end
9
+
10
+ def method_missing(method, *args, &block)
11
+ client.send(method, *args, &block)
12
+ end
13
+ end
@@ -0,0 +1,42 @@
1
+ class Senju::Issue
2
+ attr_reader :raw, :type
3
+ def initialize(raw, type)
4
+ @raw = raw
5
+ @type = type
6
+ end
7
+
8
+ def method_missing(method, *args, &block)
9
+ case type
10
+ when "github" then @raw[method]
11
+ when "gitlab" then @raw.send(method)
12
+ end
13
+ end
14
+
15
+ def no
16
+ case type
17
+ when "github" then @raw["number"]
18
+ when "gitlab" then @raw.iid
19
+ end
20
+ end
21
+
22
+ def owner
23
+ case type
24
+ when "github" then @raw["user"]["login"]
25
+ when "gitlab" then @raw.author.username
26
+ end
27
+ end
28
+
29
+ def url
30
+ case type
31
+ when "github" then @raw["html_url"]
32
+ when "gitlab" then @raw.web_url
33
+ end
34
+ end
35
+
36
+ def body
37
+ case type
38
+ when "github" then super
39
+ when "gitlab" then @raw.description
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,94 @@
1
+ require 'yaml'
2
+ class Senju::Repos
3
+ attr_reader :data
4
+ def initialize(filepath = nil)
5
+ filepath ||= Dir.home + '/.senju/repos'
6
+ @data = YAML.load_file(filepath)
7
+ end
8
+
9
+ def [](conf)
10
+ @data[conf]
11
+ end
12
+ end
13
+
14
+ class Senju::Repository
15
+ attr_reader :name, :options, :type
16
+
17
+ def self.all
18
+ Senju::Repos.new.data.map do |repository, config|
19
+ new(repository, config)
20
+ end
21
+ end
22
+
23
+ def self.first
24
+ all.first
25
+ end
26
+
27
+ def self.find(name)
28
+ new(name, Senju::Repos.new[name])
29
+ end
30
+
31
+ def initialize(name, options)
32
+ @name = options["repo"] || name
33
+ @options = options
34
+ @type = options["type"]
35
+ end
36
+
37
+ def client
38
+ credential = Senju::Credential.find(type)
39
+ case type
40
+ when "github" then Senju::Github.new(credential)
41
+ when "gitlab" then Senju::Gitlab.new(credential)
42
+ end
43
+ end
44
+
45
+ def issue(no)
46
+ Senju::Issue.new(client.issue(name, no), type)
47
+ end
48
+
49
+ def pull_request(no)
50
+ case type
51
+ when "github" then list = Senju::Issue.new(client.pull_request(name, no), type)
52
+ when "gitlab" then list = Senju::Issue.new(client.merge_request(name, no), type)
53
+ end
54
+ end
55
+
56
+ def comments(no)
57
+ case type
58
+ when "github" then list = client.issue_comments(name, no)
59
+ when "gitlab" then list = client.issue_notes(name, no)
60
+ end
61
+
62
+ list.map do |raw|
63
+ Senju::Comment.new(raw, type)
64
+ end
65
+ end
66
+
67
+ def changes(no)
68
+ case type
69
+ when "github" then list = client.pull_request_files(name, no)
70
+ when "gitlab" then list = client.merge_request_changes(name, no).changes
71
+ end
72
+
73
+ list.map do |raw|
74
+ Senju::Change.new(raw, type)
75
+ end
76
+ end
77
+
78
+ def issues
79
+ client.issues(name).map do |raw|
80
+ Senju::Issue.new(raw, type)
81
+ end
82
+ end
83
+
84
+ def pull_requests
85
+ case type
86
+ when "github" then list = client.pull_requests(name)
87
+ when "gitlab" then list = client.merge_requests(name)
88
+ end
89
+
90
+ list.map do |raw|
91
+ Senju::Issue.new(raw, type)
92
+ end
93
+ end
94
+ end
@@ -1,3 +1,3 @@
1
1
  module Senju
2
- VERSION = "0.0.1"
2
+ VERSION = "0.3.1"
3
3
  end
@@ -31,6 +31,12 @@ Gem::Specification.new do |spec|
31
31
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
32
32
  spec.require_paths = ["lib"]
33
33
 
34
+ spec.add_dependency "octokit", "~> 4.9.0"
35
+ spec.add_dependency "gitlab", "~> 4.5.0"
36
+ spec.add_dependency "awesome_print"
37
+ spec.add_dependency "colorize"
38
+ spec.add_dependency "tty-markdown"
39
+ spec.add_dependency "rumoji"
34
40
  spec.add_development_dependency "bundler", "~> 1.16"
35
41
  spec.add_development_dependency "rake", "~> 10.0"
36
42
  spec.add_development_dependency "rspec", "~> 3.0"
metadata CHANGED
@@ -1,15 +1,99 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: senju
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Akira SUENAMI
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-10-18 00:00:00.000000000 Z
11
+ date: 2019-01-05 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: octokit
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 4.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: 4.9.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: gitlab
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 4.5.0
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 4.5.0
41
+ - !ruby/object:Gem::Dependency
42
+ name: awesome_print
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: colorize
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
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: tty-markdown
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :runtime
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: rumoji
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
13
97
  - !ruby/object:Gem::Dependency
14
98
  name: bundler
15
99
  requirement: !ruby/object:Gem::Requirement
@@ -55,7 +139,8 @@ dependencies:
55
139
  description: You can get your todos from some tools.
56
140
  email:
57
141
  - a.suenami@gmail.com
58
- executables: []
142
+ executables:
143
+ - senju
59
144
  extensions: []
60
145
  extra_rdoc_files: []
61
146
  files:
@@ -67,7 +152,15 @@ files:
67
152
  - Rakefile
68
153
  - bin/console
69
154
  - bin/setup
155
+ - exe/senju
70
156
  - lib/senju.rb
157
+ - lib/senju/change.rb
158
+ - lib/senju/comment.rb
159
+ - lib/senju/credentials.rb
160
+ - lib/senju/github.rb
161
+ - lib/senju/gitlab.rb
162
+ - lib/senju/issue.rb
163
+ - lib/senju/repository.rb
71
164
  - lib/senju/version.rb
72
165
  - senju.gemspec
73
166
  homepage: https://github.com/mi2zq/senju