lock_diff 0.3.2 → 0.3.3

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
  SHA1:
3
- metadata.gz: 62f3acde4a4b8060e7ea1f0a7f94c08b0421fc1a
4
- data.tar.gz: e3034100548febc98058c904a524a9ef2a676c0f
3
+ metadata.gz: 40bb372ad385170936087d91ee3530cc75afb6c6
4
+ data.tar.gz: ce08c865a51232770c210585ff789e98e95e843f
5
5
  SHA512:
6
- metadata.gz: d5b2b5642151f83868aa4bee2a90350f2dac4e553cde9091623347100336d0ea607d544f1b82aafae7cce5f82435f9d8df0c40ff804f724a964f5293e3877c73
7
- data.tar.gz: 854c946249bb76873b9ee121bf719b32bc28df589bed32bb7a11adf8f1ee2e35d6ec70357abc1853749e3a766232d8774ff91a985b15334eea1ef4cc15216a5c
6
+ metadata.gz: 89509ad3d40bc26f45206f999d323ccf20dc76ebbc4dbfdc46a865beb572c8c6c9426f6c954a06fb90e1a60f7ea8e174ca8d960d596f9e3768bb170347eb4098
7
+ data.tar.gz: 416e18c67a7cf82ea5ea59fae3c3f393461b1fbe0ff3fd3920bb7e9bcffacfaa3aafff3a01819b64ad7d77d19d52e532a6e2e68891483261e31382c7829943bd
data/README.md CHANGED
@@ -114,6 +114,36 @@ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERN
114
114
 
115
115
  The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
116
116
 
117
+ ### Original
118
+
119
+ Most source code in this pepository is by https://github.com/kyanny/compare_linker .
120
+
121
+ ```
122
+ Copyright (c) 2014 Kensuke Nagae
123
+
124
+ MIT License
125
+
126
+ Permission is hereby granted, free of charge, to any person obtaining
127
+ a copy of this software and associated documentation files (the
128
+ "Software"), to deal in the Software without restriction, including
129
+ without limitation the rights to use, copy, modify, merge, publish,
130
+ distribute, sublicense, and/or sell copies of the Software, and to
131
+ permit persons to whom the Software is furnished to do so, subject to
132
+ the following conditions:
133
+
134
+ The above copyright notice and this permission notice shall be
135
+ included in all copies or substantial portions of the Software.
136
+
137
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
138
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
139
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
140
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
141
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
142
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
143
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
144
+ ```
145
+
146
+
117
147
  ## Code of Conduct
118
148
 
119
149
  Everyone interacting in the LockDiff project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/lock_diff/blob/master/CODE_OF_CONDUCT.md).
data/exe/lock_diff CHANGED
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
3
  require "lock_diff"
4
- require "lock_diff/option_parser"
4
+ require "lock_diff/cli/option_parser"
5
5
 
6
- options = LockDiff::OptionParser.parse(ARGV, require_flags: %i(repository number))
6
+ options = LockDiff::Cli::OptionParser.parse(ARGV, require_flags: %i(repository number))
7
7
  LockDiff.run(options)
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
3
  require "lock_diff"
4
- require "lock_diff/option_parser"
4
+ require "lock_diff/cli/option_parser"
5
5
 
6
- options = LockDiff::OptionParser.parse(ARGV, require_flags: %i(repository))
6
+ options = LockDiff::Cli::OptionParser.parse(ARGV, require_flags: %i(repository))
7
7
  LockDiff.run_by_latest_tachikoma(options)
@@ -0,0 +1,50 @@
1
+ require "optparse"
2
+
3
+ module LockDiff
4
+ module Cli
5
+ class OptionParser
6
+ class << self
7
+ def parse(args, require_flags:)
8
+ new(require_flags).parse(args)
9
+ end
10
+ end
11
+
12
+ def initialize(require_flags)
13
+ @require_flags = require_flags
14
+ end
15
+
16
+ def parse(args)
17
+ options = {
18
+ post_comment: false
19
+ }
20
+ opt = ::OptionParser.new
21
+
22
+ opt.separator("Require flags")
23
+ if @require_flags.include? :repository
24
+ opt.on('-r', '--repository=REPOSITORY', 'Like as "user/repository"') { |v| options[:repository] = v }
25
+ end
26
+ if @require_flags.include? :number
27
+ opt.on('-n', '--number=PULL_REQUEST_NUMBER') { |v| options[:number] = v }
28
+ end
29
+
30
+ opt.separator("\nOptional flags")
31
+ opt.on('--post-comment=true or false', 'Print result to stdout when false. (default is false)') { |v| options[:post_comment] = v }
32
+ opt.on("-v", "--verbose", "Run verbosely") { LockDiff.logger.level = :info }
33
+ opt.on("--more-verbose", "Run more verbosely") { LockDiff.logger.level = :debug }
34
+ opt.on_tail("--version", "Show version") do
35
+ $stdout.puts LockDiff::VERSION
36
+ exit
37
+ end
38
+ opt.parse!(args)
39
+
40
+ if @require_flags.all? { |flag| options.has_key?(flag) }
41
+ options
42
+ else
43
+ $stdout.puts opt.help
44
+ exit
45
+ end
46
+ end
47
+
48
+ end
49
+ end
50
+ end
@@ -8,7 +8,8 @@ module LockDiff
8
8
  NEW = 'new'
9
9
 
10
10
  attr_reader :old_package, :new_package
11
- def_delegators :package, :name, :url
11
+ def_delegators :package, :name, :repository_url
12
+ def_delegator :package, :url, :package_url
12
13
 
13
14
  def initialize(old_package:, new_package:)
14
15
  @old_package = old_package
@@ -68,7 +69,7 @@ module LockDiff
68
69
 
69
70
  Github::ChangelogUrlFinder.new(
70
71
  repository: package.repository,
71
- github_url: package.github_url,
72
+ repository_url: package.repository_url,
72
73
  ref: ref
73
74
  ).call
74
75
  end
@@ -79,7 +80,7 @@ module LockDiff
79
80
  end
80
81
 
81
82
  def commits_url
82
- return unless package.github_url
83
+ return unless package.repository_url
83
84
  old_ref = @old_package.ref
84
85
  new_ref = @new_package.ref
85
86
  commits_url =
@@ -94,7 +95,7 @@ module LockDiff
94
95
  "commits/#{new_ref}" if new_ref
95
96
  end
96
97
 
97
- "#{package.github_url}/#{commits_url}" if commits_url
98
+ "#{package.repository_url}/#{commits_url}" if commits_url
98
99
  end
99
100
 
100
101
  def commits_url_text
@@ -18,8 +18,8 @@ module LockDiff
18
18
 
19
19
  def headers
20
20
  [
21
- "| name | status | commits | changelog |",
22
- "|------|--------|---------|-----------|"
21
+ "| package | repo | status | commits | changelog |",
22
+ "|---------|:----:|:------:|---------|-----------|"
23
23
  ]
24
24
  end
25
25
 
@@ -35,7 +35,8 @@ module LockDiff
35
35
 
36
36
  def call
37
37
  text = []
38
- text << name
38
+ text << package
39
+ text << repository
39
40
  text << status
40
41
  text << commits_text
41
42
  text << changelog
@@ -50,14 +51,22 @@ module LockDiff
50
51
  diff_info.status_emoji
51
52
  end
52
53
 
53
- def name
54
- if diff_info.url
55
- "[#{diff_info.name}](#{diff_info.url})"
54
+ def package
55
+ if diff_info.package_url
56
+ "[#{diff_info.name}](#{diff_info.package_url})"
56
57
  else
57
58
  diff_info.name
58
59
  end
59
60
  end
60
61
 
62
+ def repository
63
+ if diff_info.repository_url
64
+ "[:octocat:](#{diff_info.repository_url})"
65
+ else
66
+ ''
67
+ end
68
+ end
69
+
61
70
  def commits_text
62
71
  if diff_info.commits_url
63
72
  "[#{diff_info.commits_url_text}](#{diff_info.commits_url})"
@@ -1,13 +1,6 @@
1
1
  module LockDiff
2
2
  module Gem
3
3
  class LockfileComparator
4
- def self.compare_by(pr_gemfile_lock)
5
- new(
6
- old_lockfile: pr_gemfile_lock.base_file,
7
- new_lockfile: pr_gemfile_lock.head_file
8
- ).call
9
- end
10
-
11
4
  def initialize(old_lockfile:, new_lockfile:)
12
5
  @old_lockfile = old_lockfile
13
6
  @new_lockfile = new_lockfile
@@ -3,7 +3,8 @@ module LockDiff
3
3
  class Package
4
4
  extend Forwardable
5
5
 
6
- def_delegators :@spec, :name, :revision, :version, :github_url
6
+ def_delegators :@spec, :name, :revision, :version, :repository_url
7
+ def_delegator :@spec, :ruby_gem_url, :url
7
8
 
8
9
  def initialize(spec)
9
10
  @spec = spec
@@ -21,23 +22,19 @@ module LockDiff
21
22
  revision != other.revision || version != other.version
22
23
  end
23
24
 
24
- def url
25
- @spec.github_url || @spec.homepage_url
26
- end
27
-
28
25
  def repository
29
- Github::RepositoryNameDetector.new(@spec.github_url).call
26
+ @repository ||= Github::RepositoryNameDetector.new(@spec.repository_url).call
30
27
  end
31
28
 
32
29
  private
33
30
 
34
31
  def git_tag
35
- return unless version
32
+ return unless version && repository
36
33
  return @git_tag if defined? @git_tag
37
34
  @git_tag = Github::TagFinder.new(
38
35
  repository: repository,
39
36
  package_name: name,
40
- version_str: version.to_s
37
+ version: version
41
38
  ).call
42
39
  end
43
40
 
@@ -9,27 +9,49 @@ module LockDiff
9
9
  extend Forwardable
10
10
 
11
11
  def initialize(name)
12
- content = HTTPClient.get_content("https://rubygems.org/api/v1/gems/#{name}.json")
13
- @ruby_gem = OpenStruct.new(JSON.parse(content))
14
- rescue => e
15
- LockDiff.logger.warn("Could not fetch gem info of #{name} because of #{e.inspect}")
16
- @ruby_gem = NullRubyGem.new(name)
12
+ @ruby_gem = Repository.find(name)
17
13
  end
18
14
 
19
- def github_url
20
- @github_url ||= Github::GithubUrlDetector.new([source_code_url, homepage_url]).call
15
+ def repository_url
16
+ @repository_url ||= Github::UrlDetector.new([source_code_url, homepage_url]).call
21
17
  end
22
18
 
23
19
  def homepage_url
24
20
  @ruby_gem.homepage_uri
25
21
  end
26
22
 
23
+ def url
24
+ @ruby_gem.project_uri
25
+ end
26
+
27
27
  private
28
28
 
29
29
  def source_code_url
30
30
  @ruby_gem.source_code_uri
31
31
  end
32
32
 
33
+ class Repository
34
+ class << self
35
+ def find(name)
36
+ ruby_gem = repository[name]
37
+ return ruby_gem if ruby_gem
38
+ repository[name] = fetch(name)
39
+ end
40
+
41
+ def fetch(name)
42
+ content = HTTPClient.get_content("https://rubygems.org/api/v1/gems/#{name}.json")
43
+ OpenStruct.new(JSON.parse(content))
44
+ rescue => e
45
+ LockDiff.logger.warn("Could not fetch gem info of #{name} because of #{e.inspect}")
46
+ NullRubyGem.new(name)
47
+ end
48
+
49
+ def repository
50
+ @repository ||= {}
51
+ end
52
+ end
53
+ end
54
+
33
55
  end
34
56
 
35
57
  class NullRubyGem
@@ -43,6 +65,9 @@ module LockDiff
43
65
  def source_code_uri
44
66
  end
45
67
 
68
+ def project_uri
69
+ end
70
+
46
71
  end
47
72
  end
48
73
  end
@@ -36,23 +36,25 @@ module LockDiff
36
36
  Package.new(self)
37
37
  end
38
38
 
39
- def github_url; end
39
+ def repository_url; end
40
40
  def homepage_url; end
41
+ def ruby_gem_url; end
41
42
  end
42
43
 
43
44
  class RubyGemSpec < Base
44
- def_delegators :ruby_gem, :github_url, :homepage_url
45
+ def_delegators :ruby_gem, :repository_url, :homepage_url
46
+ def_delegator :ruby_gem, :url, :ruby_gem_url
45
47
 
46
48
  private
47
49
 
48
50
  def ruby_gem
49
- @ruby_gem ||= RubyGemRepository.find(@spec.name)
51
+ @ruby_gem ||= RubyGem.new(@spec.name)
50
52
  end
51
53
  end
52
54
 
53
55
  class GitSpec < Base
54
- def github_url
55
- @github_url ||= Github::GithubUrlDetector.new(@spec.source.uri).call
56
+ def repository_url
57
+ @repository_url ||= Github::UrlDetector.new(@spec.source.uri).call
56
58
  end
57
59
  end
58
60
 
@@ -74,8 +76,9 @@ module LockDiff
74
76
  nil
75
77
  end
76
78
 
77
- def github_url; end
79
+ def repository_url; end
78
80
  def homepage_url; end
81
+ def ruby_gem_url; end
79
82
 
80
83
  def to_package
81
84
  Package.new(self)
data/lib/lock_diff/gem.rb CHANGED
@@ -2,20 +2,18 @@ require "bundler"
2
2
  require_relative "gem/lockfile_comparator"
3
3
  require_relative "gem/package"
4
4
  require_relative "gem/ruby_gem"
5
- require_relative "gem/ruby_gem_repository"
6
5
  require_relative "gem/spec"
7
6
 
8
7
  module LockDiff
9
8
  module Gem
10
9
  class << self
11
- class NotChangedLockfile < StandardError; end
12
-
13
- def lock_file_diffs(pull_request)
14
- pr_lockfile = Github::PrLockfile.new(pull_request, 'Gemfile.lock')
15
- raise NotChangedLockfile unless pr_lockfile.changed?
16
- LockfileComparator.compare_by(pr_lockfile)
10
+ def lockfile_name
11
+ 'Gemfile.lock'
17
12
  end
18
13
 
14
+ def lockfile_comparator
15
+ LockfileComparator
16
+ end
19
17
  end
20
18
  end
21
19
  end
@@ -10,9 +10,9 @@ module LockDiff
10
10
  news
11
11
  )
12
12
 
13
- def initialize(repository:, github_url:, ref:)
13
+ def initialize(repository:, repository_url:, ref:)
14
14
  @repository = repository
15
- @github_url = github_url
15
+ @repository_url = repository_url
16
16
  @ref = ref
17
17
  end
18
18
 
@@ -32,9 +32,9 @@ module LockDiff
32
32
  end
33
33
 
34
34
  def find_release_url
35
- return unless @github_url
35
+ return unless @repository_url
36
36
  unless Github.client.exist_releases?(@repository)
37
- @github_url + "/releases"
37
+ @repository_url + "/releases"
38
38
  end
39
39
  end
40
40
 
@@ -24,7 +24,7 @@ module LockDiff
24
24
  Github::PullRequest.new(@client.pull_request(repository, number))
25
25
  end
26
26
 
27
- def latest_pull_request(repository)
27
+ def newer_pull_requests(repository)
28
28
  @client.pull_requests(repository).
29
29
  map { |pull_request| Github::PullRequest.new(pull_request) }
30
30
  end
@@ -6,14 +6,6 @@ module LockDiff
6
6
  @pr = pull_request
7
7
  end
8
8
 
9
- def base_sha
10
- @pr.base.sha
11
- end
12
-
13
- def head_sha
14
- @pr.head.sha
15
- end
16
-
17
9
  def base_ref
18
10
  @pr.base.ref
19
11
  end
@@ -25,6 +17,26 @@ module LockDiff
25
17
  def number
26
18
  @pr.number
27
19
  end
20
+
21
+ def repository
22
+ @pr.base.repo.full_name
23
+ end
24
+
25
+ def find_content_path(file_name)
26
+ Github.client.pull_request_content_path(repository, number, file_name)
27
+ end
28
+
29
+ def add_comment(comment)
30
+ Github.client.add_comment(repository, number, comment)
31
+ end
32
+
33
+ def base_file(path)
34
+ Github.client.file(repository, path: path, ref: @pr.base.sha)
35
+ end
36
+
37
+ def head_file(path)
38
+ Github.client.file(repository, path: path, ref: @pr.head.sha)
39
+ end
28
40
  end
29
41
  end
30
42
  end
@@ -1,10 +1,10 @@
1
1
  module LockDiff
2
2
  module Github
3
3
  class TagFinder
4
- def initialize(repository:, package_name:, version_str:)
4
+ def initialize(repository:, package_name:, version:)
5
5
  @repository = repository
6
6
  @package_name = package_name
7
- @version_str = version_str
7
+ @version_str = version.to_s
8
8
  end
9
9
 
10
10
  def call
@@ -16,19 +16,41 @@ module LockDiff
16
16
  def find_tag(page: 1, limit:, per_page:)
17
17
  return nil if page > limit
18
18
 
19
- fetched_tags = LockDiff.client.tag_names(@repository, page: page, per_page: per_page)
20
- tag = fetched_tags.find do |tag_name|
21
- tag_name == @version_str ||
22
- tag_name == "v#{@version_str}" ||
23
- tag_name == "#{@package_name}-#{@version_str}"
19
+ fetched_tags = TagsRepository.find(@repository, page: page, per_page: per_page)
20
+ tag = fetched_tags.find { |tag_name| match_rule?(tag_name) }
21
+
22
+ return tag if tag
23
+
24
+ unless fetched_tags.count < per_page
25
+ find_tag(page: page + 1, limit: limit, per_page: per_page)
24
26
  end
27
+ end
28
+
29
+ def match_rule?(tag_name)
30
+ [
31
+ @version_str,
32
+ "v#{@version_str}",
33
+ "#{@package_name}-#{@version_str}",
34
+ "#{@package_name.downcase}-#{@version_str}"
35
+ ].include?(tag_name)
36
+ end
37
+
38
+ class TagsRepository
39
+ class << self
40
+ def find(repo_name, options = {})
41
+ key = "#{repo_name}-#{options[:page]}"
42
+ ruby_gem = repository[key]
43
+ return ruby_gem if repository.has_key?(key)
44
+ repository[key] = fetch(repo_name, options)
45
+ end
46
+
47
+ def fetch(repo_name, options = {})
48
+ LockDiff.logger.debug { "Fetch tags #{repo_name}, #{options}"}
49
+ Github.client.tag_names(repo_name, options)
50
+ end
25
51
 
26
- if tag
27
- return tag
28
- else
29
- LockDiff.logger.debug { "Not found tag of #{@package_name}, #{@version_str} by page: #{page}, per_page: #{per_page}"}
30
- unless fetched_tags.count < per_page
31
- find_tag(page: page + 1, limit: limit, per_page: per_page)
52
+ def repository
53
+ @repository ||= {}
32
54
  end
33
55
  end
34
56
  end
@@ -2,7 +2,7 @@ require "httpclient"
2
2
 
3
3
  module LockDiff
4
4
  module Github
5
- class GithubUrlDetector
5
+ class UrlDetector
6
6
  # xxx.github.aaa/yyyy
7
7
  REGEXP = %r!https?://([^/]+)\.github\.[^/]+/([^/]+)!
8
8
 
@@ -2,8 +2,7 @@ require_relative "github/access_token"
2
2
  require_relative "github/changelog_url_finder"
3
3
  require_relative "github/client"
4
4
  require_relative "github/content"
5
- require_relative "github/github_url_detector"
6
- require_relative "github/pr_lockfile"
5
+ require_relative "github/url_detector"
7
6
  require_relative "github/pull_request"
8
7
  require_relative "github/repository_name_detector"
9
8
  require_relative "github/tag_finder"
@@ -0,0 +1,19 @@
1
+ module LockDiff
2
+ class LockfileComparator
3
+ class << self
4
+ def compare_by(pull_request)
5
+ file_path = pull_request.find_content_path(lockfile_name)
6
+ raise NotChangedLockfile unless !!file_path
7
+
8
+ LockDiff.config.strategy.lockfile_comparator.new(
9
+ old_lockfile: pull_request.base_file(file_path),
10
+ new_lockfile: pull_request.head_file(file_path)
11
+ ).call
12
+ end
13
+
14
+ def lockfile_name
15
+ LockDiff.config.strategy.lockfile_name
16
+ end
17
+ end
18
+ end
19
+ end
@@ -1,29 +1,28 @@
1
1
  module LockDiff
2
2
  class PullRequest
3
- attr_reader :repository, :number
3
+ extend Forwardable
4
4
 
5
- class NotFoundPullRequest < StandardError; end
5
+ class << self
6
+ class NotChangedLockfile < StandardError; end
6
7
 
7
- def initialize(repository:, number:)
8
- @repository = repository
9
- @number = number
10
- @pr = LockDiff.client.pull_request(repository, number)
11
- rescue => e
12
- message = "Not found pull request by (repository: #{repository}, number: #{number}, client: #{LockDiff.client.class}). Becase of #{e.inspect}"
13
- LockDiff.logger.warn(message)
14
- raise NotFoundPullRequest.new(message)
15
- end
8
+ def find_by(repository:, number:)
9
+ client.pull_request(repository, number)
10
+ rescue => e
11
+ message = "Not found pull request by (repository: #{repository}, number: #{number}, client: #{LockDiff.client.class}). Becase of #{e.inspect}"
12
+ LockDiff.logger.warn(message)
13
+ raise NotFoundPullRequest.new(message)
14
+ end
16
15
 
17
- def base_sha
18
- @pr.base_sha
19
- end
16
+ def latest_by_tachikoma(repository)
17
+ client.newer_pull_requests(repository).
18
+ find { |pull_request| pull_request.head_ref.include?("tachikoma") }
19
+ end
20
20
 
21
- def head_sha
22
- @pr.head_sha
23
- end
21
+ private
24
22
 
25
- def find_content_path(file_name)
26
- LockDiff.client.pull_request_content_path(@repository, @number, file_name)
23
+ def client
24
+ LockDiff.config.pr_repository_service.client
25
+ end
27
26
  end
28
27
 
29
28
  end
@@ -1,3 +1,3 @@
1
1
  module LockDiff
2
- VERSION = "0.3.2"
2
+ VERSION = "0.3.3"
3
3
  end
data/lib/lock_diff.rb CHANGED
@@ -5,6 +5,7 @@ require "lock_diff/diff_info"
5
5
  require "lock_diff/formatter/github_markdown"
6
6
  require "lock_diff/gem"
7
7
  require "lock_diff/github"
8
+ require "lock_diff/lockfile_comparator"
8
9
  require "lock_diff/pull_request"
9
10
  require "lock_diff/version"
10
11
 
@@ -16,48 +17,50 @@ module LockDiff
16
17
  self.config = Config.new
17
18
  end
18
19
 
19
- def client
20
- config.client_class.client
21
- end
22
-
23
20
  def logger
24
21
  config.logger
25
22
  end
26
23
 
27
24
  def run(repository:, number:, post_comment: false)
28
- pr = PullRequest.new(repository: repository, number: number)
29
- lockfile_diff_infos = config.strategy.lock_file_diffs(pr)
30
- result = config.formatter.format(lockfile_diff_infos)
31
-
32
- if post_comment
33
- client.add_comment(repository, number, result)
34
- else
35
- $stdout.puts result
36
- end
25
+ pr = PullRequest.find_by(repository: repository, number: number)
26
+ _run(pull_request: pr, post_comment: post_comment)
37
27
  end
38
28
 
39
29
  def run_by_latest_tachikoma(repository:, post_comment: false)
40
- pr = Github.client.latest_pull_request(repository).
41
- find { |pull_request| pull_request.head_ref.include?("tachikoma") }
30
+ pr = PullRequest.latest_by_tachikoma(repository)
42
31
  if pr
43
- run(repository: repository, number: pr.number, post_comment: post_comment)
32
+ LockDiff.logger.info { "Running on repository: #{pr.repository}, number: #{pr.number}"}
33
+ _run(pull_request: pr, post_comment: post_comment)
44
34
  else
45
35
  LockDiff.logger.warn("Not found pull request by tachikoma. (Hint: search pull request by whether branch name includes 'tachikoma'")
46
36
  end
47
37
  end
48
38
 
49
- class Config
50
- attr_accessor :client_class, :formatter, :strategy, :logger
39
+ private
51
40
 
52
- def initialize
53
- @client_class = Github
54
- @formatter = Formatter::GithubMarkdown
55
- @strategy = Gem
56
- @logger = Logger.new($stdout)
57
- @logger.level = :warn
41
+ def _run(pull_request:, post_comment: false)
42
+ lockfile_diff_infos = LockfileComparator.compare_by(pull_request)
43
+ result = config.formatter.format(lockfile_diff_infos)
44
+
45
+ if post_comment
46
+ pull_request.add_comment(result)
47
+ else
48
+ $stdout.puts result
58
49
  end
59
50
  end
60
51
  end
52
+
53
+ class Config
54
+ attr_accessor :pr_repository_service, :formatter, :strategy, :logger
55
+
56
+ def initialize
57
+ @pr_repository_service = Github
58
+ @formatter = Formatter::GithubMarkdown
59
+ @strategy = Gem
60
+ @logger = Logger.new($stdout)
61
+ @logger.level = :warn
62
+ end
63
+ end
61
64
  end
62
65
 
63
66
  LockDiff.init!
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lock_diff
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.2
4
+ version: 0.3.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - vividmuimui
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-07-18 00:00:00.000000000 Z
11
+ date: 2017-07-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: octokit
@@ -131,25 +131,24 @@ files:
131
131
  - exe/lock_diff
132
132
  - exe/lock_diff_for_tachikoma
133
133
  - lib/lock_diff.rb
134
+ - lib/lock_diff/cli/option_parser.rb
134
135
  - lib/lock_diff/diff_info.rb
135
136
  - lib/lock_diff/formatter/github_markdown.rb
136
137
  - lib/lock_diff/gem.rb
137
138
  - lib/lock_diff/gem/lockfile_comparator.rb
138
139
  - lib/lock_diff/gem/package.rb
139
140
  - lib/lock_diff/gem/ruby_gem.rb
140
- - lib/lock_diff/gem/ruby_gem_repository.rb
141
141
  - lib/lock_diff/gem/spec.rb
142
142
  - lib/lock_diff/github.rb
143
143
  - lib/lock_diff/github/access_token.rb
144
144
  - lib/lock_diff/github/changelog_url_finder.rb
145
145
  - lib/lock_diff/github/client.rb
146
146
  - lib/lock_diff/github/content.rb
147
- - lib/lock_diff/github/github_url_detector.rb
148
- - lib/lock_diff/github/pr_lockfile.rb
149
147
  - lib/lock_diff/github/pull_request.rb
150
148
  - lib/lock_diff/github/repository_name_detector.rb
151
149
  - lib/lock_diff/github/tag_finder.rb
152
- - lib/lock_diff/option_parser.rb
150
+ - lib/lock_diff/github/url_detector.rb
151
+ - lib/lock_diff/lockfile_comparator.rb
153
152
  - lib/lock_diff/pull_request.rb
154
153
  - lib/lock_diff/version.rb
155
154
  - lock_diff.gemspec
@@ -1,23 +0,0 @@
1
- module LockDiff
2
- module Gem
3
- class RubyGemRepository
4
- class << self
5
- def find(name)
6
- ruby_gem = repository[name]
7
- return ruby_gem if ruby_gem
8
- repository[name] = RubyGem.new(name)
9
- end
10
-
11
- def repository
12
- @repository ||= {}
13
- end
14
-
15
- def clear
16
- @repository = {}
17
- end
18
- end
19
-
20
- end
21
-
22
- end
23
- end
@@ -1,27 +0,0 @@
1
- module LockDiff
2
- module Github
3
- class PrLockfile
4
- def initialize(pull_request, lockfile_name)
5
- @pr = pull_request
6
- @lockfile_name = lockfile_name
7
- end
8
-
9
- def changed?
10
- !!path
11
- end
12
-
13
- def path
14
- @path ||= @pr.find_content_path(@lockfile_name)
15
- end
16
-
17
- def base_file
18
- @base_file ||= LockDiff.client.file(@pr.repository, path: path, ref: @pr.base_sha)
19
- end
20
-
21
- def head_file
22
- @head_file ||= LockDiff.client.file(@pr.repository, path: path, ref: @pr.head_sha)
23
- end
24
-
25
- end
26
- end
27
- end
@@ -1,48 +0,0 @@
1
- require "optparse"
2
-
3
- module LockDiff
4
- class OptionParser
5
- class << self
6
- def parse(args, require_flags:)
7
- new(require_flags).parse(args)
8
- end
9
- end
10
-
11
- def initialize(require_flags)
12
- @require_flags = require_flags
13
- end
14
-
15
- def parse(args)
16
- options = {
17
- post_comment: false
18
- }
19
- opt = ::OptionParser.new
20
-
21
- opt.separator("Require flags")
22
- if @require_flags.include? :repository
23
- opt.on('-r', '--repository=REPOSITORY', 'Like as "user/repository"') { |v| options[:repository] = v }
24
- end
25
- if @require_flags.include? :number
26
- opt.on('-n', '--number=PULL_REQUEST_NUMBER') { |v| options[:number] = v }
27
- end
28
-
29
- opt.separator("\nOptional flags")
30
- opt.on('--post-comment=true or false', 'Print result to stdout when false. (default is false)') { |v| options[:post_comment] = v }
31
- opt.on("-v", "--verbose", "Run verbosely") { LockDiff.logger.level = :info }
32
- opt.on("--more-verbose", "Run more verbosely") { LockDiff.logger.level = :debug }
33
- opt.on_tail("--version", "Show version") do
34
- $stdout.puts LockDiff::VERSION
35
- exit
36
- end
37
- opt.parse!(args)
38
-
39
- if @require_flags.all? { |flag| options.has_key?(flag) }
40
- options
41
- else
42
- $stdout.puts opt.help
43
- exit
44
- end
45
- end
46
-
47
- end
48
- end