bu_pr 0.5.0 → 0.6.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 151da8efbdea7d8e1f213c389aec5638ada216fb
4
- data.tar.gz: 8ed0c5664508e90b7eeafa3f2d6830c45d6c8f17
3
+ metadata.gz: dfefdc17a5f821f2fd9b6eaf2d14746d52a7562f
4
+ data.tar.gz: a544d1f62fab74dc852fa1b0c3b8d78eb4c4a100
5
5
  SHA512:
6
- metadata.gz: 57c0c8693900ff6b9ddb68eac293fd47d9927d02f758a8246b8922e0706f01407c672fd656d98740e21ba91ffe62f0dd7571a8ec67a8870cb99230f4c38c11d5
7
- data.tar.gz: 253564184b645a6f4cbdffbc1387275794bea5f788ffe438259368e78e8cf178a429a1aebd9c2bf98a9692255a4f801b4d4a1cda997e8ec0406943d138d2db6f
6
+ metadata.gz: fc2655816c91d8f24cb23e976db2161320426c62870cf2c37d26fc28b8161424e34009180f0526b52e5b3353324ed79f3c624ad8f4f98fc5394d0a00cfc5519c
7
+ data.tar.gz: bcbdba47a2a454c6c7214c9479f7304ae018dcb72f574c5c9ebc3547bc187775011c61ec6408c71091758dbac14e08907a15d90402970836d7db941c1998f856
data/.travis.yml CHANGED
@@ -1,9 +1,9 @@
1
1
  sudo: false
2
2
  language: ruby
3
3
  rvm:
4
- - 2.1.0
5
4
  - 2.2.0
6
5
  - 2.3.0
6
+ - 2.4.0
7
7
  - ruby-head
8
8
  before_install: gem install bundler
9
9
  matrix:
data/bu_pr.gemspec CHANGED
@@ -22,7 +22,6 @@ Gem::Specification.new do |spec|
22
22
  spec.require_paths = ["lib"]
23
23
 
24
24
  spec.add_dependency "compare_linker", "~> 1.1.0"
25
- spec.add_dependency "thor", "~> 0.19"
26
25
 
27
26
  spec.add_development_dependency "bundler", "~> 1.13"
28
27
  spec.add_development_dependency "rake", "~> 10.0"
data/lib/bu_pr/command.rb CHANGED
@@ -1,19 +1,43 @@
1
1
  # frozen_string_literal: true
2
- require "thor"
2
+
3
+ require "optparse"
3
4
 
4
5
  module BuPr
5
- class Command < ::Thor
6
- default_command :all
7
-
8
- desc "all", "Run bundle update and create pull-request"
9
- method_options(
10
- branch: :string,
11
- title: :string,
12
- token: :string,
13
- repo: :string,
14
- )
15
- def all
16
- Runner.call(options)
6
+ class Command
7
+ # Entry Point
8
+ #
9
+ # @note for backward compatibility
10
+ def self.start args
11
+ Runner.call \
12
+ new(args).parse
13
+ end
14
+
15
+ attr_reader :args
16
+ attr_reader :opts
17
+
18
+ # @param args [Array<String>]
19
+ def initialize args
20
+ @args = args
21
+ @opts = {}
22
+ end
23
+
24
+ # @return [Hash<Symbol, String>]
25
+ def parse
26
+ parser.parse! args
27
+ opts
28
+ end
29
+
30
+ private
31
+
32
+ def parser
33
+ ::OptionParser.new do |o|
34
+ o.banner = "Usage: bu_pr [options]"
35
+
36
+ o.on("-b", "--branch [NAME]", String, "Base branch name") { |v| opts[:branch] = v }
37
+ o.on("-t", "--title [TITLE]", String, "pull-request title") { |v| opts[:title] = v }
38
+ o.on("-k", "--token [TOKEN]", String, "GitHub Token") { |v| opts[:token] = v }
39
+ o.on("-r", "--repo [NAME]", String, "GitHub repo name") { |v| opts[:repo] = v }
40
+ end
17
41
  end
18
42
  end
19
43
  end
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  module BuPr
3
4
  class Configuration
4
5
  ATTRS = %i(
@@ -8,10 +9,9 @@ module BuPr
8
9
  repo
9
10
  )
10
11
 
11
- # @return [String]
12
- attr_accessor(*ATTRS)
12
+ attr_accessor(*ATTRS) # @return [String]
13
13
 
14
- # @param opts [Hash]
14
+ # @param opts [Hash]
15
15
  # @option opts [String] :branch Base branch name
16
16
  # @option opts [String] :title pull-request title
17
17
  # @option opts [String] :token GitHub access token
@@ -33,8 +33,9 @@ module BuPr
33
33
 
34
34
  ATTRS.each do |attr|
35
35
  # @private
36
+ # @return [Boolean]
36
37
  define_method "#{attr}?" do
37
- v = public_send(attr)
38
+ v = public_send attr
38
39
  !v.nil? && v != ""
39
40
  end
40
41
  end
data/lib/bu_pr/git.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  module BuPr
3
4
  class Git
4
5
  LOCKFILE = "Gemfile.lock"
@@ -18,12 +19,12 @@ module BuPr
18
19
 
19
20
  # @return [Boolean]
20
21
  def diff?
21
- `git status`.include?(LOCKFILE)
22
+ `git status`.include? LOCKFILE
22
23
  end
23
24
 
24
25
  # @return [Boolean]
25
26
  def installed?
26
- system("git --help > /dev/null 2>&1")
27
+ system "git --help > /dev/null 2>&1"
27
28
  end
28
29
 
29
30
  def push
@@ -1,43 +1,41 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  require "octokit"
3
4
  require "compare_linker"
4
5
 
5
6
  module BuPr
6
7
  module Handlers
7
8
  class Github
8
- # @return [String] base branch name
9
- attr_reader :base
10
-
11
- # @return [String]
12
- attr_reader :current_branch
13
-
14
- # @return [String]
15
- attr_reader :repo
16
-
17
- # @return [String]
18
- attr_reader :title
19
-
20
- # @return [String]
21
- attr_reader :token
22
-
23
- # @return [CompareLinker]
24
- attr_reader :linker
25
-
26
- # @param attrs [Hash]
27
- def initialize attrs = {}
28
- config = attrs[:config]
29
-
30
- @current_branch = attrs[:current_branch]
9
+ attr_reader :base # @return [String] base branch name
10
+ attr_reader :current # @return [String] current branch
11
+ attr_reader :repo # @return [String]
12
+ attr_reader :title # @return [String]
13
+ attr_reader :token # @return [String]
14
+ attr_reader :linker # @return [CompareLinker]
15
+
16
+ # Entry point
17
+ #
18
+ # @option [BuPr::Configuration] :config
19
+ # @option [String] :current_branch
20
+ def self.call config:, current_branch:
21
+ new(
22
+ config: config,
23
+ current_branch: current_branch
24
+ ).call
25
+ end
31
26
 
32
- @base = config.branch
33
- @repo = config.repo
34
- @title = config.title
35
- @token = config.token
27
+ # @option [BuPr::Configuration] :config
28
+ # @option [String] :current_branch
29
+ def initialize config:, current_branch:
30
+ @current = current_branch
31
+ @base = config.branch
32
+ @repo = config.repo
33
+ @title = config.title
34
+ @token = config.token
36
35
  end
37
36
 
38
37
  def call
39
- number = create_pull_request
40
- diff_comment(number)
38
+ diff_comment create_pull_request
41
39
  end
42
40
 
43
41
  # @return [Integer] pull-request ID
@@ -45,14 +43,15 @@ module BuPr
45
43
  res = client.create_pull_request \
46
44
  repo,
47
45
  base,
48
- current_branch,
46
+ current,
49
47
  title
50
48
 
51
49
  res[:number]
52
50
  end
53
51
 
52
+ # @param pr_number [Integer]
54
53
  def diff_comment pr_number
55
- load_linker(pr_number)
54
+ load_linker pr_number
56
55
  linker.add_comment repo, pr_number, comment_content
57
56
  end
58
57
 
@@ -61,9 +60,7 @@ module BuPr
61
60
  # @private
62
61
  # @return [Octokit::Client]
63
62
  def client
64
- @client ||= ::Octokit::Client.new(
65
- access_token: token,
66
- )
63
+ @client ||= ::Octokit::Client.new access_token: token
67
64
  end
68
65
 
69
66
  # @private
data/lib/bu_pr/runner.rb CHANGED
@@ -1,5 +1,10 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  module BuPr
4
+ # Custom errors
5
+ class RequirementUnfulfilled < StandardError; end
6
+ class InvalidConfigurations < StandardError; end
7
+
3
8
  class Runner
4
9
  class << self
5
10
  # @param opts [Hash]
@@ -9,23 +14,16 @@ module BuPr
9
14
  end
10
15
  end
11
16
 
12
- # @private
13
- # @return [BuPr::Git]
14
- attr_reader :git
15
-
16
- # @private
17
- # @return [BuPr::Configuration]
18
- attr_reader :config
17
+ attr_reader :git # @return [BuPr::Git]
18
+ attr_reader :config # @return [BuPr::Configuration]
19
19
 
20
- # @private
21
20
  # @param opts [Hash]
22
21
  # @see BuPr::Configuration#initialize
23
22
  def initialize opts = {}
24
23
  @git = Git.new
25
- @config = Configuration.new(opts)
24
+ @config = Configuration.new opts
26
25
  end
27
26
 
28
- # @private
29
27
  def call
30
28
  if bundle_update && !git.diff?
31
29
  puts "no update"
@@ -34,28 +32,21 @@ module BuPr
34
32
 
35
33
  git.push
36
34
 
37
- handler = Handlers::Github.new config: config, current_branch: git.current_branch
38
- handler.call
35
+ Handlers::Github.call \
36
+ config: config,
37
+ current_branch: git.current_branch
39
38
  end
40
39
 
41
- # @private
42
40
  # @return [Boolean]
43
41
  def bundle_update
44
42
  valid? && _bundle_update
45
43
  end
46
44
 
47
- # @private
48
45
  # @return [Boolean]
46
+ # @raise [BuPr::InvalidConfigurations]
47
+ # @raise [BuPr::RequirementUnfulfilled]
49
48
  def valid?
50
- unless config.valid?
51
- raise "Invalid configuration"
52
- end
53
-
54
- unless git.installed?
55
- raise "Git is not installed"
56
- end
57
-
58
- true
49
+ check_config! && check_git!
59
50
  end
60
51
 
61
52
  private
@@ -68,5 +59,23 @@ module BuPr
68
59
 
69
60
  raise "Error(s) happened"
70
61
  end
62
+
63
+ # @private
64
+ # @return [Boolean]
65
+ # @raise [BuPr::InvalidConfigurations]
66
+ def check_config!
67
+ return true if config.valid?
68
+
69
+ raise InvalidConfigurations, "Invalid configuration"
70
+ end
71
+
72
+ # @private
73
+ # @return [Boolean]
74
+ # @raise [BuPr::RequirementUnfulfilled]
75
+ def check_git!
76
+ return true if git.installed?
77
+
78
+ raise RequirementUnfulfilled, "Git is not installed"
79
+ end
71
80
  end
72
81
  end
data/lib/bu_pr/version.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  module BuPr
3
- VERSION = "0.5.0"
4
+ VERSION = "0.6.0"
4
5
  end
data/lib/bu_pr.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  require "bu_pr/version"
3
4
  require "bu_pr/configuration"
4
5
  require "bu_pr/git"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bu_pr
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Masaya Myojin
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-04-04 00:00:00.000000000 Z
11
+ date: 2017-05-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: compare_linker
@@ -24,20 +24,6 @@ dependencies:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: 1.1.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'
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'
41
27
  - !ruby/object:Gem::Dependency
42
28
  name: bundler
43
29
  requirement: !ruby/object:Gem::Requirement