lock_diff 0.1.5 → 0.1.6

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: 8c0b8383d775ad39dbd93fff93530652b7e60e3d
4
- data.tar.gz: 34ef1bd10ad27bb846e4ba47c7926dd9a0281ae4
3
+ metadata.gz: f5daade500e51cc434beb8931d9ff6b12d7dde3e
4
+ data.tar.gz: 8a33731e03a14c8768bae59dd80bf7d84f3f228f
5
5
  SHA512:
6
- metadata.gz: f2885f2572e82adffed6fa073a2f1fa7b7ae0500a0f8aca59039fe4a52b2da2163f764c0357978016c133e1592a60fedf2da8273b4e8c66a36e39808d086eff4
7
- data.tar.gz: c076daeb953b7da33bb7a20fc2e2e607791261b15cedc41b862493f8fb9b4043e30b4b33647c940ad01b33d10a055913cb2c8bca36dccde52421a2ea9f1b3e50
6
+ metadata.gz: 123148022cfa87ba4b0b125f4656c779a33f87dcd52f7e1e5ca4e10fc534a35ce82c92dacd539a40060ae45471197973cc7cdf679efaac99f901d0b78fd285b9
7
+ data.tar.gz: 2ad1171f41b5a751685780d886e54b9cb9d8857d4f92735c938c17f5b603b60ada2e24b6b58764a08fb6211f103ddc77720f35ff03c3a21d0ba62c6cc42f92c0
data/.travis.yml ADDED
@@ -0,0 +1,6 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.3.4
4
+ - 2.4.1
5
+ script:
6
+ - bundle exec rspec
data/README.md CHANGED
@@ -1,6 +1,11 @@
1
1
  # LockDiff
2
2
 
3
- [![CircleCI](https://circleci.com/gh/vividmuimui/lock_diff.svg?style=svg)](https://circleci.com/gh/vividmuimui/lock_diff)
3
+ [![Gem Version](https://badge.fury.io/rb/lock_diff.svg)](https://badge.fury.io/rb/lock_diff)
4
+ [![GitHub tag](https://img.shields.io/github/tag/vividmuimui/lock_diff.svg)](https://github.com/vividmuimui/lock_diff/tags)
5
+ [![Build Status](https://travis-ci.org/vividmuimui/lock_diff.svg?branch=master)](https://travis-ci.org/vividmuimui/lock_diff)
6
+ [![Dependency Status](https://gemnasium.com/badges/github.com/vividmuimui/lock_diff.svg)](https://gemnasium.com/github.com/vividmuimui/lock_diff)
7
+ [![Code Climate](https://codeclimate.com/github/vividmuimui/lock_diff/badges/gpa.svg)](https://codeclimate.com/github/vividmuimui/lock_diff)
8
+ [![Issue Count](https://codeclimate.com/github/vividmuimui/lock_diff/badges/issue_count.svg)](https://codeclimate.com/github/vividmuimui/lock_diff)
4
9
 
5
10
  This gem detects changes to your package manager (e.g. Gemfile) and generates a Markdown-formatted diff including:
6
11
 
@@ -69,7 +74,7 @@ When used in conjunction with [tachikoma](https://rubygems.org/gems/tachikoma),
69
74
  #### Command line
70
75
 
71
76
  ```sh
72
- $ lock_diff
77
+ $ lock_diff_for_tachikoma
73
78
  Usage: lock_diff_for_tachikoma [options]
74
79
  -r, --repository=REPOSITORY required. Like as "user/repository"
75
80
  --post-comment=true or false default=false
data/exe/lock_diff CHANGED
@@ -1,20 +1,7 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
3
  require "lock_diff"
4
- require "optparse"
4
+ require "lock_diff/option_parser"
5
5
 
6
- options = {
7
- post_comment: false
8
- }
9
- opt = OptionParser.new
10
-
11
- opt.on('-r', '--repository=REPOSITORY', 'required. Like as "user/repository"') { |v| options[:repository] = v }
12
- opt.on('-n', '--number=PULL_REQUEST_NUMBER', 'required') { |v| options[:number] = v }
13
- opt.on('--post-comment=true or false', '(default=false. Print result to stdout when false.)') { |v| options[:post_comment] = v }
14
- opt.parse!
15
-
16
- unless options[:repository] && options[:number]
17
- $stdout.puts opt.help
18
- else
19
- LockDiff.run(options)
20
- end
6
+ options = LockDiff::OptionParser.parse(ARGV, require_flags: %i(repository number))
7
+ LockDiff.run(options)
@@ -1,19 +1,7 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
3
  require "lock_diff"
4
- require "optparse"
4
+ require "lock_diff/option_parser"
5
5
 
6
- options = {
7
- post_comment: false
8
- }
9
- opt = OptionParser.new
10
-
11
- opt.on('-r', '--repository=REPOSITORY', 'required. Like as "user/repository"') { |v| options[:repository] = v }
12
- opt.on('--post-comment=true or false', '(default=false. Print result to stdout when false.)') { |v| options[:post_comment] = v }
13
- opt.parse!
14
-
15
- unless options[:repository]
16
- $stdout.puts opt.help
17
- else
18
- LockDiff.run_by_latest_tachikoma(options)
19
- end
6
+ options = LockDiff::OptionParser.parse(ARGV, require_flags: %i(repository))
7
+ LockDiff.run_by_latest_tachikoma(options)
@@ -59,7 +59,7 @@ module LockDiff
59
59
 
60
60
  def change_log
61
61
  if diff_info.change_log_url
62
- "[change log](#{diff_info.change_log_url})"
62
+ "[#{diff_info.change_log_name}](#{diff_info.change_log_url})"
63
63
  else
64
64
  ""
65
65
  end
@@ -4,7 +4,7 @@ module LockDiff
4
4
  extend Forwardable
5
5
 
6
6
  attr_reader :old_version, :new_version
7
- def_delegators :@gem, :name, :url, :change_log_url
7
+ def_delegators :@gem, :name, :url
8
8
 
9
9
  def self.by(old_spec:, new_spec:)
10
10
  gem = Gem.new(new_spec.name)
@@ -26,6 +26,18 @@ module LockDiff
26
26
  @old_version.version != @new_version.version
27
27
  end
28
28
 
29
+ def change_log_url
30
+ @change_log_url ||= Github::ChangeLogUrlFinder.new(
31
+ repository: @gem.repository,
32
+ github_url: @gem.github_url,
33
+ ref: @new_version.ref
34
+ ).call
35
+ end
36
+
37
+ def change_log_name
38
+ File.basename(change_log_url)
39
+ end
40
+
29
41
  def diff_url
30
42
  return unless @gem.github_url && @old_version.ref && @new_version.ref
31
43
  "#{@gem.github_url}/compare/#{@old_version.ref}...#{@new_version.ref}"
@@ -15,18 +15,10 @@ module LockDiff
15
15
  @ruby_gem.github_url || @ruby_gem.homepage_url
16
16
  end
17
17
 
18
- def change_log_url
19
- @change_log_url ||= Github::ChangeLogUrlFinder.new(repository: repository, github_url: @ruby_gem.github_url).call
20
- end
21
-
22
18
  def repository
23
19
  Github::RepositoryNameDetector.new(@ruby_gem.github_url).call
24
20
  end
25
21
 
26
- def tag_names
27
- @tag_names ||= LockDiff.client.tag_names(repository)
28
- end
29
-
30
22
  end
31
23
  end
32
24
  end
@@ -15,18 +15,35 @@ module LockDiff
15
15
  end
16
16
 
17
17
  def to_s
18
- ref || version.to_s
18
+ revision || version.to_s
19
19
  end
20
20
 
21
21
  private
22
22
 
23
23
  def git_tag
24
+ return @git_tag if defined? @git_tag
25
+ @git_tag = find_tag(limit: 4, per_page: 50)
26
+ end
27
+
28
+ def find_tag(page: 1, limit:, per_page:)
29
+ return nil if page > limit
30
+
24
31
  version_str = version.to_s
25
- @gem.tag_names.find do |tag_name|
32
+ fetched_tags = LockDiff.client.tag_names(@gem.repository, page: page, per_page: per_page)
33
+ tag = fetched_tags.find do |tag_name|
26
34
  tag_name == version_str ||
27
35
  tag_name == "v#{version_str}" ||
28
36
  tag_name == "#{@gem.name}-#{version_str}"
29
37
  end
38
+
39
+ if tag
40
+ return tag
41
+ else
42
+ LockDiff.logger.debug { "Not found tag of #{@gem.name}, #{version_str} by page: #{page}, per_page: #{per_page}"}
43
+ unless fetched_tags.count < per_page
44
+ find_tag(page: page + 1, limit: limit, per_page: per_page)
45
+ end
46
+ end
30
47
  end
31
48
 
32
49
  end
@@ -10,9 +10,10 @@ module LockDiff
10
10
  news
11
11
  )
12
12
 
13
- def initialize(repository:, github_url:)
13
+ def initialize(repository:, github_url:, ref:)
14
14
  @repository = repository
15
15
  @github_url = github_url
16
+ @ref = ref
16
17
  end
17
18
 
18
19
  def call
@@ -22,7 +23,7 @@ module LockDiff
22
23
  private
23
24
 
24
25
  def find_change_log_url
25
- Github.client.contents(@repository).
26
+ Github.client.contents(@repository, ref: @ref).
26
27
  select(&:file?).
27
28
  find { |content|
28
29
  name = content.name.downcase.delete('_')
@@ -40,16 +40,16 @@ module LockDiff
40
40
  @client.releases(repository).empty?
41
41
  end
42
42
 
43
- def contents(repository)
43
+ def contents(repository, options = {})
44
44
  return [] unless repository
45
- @client.contents(repository).map do |content|
45
+ @client.contents(repository, options).map do |content|
46
46
  Content.new(content)
47
47
  end
48
48
  end
49
49
 
50
- def tag_names(repository)
50
+ def tag_names(repository, options = {})
51
51
  return [] unless repository
52
- @client.tags(repository).map(&:name)
52
+ @client.tags(repository, options).map(&:name)
53
53
  end
54
54
 
55
55
  def add_comment(repository, number, comment)
@@ -0,0 +1,48 @@
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") { |v| LockDiff.logger.level = :debug }
32
+ opt.on_tail("--version", "Show version") do
33
+ $stdout.puts LockDiff::VERSION
34
+ exit
35
+ end
36
+ opt.parse!(args)
37
+
38
+ if @require_flags.all? { |flag| options.has_key?(flag) }
39
+ options
40
+ else
41
+ puts options
42
+ $stdout.puts opt.help
43
+ exit
44
+ end
45
+ end
46
+
47
+ end
48
+ end
@@ -1,3 +1,3 @@
1
1
  module LockDiff
2
- VERSION = "0.1.5"
2
+ VERSION = "0.1.6"
3
3
  end
data/lib/lock_diff.rb CHANGED
@@ -28,7 +28,7 @@ module LockDiff
28
28
  end
29
29
 
30
30
  def run_by_latest_tachikoma(repository:, post_comment: false)
31
- pr = Github.client.latest_pull_request(repository, limit: 10).
31
+ pr = Github.client.latest_pull_request(repository).
32
32
  find { |pull_request| pull_request.head_ref.include?("tachikoma") }
33
33
  if pr
34
34
  run(repository: repository, number: pr.number, post_comment: post_comment)
@@ -41,5 +41,5 @@ module LockDiff
41
41
  self.client_class = Github
42
42
  self.formatter = Formatter::GithubMarkdown
43
43
  self.strategy = Gem
44
- self.logger = Logger.new($stdout)
44
+ self.logger = Logger.new($stdout, level: :info)
45
45
  end
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.1.5
4
+ version: 0.1.6
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-05 00:00:00.000000000 Z
11
+ date: 2017-07-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: octokit
@@ -118,9 +118,9 @@ executables:
118
118
  extensions: []
119
119
  extra_rdoc_files: []
120
120
  files:
121
- - ".circleci/config.yml"
122
121
  - ".gitignore"
123
122
  - ".rspec"
123
+ - ".travis.yml"
124
124
  - CODE_OF_CONDUCT.md
125
125
  - Gemfile
126
126
  - LICENSE.txt
@@ -148,6 +148,7 @@ files:
148
148
  - lib/lock_diff/github/github_url_detector.rb
149
149
  - lib/lock_diff/github/pull_request.rb
150
150
  - lib/lock_diff/github/repository_name_detector.rb
151
+ - lib/lock_diff/option_parser.rb
151
152
  - lib/lock_diff/pull_request.rb
152
153
  - lib/lock_diff/version.rb
153
154
  - lock_diff.gemspec
data/.circleci/config.yml DELETED
@@ -1,34 +0,0 @@
1
- version: 2
2
- jobs:
3
- build:
4
- working_directory: ~/lock_diff
5
- docker:
6
- - image: circleci/ruby:2.4.1-node
7
- steps:
8
- - checkout
9
-
10
- # Restore bundle cache
11
- - type: cache-restore
12
- key: bundle-cache-{{ checksum "Gemfile.lock" }}
13
-
14
- # Bundle install dependencies
15
- - run: bundle install --path vendor/bundle
16
-
17
- # Store bundle cache
18
- - type: cache-save
19
- key: bundle-cache-{{ checksum "Gemfile.lock" }}
20
- paths:
21
- - vendor/bundle
22
-
23
- # Run rspec in parallel
24
- - type: shell
25
- command: |
26
- bundle exec rspec --profile 10 \
27
- --format RspecJunitFormatter \
28
- --out /tmp/test-results/rspec.xml \
29
- --format progress \
30
- $(circleci tests glob "spec/**/*_spec.rb" | circleci tests split --split-by=timings)
31
-
32
- # Save artifacts
33
- - type: store_test_results
34
- path: /tmp/test-results