bu_pr 0.4.0 → 0.5.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: 8d6a26d015d99b0818e94691d0c9ac8f4ec3e024
4
- data.tar.gz: 42188f7945e7571011501e85fd78fc597211c5f2
3
+ metadata.gz: 151da8efbdea7d8e1f213c389aec5638ada216fb
4
+ data.tar.gz: 8ed0c5664508e90b7eeafa3f2d6830c45d6c8f17
5
5
  SHA512:
6
- metadata.gz: ff2ac1be3f65db5a20da3a878686ee416b45a435bf4a66db2bdd48e08582d51a92f43c82a82bfcaa4af6261ef54b1497abea2ddcf36b7ee2cdd2bbb53693e074
7
- data.tar.gz: 6c28f0f2a9bc0fcf6849c047bb00a072a3a89f85b139c0802ae4764e384de79a8cc284c06c612cf31c90078d19f3aeb0ef132772272a6b77033fb18d63b13bc7
6
+ metadata.gz: 57c0c8693900ff6b9ddb68eac293fd47d9927d02f758a8246b8922e0706f01407c672fd656d98740e21ba91ffe62f0dd7571a8ec67a8870cb99230f4c38c11d5
7
+ data.tar.gz: 253564184b645a6f4cbdffbc1387275794bea5f788ffe438259368e78e8cf178a429a1aebd9c2bf98a9692255a4f801b4d4a1cda997e8ec0406943d138d2db6f
data/README.md CHANGED
@@ -22,67 +22,33 @@ Or install it yourself as:
22
22
 
23
23
  ## Usage
24
24
 
25
- Get Github access token from [this page](https://github.com/settings/tokens/new) with `repo` scope.
25
+ Get GitHub access token from [this page](https://github.com/settings/tokens/new) with `repo` scope.
26
26
 
27
+ then run
27
28
 
28
- ### Set configuration values as Environment variables.
29
+ ```sh
30
+ $ bundle exec bu_pr --repo=mmyoji/bu_pr --token=<the token you got above>
31
+ ```
32
+
33
+ or you can just set `repo` and `token` values in your `$HOME/.profile` file.
29
34
 
30
35
  ```sh
31
36
  # .bash_profile / .profile / .zshrc / etc.
32
37
 
33
38
  export BUPR_TOKEN="xxx"
34
39
  export BUPR_REPO="mmyoji/bu_pr"
40
+
41
+ # If you wanna override them:
35
42
  # export BUPR_BRANCH="develop"
36
43
  # export BUPR_TITLE="My bundle update"
37
44
  ```
38
45
 
46
+ ### Available options
39
47
 
40
- ### Set configuration values in config file.
41
-
42
- ```rb
43
- require 'bu_pr'
44
-
45
- # Setup
46
- BuPr.configure do |config|
47
- config.token = "xxx" # Required
48
- config.repo = "mmyoji/bu_pr" # Required
49
-
50
- config.branch = "develop" # Optional :: default is 'master'
51
- config.title = "My bundle update" # Optional :: default is like 'Bundle update 2016-11-13'
52
- end
53
-
54
- BuPr::Runner.call
55
- ```
56
-
57
- ### Rails
58
-
59
- ```rb
60
- # config/initializers/bu_pr.rb
61
-
62
- BuPr.configure do |config|
63
- config.token = "xxx"
64
- config.repo = "mmyoji/bu_pr"
65
- end
66
- ```
67
-
68
- then run the following commands
69
-
70
- ```sh
71
- # Run all tasks
72
- $ bin/rake bu_pr:all
73
-
74
- # If you want to execute each task,
75
-
76
- # Run `bundle update` only
77
- $ bin/rake bu_pr:bu
78
-
79
- # Create pull-request
80
- $ bin/rake bu_pr:pr
81
-
82
- # Add gem diff comment
83
- $ bin/rake bu_pr:diff
84
- ```
85
-
48
+ * branch: base branch name for the pull-request. Default is `master`
49
+ * repo: your github repository name
50
+ * title: the pull-request title. Default is `Bundle update 2017-04-04`
51
+ * token: your GitHub access token
86
52
 
87
53
  ## Contributing
88
54
 
data/bu_pr.gemspec CHANGED
@@ -22,6 +22,7 @@ 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"
25
26
 
26
27
  spec.add_development_dependency "bundler", "~> 1.13"
27
28
  spec.add_development_dependency "rake", "~> 10.0"
data/exe/bu_pr ADDED
@@ -0,0 +1,9 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ $LOAD_PATH.unshift File.expand_path("../../lib", __FILE__)
5
+
6
+ require "bundler/setup"
7
+ require "bu_pr"
8
+
9
+ BuPr::Command.start(ARGV)
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+ require "thor"
3
+
4
+ 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)
17
+ end
18
+ end
19
+ end
@@ -1,55 +1,48 @@
1
1
  # frozen_string_literal: true
2
- require 'singleton'
3
-
4
2
  module BuPr
5
3
  class Configuration
6
- include Singleton
7
-
8
- attr_accessor(
9
- :branch,
10
- :title,
11
- :token,
12
- :repo,
4
+ ATTRS = %i(
5
+ branch
6
+ title
7
+ token
8
+ repo
13
9
  )
14
10
 
15
- # DEPRECATED
16
- alias access_token token
17
- alias access_token= token=
18
- alias base_branch branch
19
- alias base_branch= branch=
20
- alias pr_title title
21
- alias pr_title= title=
22
- alias repo_name repo
23
- alias repo_name= repo=
11
+ # @return [String]
12
+ attr_accessor(*ATTRS)
24
13
 
25
- def initialize
26
- @branch = ENV.fetch("BUPR_BRANCH") { "master" }
27
- @title = ENV.fetch("BUPR_TITLE") { "Bundle update #{Time.now.strftime('%F')}" }
14
+ # @param opts [Hash]
15
+ # @option opts [String] :branch Base branch name
16
+ # @option opts [String] :title pull-request title
17
+ # @option opts [String] :token GitHub access token
18
+ # @option opts [String] :repo GitHub repository name
19
+ def initialize opts = {}
20
+ @branch = opts.fetch(:branch) { ENV.fetch("BUPR_BRANCH") { "master" } }
21
+ @title = opts.fetch(:title) { ENV.fetch("BUPR_TITLE") { default_title } }
28
22
 
29
- @token = ENV["BUPR_TOKEN"]
30
- @repo = ENV["BUPR_REPO"]
23
+ @token = opts.fetch(:token) { ENV["BUPR_TOKEN"] }
24
+ @repo = opts.fetch(:repo) { ENV["BUPR_REPO"] }
31
25
  end
32
26
 
27
+ # @return [Boolean]
33
28
  def valid?
34
29
  token? && branch? && title? && repo?
35
30
  end
36
31
 
37
32
  private
38
33
 
39
- def token?
40
- token && token != ""
41
- end
42
-
43
- def branch?
44
- branch && branch != ""
45
- end
46
-
47
- def title?
48
- title && title != ""
34
+ ATTRS.each do |attr|
35
+ # @private
36
+ define_method "#{attr}?" do
37
+ v = public_send(attr)
38
+ !v.nil? && v != ""
39
+ end
49
40
  end
50
41
 
51
- def repo?
52
- repo && repo != ""
42
+ # @private
43
+ # @return [String]
44
+ def default_title
45
+ "Bundle update #{Time.now.strftime('%F')}"
53
46
  end
54
47
  end
55
48
  end
data/lib/bu_pr/git.rb CHANGED
@@ -1,9 +1,9 @@
1
1
  # frozen_string_literal: true
2
-
3
2
  module BuPr
4
3
  class Git
5
4
  LOCKFILE = "Gemfile.lock"
6
5
 
6
+ # @return [String]
7
7
  def current_branch
8
8
  @current_branch ||=
9
9
  begin
@@ -16,10 +16,12 @@ module BuPr
16
16
  end
17
17
  end
18
18
 
19
+ # @return [Boolean]
19
20
  def diff?
20
21
  `git status`.include?(LOCKFILE)
21
22
  end
22
23
 
24
+ # @return [Boolean]
23
25
  def installed?
24
26
  system("git --help > /dev/null 2>&1")
25
27
  end
@@ -30,18 +32,22 @@ module BuPr
30
32
 
31
33
  private
32
34
 
35
+ # @private
33
36
  def add
34
37
  `git add #{LOCKFILE}`
35
38
  end
36
39
 
40
+ # @private
37
41
  def branches
38
42
  `git branch`.strip
39
43
  end
40
44
 
45
+ # @private
41
46
  def commit
42
47
  `git commit -m "bundle update"`
43
48
  end
44
49
 
50
+ # @private
45
51
  def _push
46
52
  `git push origin #{current_branch}`
47
53
  end
@@ -1,18 +1,29 @@
1
1
  # frozen_string_literal: true
2
-
3
2
  require "octokit"
4
3
  require "compare_linker"
5
4
 
6
5
  module BuPr
7
6
  module Handlers
8
7
  class Github
8
+ # @return [String] base branch name
9
9
  attr_reader :base
10
+
11
+ # @return [String]
10
12
  attr_reader :current_branch
13
+
14
+ # @return [String]
11
15
  attr_reader :repo
16
+
17
+ # @return [String]
12
18
  attr_reader :title
19
+
20
+ # @return [String]
13
21
  attr_reader :token
22
+
23
+ # @return [CompareLinker]
14
24
  attr_reader :linker
15
25
 
26
+ # @param attrs [Hash]
16
27
  def initialize attrs = {}
17
28
  config = attrs[:config]
18
29
 
@@ -29,6 +40,7 @@ module BuPr
29
40
  diff_comment(number)
30
41
  end
31
42
 
43
+ # @return [Integer] pull-request ID
32
44
  def create_pull_request
33
45
  res = client.create_pull_request \
34
46
  repo,
@@ -46,16 +58,22 @@ module BuPr
46
58
 
47
59
  private
48
60
 
61
+ # @private
62
+ # @return [Octokit::Client]
49
63
  def client
50
64
  @client ||= ::Octokit::Client.new(
51
65
  access_token: token,
52
66
  )
53
67
  end
54
68
 
69
+ # @private
70
+ # @return [String]
55
71
  def comment_content
56
72
  "#{linker.make_compare_links.to_a.join("\n")}"
57
73
  end
58
74
 
75
+ # @private
76
+ # @return [CompareLinker]
59
77
  def load_linker pr_number
60
78
  ENV['OCTOKIT_ACCESS_TOKEN'] = token
61
79
 
data/lib/bu_pr/runner.rb CHANGED
@@ -1,29 +1,35 @@
1
1
  # frozen_string_literal: true
2
-
3
2
  module BuPr
4
3
  class Runner
5
4
  class << self
6
- attr_writer :config
7
-
8
- def config
9
- @config ||= Configuration.instance
10
- end
11
-
12
- def call
13
- new.call
5
+ # @param opts [Hash]
6
+ # @see BuPr::Configuration#initialize
7
+ def call opts = {}
8
+ new(opts).call
14
9
  end
15
10
  end
16
11
 
12
+ # @private
13
+ # @return [BuPr::Git]
17
14
  attr_reader :git
18
15
 
19
- def initialize
20
- @git = Git.new
16
+ # @private
17
+ # @return [BuPr::Configuration]
18
+ attr_reader :config
19
+
20
+ # @private
21
+ # @param opts [Hash]
22
+ # @see BuPr::Configuration#initialize
23
+ def initialize opts = {}
24
+ @git = Git.new
25
+ @config = Configuration.new(opts)
21
26
  end
22
27
 
28
+ # @private
23
29
  def call
24
30
  if bundle_update && !git.diff?
25
31
  puts "no update"
26
- exit
32
+ return
27
33
  end
28
34
 
29
35
  git.push
@@ -32,14 +38,14 @@ module BuPr
32
38
  handler.call
33
39
  end
34
40
 
41
+ # @private
42
+ # @return [Boolean]
35
43
  def bundle_update
36
44
  valid? && _bundle_update
37
45
  end
38
46
 
39
- def config
40
- self.class.config
41
- end
42
-
47
+ # @private
48
+ # @return [Boolean]
43
49
  def valid?
44
50
  unless config.valid?
45
51
  raise "Invalid configuration"
@@ -54,6 +60,9 @@ module BuPr
54
60
 
55
61
  private
56
62
 
63
+ # @private
64
+ # @return [Boolean]
65
+ # @raise RuntimeError
57
66
  def _bundle_update
58
67
  return true if system("bundle update")
59
68
 
data/lib/bu_pr/version.rb CHANGED
@@ -1,5 +1,4 @@
1
1
  # frozen_string_literal: true
2
-
3
2
  module BuPr
4
- VERSION = "0.4.0"
3
+ VERSION = "0.5.0"
5
4
  end
data/lib/bu_pr.rb CHANGED
@@ -4,14 +4,4 @@ require "bu_pr/configuration"
4
4
  require "bu_pr/git"
5
5
  require "bu_pr/handlers/github"
6
6
  require "bu_pr/runner"
7
- require "bu_pr/railtie" if defined?(Rails::Railtie)
8
-
9
- module BuPr
10
- def configure
11
- conf = Configuration.instance
12
- yield conf
13
-
14
- Runner.config = conf
15
- end
16
- module_function :configure
17
- end
7
+ require "bu_pr/command"
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.4.0
4
+ version: 0.5.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-02-14 00:00:00.000000000 Z
11
+ date: 2017-04-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: compare_linker
@@ -24,6 +24,20 @@ 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'
27
41
  - !ruby/object:Gem::Dependency
28
42
  name: bundler
29
43
  requirement: !ruby/object:Gem::Requirement
@@ -69,7 +83,8 @@ dependencies:
69
83
  description: BuPr is simple pull request creator for the daily bundle update.
70
84
  email:
71
85
  - m.myojin0425@gmail.com
72
- executables: []
86
+ executables:
87
+ - bu_pr
73
88
  extensions: []
74
89
  extra_rdoc_files: []
75
90
  files:
@@ -84,13 +99,13 @@ files:
84
99
  - bin/console
85
100
  - bin/setup
86
101
  - bu_pr.gemspec
102
+ - exe/bu_pr
87
103
  - lib/bu_pr.rb
104
+ - lib/bu_pr/command.rb
88
105
  - lib/bu_pr/configuration.rb
89
106
  - lib/bu_pr/git.rb
90
107
  - lib/bu_pr/handlers/github.rb
91
- - lib/bu_pr/railtie.rb
92
108
  - lib/bu_pr/runner.rb
93
- - lib/bu_pr/tasks/bu_pr.rake
94
109
  - lib/bu_pr/version.rb
95
110
  homepage: https://github.com/mmyoji/bu_pr
96
111
  licenses:
@@ -112,7 +127,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
112
127
  version: '0'
113
128
  requirements: []
114
129
  rubyforge_project:
115
- rubygems_version: 2.5.2
130
+ rubygems_version: 2.6.11
116
131
  signing_key:
117
132
  specification_version: 4
118
133
  summary: Simple bundle update p-r creator
data/lib/bu_pr/railtie.rb DELETED
@@ -1,9 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module BuPr
4
- class Railtie < ::Rails::Railtie
5
- rake_tasks do
6
- load "bu_pr/tasks/bu_pr.rake"
7
- end
8
- end
9
- end
@@ -1,45 +0,0 @@
1
- namespace :bu_pr do
2
- desc "Run `bundle update`"
3
- task bu: :environment do
4
- puts "Running `bundle update`..."
5
-
6
- BuPr::Runner.new.bundle_update
7
-
8
- puts "Finished `bundle update`"
9
- end
10
-
11
- desc "Create pull-request"
12
- task pr: :environment do
13
- puts "Creating pull-request..."
14
-
15
- r = BuPr::Runner.new
16
- handler = BuPr::Handlers::Github.new \
17
- config: r.config,
18
- current_branch: r.git.current_branch
19
-
20
- pr_number = handler.create_pull_request
21
-
22
- puts "Finished: p-r number is `#{pr_number}`"
23
- end
24
-
25
- desc "Add gem diff comment"
26
- task diff: :environment do
27
- pr_number = ENV.fetch("PR_NUMBER")
28
-
29
- puts "Commenting..."
30
-
31
- r = BuPr::Runner.new
32
- handler = BuPr::Handlers::Github.new \
33
- config: r.config,
34
- current_branch: r.git.current_branch
35
-
36
- handler.diff_comment(pr_number)
37
-
38
- puts "Finished!"
39
- end
40
-
41
- desc "Run bu_pr all tasks"
42
- task all: :environment do
43
- BuPr::Runner.call
44
- end
45
- end