whatsnew 0.3.0 → 0.4.0

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: a219950a9a69efe9a80a642981f63e71b42a8cca
4
- data.tar.gz: ac3290929b7c929d2a839adccf34a0de8d9a3237
3
+ metadata.gz: 8e65b62f957e1db459c711ace3bffe378b45dbcf
4
+ data.tar.gz: ac629b4ff791f3c34e8cabdf0f22c0df9ac0115f
5
5
  SHA512:
6
- metadata.gz: 3737fe2813a30bbb0e5de036bcea21a6aac8b895b6684f76c0b111e4c258667f97e86902fb741982695a5ae4ffb723cc830161dee9f4bc6b6b785274266a8a70
7
- data.tar.gz: 9d8a0d1708a8bbff80248f12afbbb11b4a99ce0e845d3f290a063cc332832187fdecdd3b9b2004e5411dba050140e2b8426e35b39ad10f8df162ffe5581f1b92
6
+ metadata.gz: 24336375d94687abae9b7b40a185efa2c2fd098ff654a0807777d10cc7447b81f5ad8cdee368e839f393cae2df52c37ac02eb9ebf6ed3ac126dc1295ece21bd9
7
+ data.tar.gz: 685cfc1708993d40744908ff31509c4c4c761f3c62b2f121ef14c9e9aa5a92f34b42c0b5c18e8cb7bfcc899e392c13f52fcb02b3ab5c63914e76cdb1fdeb615d
data/.travis.yml CHANGED
@@ -12,4 +12,4 @@ matrix:
12
12
  fast_finish: true
13
13
  notifications:
14
14
  slack:
15
- secure: wZ1UPEcH/Zf/wSPvpR1q76vpUQvAEGuwR5500ML8C+shW7PedvuSZaiZYAOZxhyD17RXzXYroON0ArEk3NUcKD8supPzYjUWzCeWDIFaYxEb7dOm7tpRBf4GuQ/oy8HGsBi947ZTX3WytGWZU0q0aRu2EirPcoY05vzley/hYTI=
15
+ secure: B25UgGnWzd/gLr97Ac233rhp7bV3FnmbmuYU9KGLa7s8YTmdKnHg5ASOl3NEdDRSZwhhQvMF6FRhqLvQenFsIYn9f9qSmY0+d5/gB8iUQkGAIXIx0VFrPhO6ZTefEJ2uhPyKtZIkzEOVD9jo4w5Kh9XvUPFY1v8OM+wz+8cW28G+fS1gof+yJUBVQb7/FGSzc2nxDvCwcU2pYeQ2rUnugDc8wfcQYCsp+MU+qBTsotTBCiGqrZWouqi3dWbMPHqeaW8B343+jviM0LgvyEF6klw0dR218SRWlavYjZq6w4yEwtPI+Wl0jXe06DcbISBQwKRH4ljwT2Qvx0gjIEG9fKo7Gl59gg/U3p3wZixV/O1/f0oDgVO1FZIMHP0CVWX8+VV/g4ru/jVp0R74Mfq3mIhSh1z7iMgFMoVMzOLJq8nDPQWPi+1Wc5z1AeCnC1bjcwhN07FzIHq3GTuqjLGRNfm5nvG8PCsw0dgsV9z826teHJrXJz8mApGZZR6WvWdSqWdUaIxtHoeuaBd+7/iqxYKdW8uov4U7Vc4gFqs36SmNtrRf1fnVs/p0QM4SbPo+KYROin7oZTngMLVJ2qLYhTMWpszJfnpFl2ZHYlfTF2rHUaBioOnagAqs1iiVp51mX2brXnjUdQWGbGuEryrO88qZ5tS6DnfS4+A57cgloe8=
data/CHANGELOG.md CHANGED
@@ -2,9 +2,17 @@
2
2
 
3
3
  ## Unrelease
4
4
 
5
+ ## v0.4.0 - 2015-08-09
6
+
7
+ ### API CHANGES
8
+
9
+ - `NewsFile#content` => `NewsFile#read` [#4](https://github.com/jollygoodcode/whatsnew/pull/4)
10
+ - `NewsFile#content` => The content of the news file [#4](https://github.com/jollygoodcode/whatsnew/pull/4)
11
+ - Refactor the internal classes interfaces [#3](https://github.com/jollygoodcode/whatsnew/pull/3)
12
+
5
13
  ## v0.3.0 - 2015-08-09
6
14
 
7
- - API Support finding news file from Octokit response
15
+ - API Support finding news file from Octokit response [#1](https://github.com/jollygoodcode/whatsnew/pull/1)
8
16
 
9
17
  ## v0.2.0 - 2015-08-08
10
18
 
data/README.md CHANGED
@@ -3,7 +3,7 @@
3
3
  [![Gem Version](https://badge.fury.io/rb/whatsnew.svg)](http://badge.fury.io/rb/whatsnew)
4
4
  [![Build Status](https://travis-ci.org/jollygoodcode/whatsnew.svg?branch=master)](https://travis-ci.org/jollygoodcode/whatsnew)
5
5
 
6
- What's New of a project?
6
+ What's New about a project?
7
7
 
8
8
  --
9
9
 
@@ -36,7 +36,7 @@ What's New:
36
36
  See CHANGELOG.md: https://github.com/jollygoodcode/whatsnew/blob/master/CHANGELOG.md.
37
37
  ```
38
38
 
39
- ### Local API usage
39
+ ### API usage for Local Files
40
40
 
41
41
  ```ruby
42
42
  news = Whatsnew.about "/Users/Juan/dev/whatsnew"
@@ -47,13 +47,15 @@ news.file_name
47
47
  news.file_url
48
48
  => "https://github.com/jollygoodcode/whatsnew/blob/master/CHANGELOG.md"
49
49
 
50
- news.content
50
+ news.read
51
51
  => "What's New:\nSee CHANGELOG.md: https://github.com/jollygoodcode/whatsnew/blob/master/CHANGELOG.md."
52
52
  ```
53
53
 
54
- ### Remote API usage with [Octokit](https://github.com/octokit/octokit.rb)
54
+ ### API usage for Remote Files
55
55
 
56
- First [get an OAuth access token](https://help.github.com/articles/creating-an-access-token-for-command-line-use/), then:
56
+ #### Example use with [Octokit](https://github.com/octokit/octokit.rb)
57
+
58
+ First [get an access token](https://help.github.com/articles/creating-an-access-token-for-command-line-use/), then:
57
59
 
58
60
  ```ruby
59
61
  client = Octokit::Client.new(access_token: ENV["OAUTH_TOKEN"])
@@ -66,10 +68,27 @@ news.file_name
66
68
  news.file_url
67
69
  => "https://github.com/jollygoodcode/whatsnew/blob/master/CHANGELOG.md"
68
70
 
69
- news.content
71
+ news.read
70
72
  => "What's New:\nSee CHANGELOG.md: https://github.com/jollygoodcode/whatsnew/blob/master/CHANGELOG.md."
71
73
  ```
72
74
 
75
+ Note that you can pass in array of any objects to `Whatsnew.about`, each object must respond to `:name` and `:html_url` messages:
76
+
77
+ ```ruby
78
+ Resource = Struct.new(:name, :html_url)
79
+
80
+ news = Whatsnew.about [Resource.new("NEWS", "https://github.com/ruby/ruby/blob/trunk/NEWS")]
81
+
82
+ news.file_name
83
+ => "NEWS"
84
+
85
+ news.file_url
86
+ => "https://github.com/ruby/ruby/blob/trunk/NEWS"
87
+
88
+ news.read
89
+ => "What's New:\nSee NEWS: https://github.com/ruby/ruby/blob/trunk/NEWS."
90
+ ```
91
+
73
92
 
74
93
  ## What it searches for?
75
94
 
@@ -85,6 +104,10 @@ See [DEVELOPMENT.md](DEVELOPMENT.md).
85
104
 
86
105
  See [CONTRIBUTING.md](CONTRIBUTING.md).
87
106
 
107
+ ## Inspired by
108
+
109
+ [benbalter/licensee](https://github.com/benbalter/licensee) - A RubyGem to detect under what license a project is distributed.
110
+
88
111
  ## Credits
89
112
 
90
113
  A huge THANK YOU to all our [contributors](https://github.com/jollygoodcode/whatsnew/graphs/contributors)! :heart:
data/bin/whatsnew CHANGED
@@ -6,7 +6,7 @@ require "bundler/setup"
6
6
  require "whatsnew"
7
7
 
8
8
  if news = Whatsnew.about(Dir.pwd)
9
- puts news.content
9
+ puts news.read
10
10
  else
11
11
  puts "Not found. Do you mind keep a changelog?"
12
12
  puts "Or tell the project owner to keep a changelog :)"
@@ -0,0 +1,52 @@
1
+ require "pathname"
2
+
3
+ module Whatsnew
4
+ class LocalFiles
5
+ def initialize(path)
6
+ @path = path
7
+ @news = Dir.glob(File.join(path, "*".freeze)).find do |file|
8
+ file =~ %r{(CHANGE|CHANGES|CHANGELOG|NEWS|HISTORY)}i.freeze
9
+ end
10
+ end
11
+
12
+ def to_news_file
13
+ if news
14
+ NewsFile.new(
15
+ file_name,
16
+ content: file.read,
17
+ file_url: "#{project_uri}/blob/master/#{file_name}"
18
+ )
19
+ else
20
+ NoNewsFile.new
21
+ end
22
+ end
23
+
24
+ private
25
+
26
+ attr_reader :path, :news, :matched
27
+
28
+ def project_uri
29
+ if File.exist?("#{path}/.git") && matched_from_git_config
30
+ "https://#{matched[:host]}/#{matched[:owner]}/#{matched[:repo]}"
31
+ else
32
+ "NOT FOUND".freeze
33
+ end
34
+ end
35
+
36
+ def matched_from_git_config
37
+ @matched ||= Dir.chdir(Pathname(path).to_path) do
38
+ `git config --get remote.origin.url`.match(
39
+ %r{git.+(?<host>(github.com|bitbucket.com|bitbucket.org))[:/](?<owner>\S+)/(?<repo>\S+)\.git}
40
+ )
41
+ end
42
+ end
43
+
44
+ def file
45
+ @file ||= Pathname(news)
46
+ end
47
+
48
+ def file_name
49
+ @file_name ||= file.basename.to_s
50
+ end
51
+ end
52
+ end
@@ -2,23 +2,16 @@ require "pathname"
2
2
 
3
3
  module Whatsnew
4
4
  class NewsFile
5
- attr_reader :file_url
5
+ attr_reader :file_name, :content, :file_url
6
6
 
7
- def initialize(path, project_uri)
8
- @newsfile = Pathname(path)
9
- @file_url = "#{project_uri}/blob/master/#{file_name}"
7
+ def initialize(file_name, content: nil, file_url: nil)
8
+ @file_name = file_name
9
+ @content = content
10
+ @file_url = file_url
10
11
  end
11
12
 
12
- def content
13
+ def read
13
14
  "What's New:\n" "See #{file_name}: #{file_url}."
14
15
  end
15
-
16
- def file_name
17
- newsfile.basename.to_s
18
- end
19
-
20
- private
21
-
22
- attr_reader :newsfile
23
16
  end
24
17
  end
@@ -4,16 +4,20 @@ module Whatsnew
4
4
  class NoNewsFile
5
5
  NOT_FOUND = "NOT FOUND".freeze
6
6
 
7
- def content
7
+ def file_name
8
8
  NOT_FOUND
9
9
  end
10
10
 
11
- def file_name
11
+ def file_url
12
12
  NOT_FOUND
13
13
  end
14
14
 
15
- def file_url
15
+ def read
16
16
  NOT_FOUND
17
17
  end
18
+
19
+ def content
20
+ "".freeze
21
+ end
18
22
  end
19
23
  end
@@ -1,56 +1,25 @@
1
- require "pathname"
2
-
3
1
  module Whatsnew
4
2
  class Project
5
3
  attr_reader :news_file
6
4
 
7
- def initialize(path)
8
- @path = path
9
- @news_file = get_news_file_from_path
10
- end
11
-
12
- def get_news_file_from_path
13
- if path_is_a_sawyer_resource_array
14
- RemoteNewsFile.new(path)
15
- else
16
- if news_file_name
17
- NewsFile.new(news_file_name, project_uri)
18
- else
19
- NoNewsFile.new
20
- end
21
- end
22
- end
5
+ def initialize(path_or_resources)
6
+ @path_or_resources = Array(path_or_resources)
23
7
 
24
- # git@github.com:jollygoodcode/whatsnew.git
25
- # => https://github.com:jollygoodcode/whatsnew
26
- def project_uri
27
- if matched = matched_from_git_repository
28
- "https://#{matched[:host]}/#{matched[:owner]}/#{matched[:repo]}"
8
+ @news_file = if resources?
9
+ RemoteFiles.new(path_or_resources).to_news_file
29
10
  else
30
- "NOT FOUND".freeze
11
+ LocalFiles.new(path_or_resources).to_news_file
31
12
  end
32
13
  end
33
14
 
34
15
  private
35
16
 
36
- attr_reader :path
37
-
38
- def path_is_a_sawyer_resource_array
39
- path.is_a?(Array) && path.first.is_a?(Sawyer::Resource)
40
- end
41
-
42
- def news_file_name
43
- @news_file_name ||= Dir.glob(File.join(path, "*".freeze)).find do |file|
44
- file =~ %r{(CHANGE|CHANGES|CHANGELOG|NEWS|HISTORY)}i.freeze
45
- end
46
- end
17
+ attr_reader :path_or_resources
47
18
 
48
- def matched_from_git_repository
49
- Dir.chdir(Pathname(path).to_path) do
50
- `git config --get remote.origin.url`.match(
51
- %r{git.+(?<host>(github.com|bitbucket.com|bitbucket.org))[:/](?<owner>\S+)/(?<repo>\S+)\.git}
52
- )
53
- end
19
+ def resources?
20
+ path_or_resources &&
21
+ path_or_resources.first.respond_to?(:name) &&
22
+ path_or_resources.first.respond_to?(:html_url)
54
23
  end
55
24
  end
56
25
  end
@@ -0,0 +1,25 @@
1
+ module Whatsnew
2
+ class RemoteFiles
3
+ def initialize(resources)
4
+ @news = resources.find do |resource|
5
+ resource.name =~ %r{(CHANGE|CHANGES|CHANGELOG|NEWS|HISTORY)}i.freeze
6
+ end
7
+ end
8
+
9
+ def to_news_file
10
+ if news
11
+ NewsFile.new(news.name, content: "See #{news_html_url}", file_url: news_html_url)
12
+ else
13
+ NoNewsFile.new
14
+ end
15
+ end
16
+
17
+ private
18
+
19
+ attr_reader :news
20
+
21
+ def news_html_url
22
+ @news_html_url ||= news.html_url
23
+ end
24
+ end
25
+ end
@@ -1,3 +1,3 @@
1
1
  module Whatsnew
2
- VERSION = "0.3.0"
2
+ VERSION = "0.4.0"
3
3
  end
data/lib/whatsnew.rb CHANGED
@@ -1,11 +1,13 @@
1
1
  require "whatsnew/version"
2
- require "whatsnew/remote_news_file"
2
+ require "whatsnew/remote_files"
3
+ require "whatsnew/local_files"
3
4
  require "whatsnew/news_file"
4
5
  require "whatsnew/no_news_file"
5
6
  require "whatsnew/project"
6
7
 
7
8
  module Whatsnew
8
- def self.about(path)
9
- Whatsnew::Project.new(path).news_file
9
+ # Each resource must respond to message :name and :html.
10
+ def self.about(path_or_resources)
11
+ Whatsnew::Project.new(path_or_resources).news_file
10
12
  end
11
13
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: whatsnew
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Juanito Fatas
@@ -30,10 +30,11 @@ files:
30
30
  - bin/dev
31
31
  - bin/whatsnew
32
32
  - lib/whatsnew.rb
33
+ - lib/whatsnew/local_files.rb
33
34
  - lib/whatsnew/news_file.rb
34
35
  - lib/whatsnew/no_news_file.rb
35
36
  - lib/whatsnew/project.rb
36
- - lib/whatsnew/remote_news_file.rb
37
+ - lib/whatsnew/remote_files.rb
37
38
  - lib/whatsnew/version.rb
38
39
  - whatsnew.gemspec
39
40
  homepage: https://github.com/jollygoodcode/whatsnew
@@ -1,27 +0,0 @@
1
- require "pathname"
2
-
3
- module Whatsnew
4
- class RemoteNewsFile
5
- def initialize(sawyer_resources)
6
- @news_resource = sawyer_resources.find do |resource|
7
- resource.name =~ %r{(CHANGE|CHANGES|CHANGELOG|NEWS|HISTORY)}i.freeze
8
- end
9
- end
10
-
11
- def content
12
- "What's New:\n" "See #{file_name}: #{file_url}."
13
- end
14
-
15
- def file_name
16
- news_resource.name
17
- end
18
-
19
- def file_url
20
- news_resource.html_url
21
- end
22
-
23
- private
24
-
25
- attr_reader :news_resource
26
- end
27
- end