whatsnew 0.4.1 → 1.0.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 +4 -4
- data/.gitignore +1 -0
- data/.rspec +2 -0
- data/.travis.yml +5 -3
- data/CHANGELOG.md +2 -0
- data/CONTRIBUTING.md +14 -0
- data/Gemfile +10 -7
- data/README.md +103 -41
- data/Rakefile +3 -9
- data/bin/whatsnew +4 -8
- data/lib/whatsnew/cli.rb +31 -0
- data/lib/whatsnew/constants.rb +8 -0
- data/lib/whatsnew/local_files.rb +7 -34
- data/lib/whatsnew/local_news_file.rb +49 -0
- data/lib/whatsnew/news_file.rb +21 -7
- data/lib/whatsnew/no_news_file.rb +4 -8
- data/lib/whatsnew/project.rb +14 -10
- data/lib/whatsnew/release_file.rb +31 -0
- data/lib/whatsnew/remote_files.rb +45 -8
- data/lib/whatsnew/version.rb +1 -1
- data/lib/whatsnew.rb +11 -5
- data/whatsnew.gemspec +3 -0
- metadata +49 -6
- data/DEVELOPMENT.md +0 -13
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7afbacce07e4b62f2d0eb05bce8800e1da477ba2
|
4
|
+
data.tar.gz: afc225b4ba64d76501eaa7699a48d9c7e001c4b5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5d5f790215ad630e912dd1de66b0aa4437576225f1de2cec77261aa2ededf8538457e6905389493ec0d99816afb56c06cb4cc92437418331375a9eb4f06df1f3
|
7
|
+
data.tar.gz: 3f6a9894eea53ff3f0e33743c3f447d29bcf6a9d2eabc249fa2e0fe46e7f42aabe77285a9e5a989444ef87044ed2084a90e841279416e7f8d8af30f800b31c2f
|
data/.gitignore
CHANGED
data/.rspec
ADDED
data/.travis.yml
CHANGED
@@ -2,12 +2,14 @@ language: ruby
|
|
2
2
|
sudo: false
|
3
3
|
bundler_args: "--retry=3 --jobs=3"
|
4
4
|
rvm:
|
5
|
-
- 2.
|
6
|
-
- 2.
|
7
|
-
- 2.
|
5
|
+
- 2.1.8
|
6
|
+
- 2.2.4
|
7
|
+
- 2.3.0
|
8
|
+
- 2.0.0
|
8
9
|
- ruby-head
|
9
10
|
matrix:
|
10
11
|
allow_failures:
|
12
|
+
- rvm: 2.0.0
|
11
13
|
- rvm: ruby-head
|
12
14
|
fast_finish: true
|
13
15
|
notifications:
|
data/CHANGELOG.md
CHANGED
data/CONTRIBUTING.md
CHANGED
@@ -5,3 +5,17 @@
|
|
5
5
|
3. Commit your changes ( `git commit -am 'Add some feature'` )
|
6
6
|
4. Push to the branch ( `git push origin my-new-feature` )
|
7
7
|
5. Create a new Pull Request
|
8
|
+
|
9
|
+
## Development
|
10
|
+
|
11
|
+
### Install Dependencies
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
### Running Tests
|
16
|
+
|
17
|
+
$ bundle exec rake
|
18
|
+
|
19
|
+
### Run with local gem
|
20
|
+
|
21
|
+
$ bin/dev
|
data/Gemfile
CHANGED
@@ -2,10 +2,13 @@ source "https://rubygems.org"
|
|
2
2
|
|
3
3
|
gemspec
|
4
4
|
|
5
|
-
|
6
|
-
gem "
|
7
|
-
gem "
|
8
|
-
gem "
|
9
|
-
gem "
|
10
|
-
gem "octokit", "~> 4.
|
11
|
-
gem "dish"
|
5
|
+
group :development do
|
6
|
+
gem "bundler"
|
7
|
+
gem "rake"
|
8
|
+
gem "pry"
|
9
|
+
gem "rspec", "~> 3.3.0"
|
10
|
+
gem "octokit", "~> 4.1.1"
|
11
|
+
gem "dish"
|
12
|
+
gem "webmock"
|
13
|
+
gem "pry-byebug"
|
14
|
+
end
|
data/README.md
CHANGED
@@ -3,11 +3,11 @@
|
|
3
3
|
[](http://badge.fury.io/rb/whatsnew)
|
4
4
|
[](https://travis-ci.org/jollygoodcode/whatsnew)
|
5
5
|
|
6
|
-
What's New
|
6
|
+
What's New in a project?
|
7
7
|
|
8
|
-
|
8
|
+
This gem is used in [deppbot](https://www.deppbot.com) to find changelog in Pull Request body, an example could be found in [this Pull Request on ruby-bench/ruby-bench-web](https://github.com/ruby-bench/ruby-bench-web/pull/122).
|
9
9
|
|
10
|
-
|
10
|
+
--
|
11
11
|
|
12
12
|
## Installation
|
13
13
|
|
@@ -19,24 +19,87 @@ gem "whatsnew"
|
|
19
19
|
|
20
20
|
And then execute:
|
21
21
|
|
22
|
-
|
22
|
+
```
|
23
|
+
$ bundle
|
24
|
+
```
|
23
25
|
|
24
|
-
Or install it yourself
|
26
|
+
Or install it yourself:
|
25
27
|
|
26
|
-
|
28
|
+
```
|
29
|
+
$ gem install whatsnew
|
30
|
+
```
|
27
31
|
|
28
32
|
## Usage
|
29
33
|
|
30
|
-
###
|
34
|
+
### First Setup a OAuth Token
|
31
35
|
|
36
|
+
Either pass in as command line argument
|
37
|
+
|
38
|
+
```
|
39
|
+
whatsnew --access-token=<your-40-char-token>
|
32
40
|
```
|
33
|
-
$ whatsnew
|
34
41
|
|
42
|
+
Or stored in ENV variable: `OAUTH_ACCESS_TOKEN`.
|
43
|
+
|
44
|
+
### Get a OAuth Token
|
45
|
+
|
46
|
+
You can either get a [Personal Access Token](https://help.github.com/articles/creating-an-access-token-for-command-line-use/) or [get an OAuth token](https://developer.github.com/v3/oauth).
|
47
|
+
|
48
|
+
If you need to access private repository, make sure to specify the `repo` scope while creating your token.
|
49
|
+
|
50
|
+
If no OAuth token is provided, unauthenticated limits to [60 requests per hour](https://developer.github.com/v3/#rate-limiting).
|
51
|
+
|
52
|
+
### Command Line Usage
|
53
|
+
|
54
|
+
By default `whatsnew about` without argument will search for current folder:
|
55
|
+
|
56
|
+
```
|
57
|
+
$ whatsnew about
|
35
58
|
What's New:
|
36
59
|
See CHANGELOG.md: https://github.com/jollygoodcode/whatsnew/blob/master/CHANGELOG.md.
|
37
60
|
```
|
38
61
|
|
39
|
-
|
62
|
+
You can also search for a GitHub repository:
|
63
|
+
|
64
|
+
```
|
65
|
+
$ whatsnew about jollygoodcode/twemoji
|
66
|
+
What's New:
|
67
|
+
See CHANGELOG.md: https://github.com/jollygoodcode/twemoji/blob/master/CHANGELOG.md.
|
68
|
+
```
|
69
|
+
|
70
|
+
If a [changelog-like file](#what-does-it-search-for) cannot be found, whatsnew will search for [GitHub Releases](https://github.com/blog/1547-release-your-software) (if it has any releases with non-empty release body):
|
71
|
+
|
72
|
+
```
|
73
|
+
$ whatsnew about benbalter/licensee
|
74
|
+
What's New:
|
75
|
+
See Releases: https://github.com/benbalter/licensee/releases.
|
76
|
+
```
|
77
|
+
|
78
|
+
Both changelog and release cannot be found:
|
79
|
+
|
80
|
+
```
|
81
|
+
$ whatsnew about
|
82
|
+
Not found. This project should keep a changelog.
|
83
|
+
Please see http://keepachangelog.com.
|
84
|
+
```
|
85
|
+
|
86
|
+
## What Does It Search For?
|
87
|
+
|
88
|
+
* changelog-like file
|
89
|
+
|
90
|
+
`CHANGELOG`, `CHANGE`, `CHANGES`, `HISTORY`, `NEWS` in the root of the project (regardless of file extension).
|
91
|
+
|
92
|
+
* If a changelog-like file cannot be found, will try to see if [GitHub Releases](https://github.com/blog/1547-release-your-software) has contents to show
|
93
|
+
|
94
|
+
* It doesn't search for changelog listed in README
|
95
|
+
|
96
|
+
### API usage
|
97
|
+
|
98
|
+
`Whatsnew.about` API can take a path (see Local section below) or `owner/repo` (see Remote section below) string.
|
99
|
+
|
100
|
+
#### Local
|
101
|
+
|
102
|
+
Search in given path:
|
40
103
|
|
41
104
|
```ruby
|
42
105
|
news = Whatsnew.about "/Users/Juan/dev/whatsnew"
|
@@ -46,24 +109,26 @@ news.file_name
|
|
46
109
|
|
47
110
|
news.file_url
|
48
111
|
=> "https://github.com/jollygoodcode/whatsnew/blob/master/CHANGELOG.md"
|
112
|
+
# or returns changelog's path if this project is not a git repository
|
113
|
+
=> "/Users/Juan/dev/whatsnew/CHANGELOG.md"
|
49
114
|
|
50
115
|
news.content
|
51
|
-
=> "Content of CHANGELOG.md"
|
116
|
+
=> "Prints Content of CHANGELOG.md"
|
52
117
|
|
53
118
|
news.read
|
54
119
|
=> "What's New:\nSee CHANGELOG.md: https://github.com/jollygoodcode/whatsnew/blob/master/CHANGELOG.md."
|
55
120
|
```
|
56
121
|
|
57
|
-
|
122
|
+
#### Remote
|
58
123
|
|
59
|
-
|
124
|
+
Search changelog-like file / releases on GitHub.
|
60
125
|
|
61
|
-
|
126
|
+
It will first search if a remote repository has a changelog file:
|
62
127
|
|
63
|
-
|
64
|
-
client = Octokit::Client.new(access_token: ENV["OAUTH_TOKEN"])
|
128
|
+
Search in given `owner/repo`:
|
65
129
|
|
66
|
-
|
130
|
+
```ruby
|
131
|
+
news = Whatsnew.about "jollygoodcode/whatsnew", oauth_token: "e72e16c7e42f292c6912e7710c838347ae178b4a"
|
67
132
|
|
68
133
|
news.file_name
|
69
134
|
=> "CHANGELOG.md"
|
@@ -71,52 +136,49 @@ news.file_name
|
|
71
136
|
news.file_url
|
72
137
|
=> "https://github.com/jollygoodcode/whatsnew/blob/master/CHANGELOG.md"
|
73
138
|
|
139
|
+
news.content
|
140
|
+
=> "Please see: https://github.com/jollygoodcode/whatsnew/blob/master/CHANGELOG.md."
|
141
|
+
|
74
142
|
news.read
|
75
143
|
=> "What's New:\nSee CHANGELOG.md: https://github.com/jollygoodcode/whatsnew/blob/master/CHANGELOG.md."
|
76
144
|
```
|
77
145
|
|
78
|
-
|
146
|
+
Then search for GitHub Releases with non-empty body.
|
79
147
|
|
80
|
-
```
|
81
|
-
|
82
|
-
|
83
|
-
news = Whatsnew.about [Resource.new("NEWS", "https://github.com/ruby/ruby/blob/trunk/NEWS")]
|
148
|
+
```
|
149
|
+
news = Whatsnew.about "benbalter/licensee", oauth_token: "e72e16c7e42f292c6912e7710c838347ae178b4a"
|
84
150
|
|
85
151
|
news.file_name
|
86
|
-
=> "
|
152
|
+
=> "Releases"
|
87
153
|
|
88
154
|
news.file_url
|
89
|
-
=> "https://github.com/
|
155
|
+
=> "https://github.com/benbalter/licensee/releases"
|
156
|
+
|
157
|
+
news.content
|
158
|
+
=> "See https://github.com/benbalter/licensee/releases."
|
90
159
|
|
91
160
|
news.read
|
92
|
-
=> "What's New:\nSee
|
161
|
+
=> "What's New:\nSee Releases: https://github.com/benbalter/licensee/releases."
|
93
162
|
```
|
94
163
|
|
164
|
+
## Inspired by
|
95
165
|
|
96
|
-
|
97
|
-
|
98
|
-
* `CHANGELOG`, `CHANGE`, `CHANGES`, `HISTORY`, `NEWS` in the root of project (regardless of file extension).
|
99
|
-
|
100
|
-
* It doesn't search for changelog listed in README.
|
101
|
-
|
102
|
-
## Development
|
103
|
-
|
104
|
-
See [DEVELOPMENT.md](DEVELOPMENT.md).
|
166
|
+
[benbalter/licensee](https://github.com/benbalter/licensee) - A RubyGem to detect under what license a project is distributed.
|
105
167
|
|
106
168
|
## Contributing
|
107
169
|
|
108
|
-
|
109
|
-
|
110
|
-
## Inspired by
|
111
|
-
|
112
|
-
[benbalter/licensee](https://github.com/benbalter/licensee) - A RubyGem to detect under what license a project is distributed.
|
170
|
+
Please see the [CONTRIBUTING.md](/CONTRIBUTING.md) file.
|
113
171
|
|
114
172
|
## Credits
|
115
173
|
|
116
174
|
A huge THANK YOU to all our [contributors](https://github.com/jollygoodcode/whatsnew/graphs/contributors)! :heart:
|
117
175
|
|
118
|
-
This project is maintained by [Jolly Good Code](http://www.jollygoodcode.com).
|
119
|
-
|
120
176
|
## License
|
121
177
|
|
122
|
-
|
178
|
+
Please see the [LICENSE.md](/LICENSE.md) file.
|
179
|
+
|
180
|
+
## Maintained by Jolly Good Code
|
181
|
+
|
182
|
+
[](http://www.jollygoodcode.com)
|
183
|
+
|
184
|
+
We specialise in Agile practices and Ruby, and we love contributing to open source. [Speak to us](http://www.jollygoodcode.com/#get-in-touch) about your next big idea, or [check out our projects](http://www.jollygoodcode.com/open-source).
|
data/Rakefile
CHANGED
@@ -1,10 +1,4 @@
|
|
1
1
|
require "bundler/gem_tasks"
|
2
|
-
require "
|
3
|
-
|
4
|
-
|
5
|
-
t.libs << "test"
|
6
|
-
t.libs << "lib"
|
7
|
-
t.test_files = FileList["test/**/*_test.rb"]
|
8
|
-
end
|
9
|
-
|
10
|
-
task default: :test
|
2
|
+
require "rspec/core/rake_task"
|
3
|
+
RSpec::Core::RakeTask.new(:spec)
|
4
|
+
task default: [:spec]
|
data/bin/whatsnew
CHANGED
@@ -2,12 +2,8 @@
|
|
2
2
|
|
3
3
|
Signal.trap("INT") { abort }
|
4
4
|
|
5
|
-
|
5
|
+
lib_dir = File.expand_path(File.join(File.dirname(__FILE__), "..", "lib"))
|
6
|
+
$LOAD_PATH << lib_dir unless $LOAD_PATH.include?(lib_dir)
|
7
|
+
require "whatsnew/cli"
|
6
8
|
|
7
|
-
|
8
|
-
puts news.read
|
9
|
-
else
|
10
|
-
puts "Not found. Do you mind keep a changelog?"
|
11
|
-
puts "Or tell the project owner to keep a changelog :)"
|
12
|
-
puts "See http://keepachangelog.com"
|
13
|
-
end
|
9
|
+
Whatsnew::CLI.start
|
data/lib/whatsnew/cli.rb
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
require "thor"
|
2
|
+
require "whatsnew"
|
3
|
+
|
4
|
+
module Whatsnew
|
5
|
+
class CLI < Thor
|
6
|
+
desc "version", "Show Whatsnew version."
|
7
|
+
def version
|
8
|
+
say Whatsnew::VERSION
|
9
|
+
end
|
10
|
+
map %w(-v --version) => :version
|
11
|
+
|
12
|
+
desc "about", "Find changelog / releases of a given path or repo on GitHub. If no argument is given, look for current path's changelog."
|
13
|
+
option :access_token, type: :string, aliases: "-a"
|
14
|
+
def about(path_or_repo = nil)
|
15
|
+
news = Whatsnew.about path_or_repo, options[:access_token]
|
16
|
+
|
17
|
+
if news.is_a? Whatsnew::NoNewsFile
|
18
|
+
say_in_green "Not found. This project should keep a changelog."
|
19
|
+
say_in_green "Please see http://keepachangelog.com."
|
20
|
+
else
|
21
|
+
say_in_green news.read
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
|
27
|
+
def say_in_green(content)
|
28
|
+
say content, :green
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
data/lib/whatsnew/local_files.rb
CHANGED
@@ -1,21 +1,12 @@
|
|
1
|
-
require "pathname"
|
2
|
-
|
3
1
|
module Whatsnew
|
4
2
|
class LocalFiles
|
5
3
|
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
|
4
|
+
@path = path || DOT
|
10
5
|
end
|
11
6
|
|
12
7
|
def to_news_file
|
13
|
-
if news
|
14
|
-
|
15
|
-
file_name,
|
16
|
-
content: file.read,
|
17
|
-
file_url: "#{project_uri}/blob/master/#{file_name}"
|
18
|
-
)
|
8
|
+
if news = find_news_at_local
|
9
|
+
LocalNewsFile.new(news, path)
|
19
10
|
else
|
20
11
|
NoNewsFile.new
|
21
12
|
end
|
@@ -23,30 +14,12 @@ module Whatsnew
|
|
23
14
|
|
24
15
|
private
|
25
16
|
|
26
|
-
attr_reader :path
|
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
|
17
|
+
attr_reader :path
|
35
18
|
|
36
|
-
def
|
37
|
-
|
38
|
-
|
39
|
-
%r{(http://|https://|git.+)(?<host>(github.com|bitbucket.com|bitbucket.org))[:/](?<owner>\S+)/(?<repo>\S+)\.git}
|
40
|
-
)
|
19
|
+
def find_news_at_local
|
20
|
+
Dir.glob(File.join(path, STAR)).find do |local_file|
|
21
|
+
local_file =~ FILES_TO_SEARCH_REGEXP
|
41
22
|
end
|
42
23
|
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
24
|
end
|
52
25
|
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
require "pathname"
|
2
|
+
|
3
|
+
module Whatsnew
|
4
|
+
class LocalNewsFile
|
5
|
+
def initialize(news, path)
|
6
|
+
@news = news
|
7
|
+
@path = path
|
8
|
+
end
|
9
|
+
|
10
|
+
def file_name
|
11
|
+
@file_name ||= file.basename.to_s
|
12
|
+
end
|
13
|
+
|
14
|
+
def file_url
|
15
|
+
return NOT_FOUND unless news
|
16
|
+
return file.to_path unless File.exist?(File.join(path, DOT_GIT))
|
17
|
+
|
18
|
+
"https://#{matched[:host]}/#{matched[:owner]}/#{matched[:repo]}/blob/master/#{file_name}"
|
19
|
+
end
|
20
|
+
|
21
|
+
def content
|
22
|
+
file.read
|
23
|
+
end
|
24
|
+
|
25
|
+
def read
|
26
|
+
"What's New:\n" "See #{file_name}: #{file_url}."
|
27
|
+
end
|
28
|
+
|
29
|
+
private
|
30
|
+
|
31
|
+
attr_reader :news, :path
|
32
|
+
|
33
|
+
def file
|
34
|
+
@file ||= Pathname(news)
|
35
|
+
end
|
36
|
+
|
37
|
+
def matched
|
38
|
+
@matched ||= matched_from_git_config
|
39
|
+
end
|
40
|
+
|
41
|
+
def matched_from_git_config
|
42
|
+
Dir.chdir(Pathname(path).to_path) do
|
43
|
+
`git config --get remote.origin.url`.match(
|
44
|
+
%r{(http://|https://|git.+)(?<host>(github.com|bitbucket.com|bitbucket.org))[:/](?<owner>\S+)/(?<repo>\S+)\.git}.freeze
|
45
|
+
)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
data/lib/whatsnew/news_file.rb
CHANGED
@@ -1,17 +1,31 @@
|
|
1
|
-
require "pathname"
|
2
|
-
|
3
1
|
module Whatsnew
|
4
2
|
class NewsFile
|
5
|
-
|
3
|
+
def initialize(news)
|
4
|
+
@news = news
|
5
|
+
end
|
6
6
|
|
7
|
-
def
|
8
|
-
|
9
|
-
|
10
|
-
|
7
|
+
def file_name
|
8
|
+
news.name
|
9
|
+
end
|
10
|
+
|
11
|
+
def file_url
|
12
|
+
news_html_url
|
13
|
+
end
|
14
|
+
|
15
|
+
def content
|
16
|
+
"See #{file_url}."
|
11
17
|
end
|
12
18
|
|
13
19
|
def read
|
14
20
|
"What's New:\n" "See #{file_name}: #{file_url}."
|
15
21
|
end
|
22
|
+
|
23
|
+
private
|
24
|
+
|
25
|
+
attr_reader :news
|
26
|
+
|
27
|
+
def news_html_url
|
28
|
+
news.html_url
|
29
|
+
end
|
16
30
|
end
|
17
31
|
end
|
@@ -1,9 +1,5 @@
|
|
1
|
-
require "pathname"
|
2
|
-
|
3
1
|
module Whatsnew
|
4
2
|
class NoNewsFile
|
5
|
-
NOT_FOUND = "NOT FOUND".freeze
|
6
|
-
|
7
3
|
def file_name
|
8
4
|
NOT_FOUND
|
9
5
|
end
|
@@ -12,12 +8,12 @@ module Whatsnew
|
|
12
8
|
NOT_FOUND
|
13
9
|
end
|
14
10
|
|
15
|
-
def
|
16
|
-
|
11
|
+
def content
|
12
|
+
EMPTY_STRING
|
17
13
|
end
|
18
14
|
|
19
|
-
def
|
20
|
-
|
15
|
+
def read
|
16
|
+
NOT_FOUND
|
21
17
|
end
|
22
18
|
end
|
23
19
|
end
|
data/lib/whatsnew/project.rb
CHANGED
@@ -2,24 +2,28 @@ module Whatsnew
|
|
2
2
|
class Project
|
3
3
|
attr_reader :news_file
|
4
4
|
|
5
|
-
def initialize(
|
6
|
-
@
|
5
|
+
def initialize(path_or_repo, access_token = nil)
|
6
|
+
@path_or_repo = path_or_repo
|
7
|
+
@access_token = access_token
|
8
|
+
end
|
9
|
+
|
10
|
+
def news_file
|
11
|
+
return LocalFiles.new(path_or_repo).to_news_file unless path_or_repo
|
7
12
|
|
8
|
-
|
9
|
-
RemoteFiles.new(
|
13
|
+
if query_for_a_repo?
|
14
|
+
RemoteFiles.new(path_or_repo, access_token).to_news_file
|
10
15
|
else
|
11
|
-
LocalFiles.new(
|
16
|
+
LocalFiles.new(path_or_repo).to_news_file
|
12
17
|
end
|
13
18
|
end
|
14
19
|
|
15
20
|
private
|
16
21
|
|
17
|
-
attr_reader :
|
22
|
+
attr_reader :path_or_repo, :access_token
|
18
23
|
|
19
|
-
def
|
20
|
-
|
21
|
-
|
22
|
-
path_or_resources.first.respond_to?(:html_url)
|
24
|
+
def query_for_a_repo?
|
25
|
+
path_or_repo.count("/".freeze) == 1 &&
|
26
|
+
path_or_repo =~ %r(^.+/.+$).freeze
|
23
27
|
end
|
24
28
|
end
|
25
29
|
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
module Whatsnew
|
2
|
+
class ReleaseFile
|
3
|
+
def initialize(release)
|
4
|
+
@release = release
|
5
|
+
end
|
6
|
+
|
7
|
+
def file_name
|
8
|
+
"Releases".freeze
|
9
|
+
end
|
10
|
+
|
11
|
+
def file_url
|
12
|
+
release_html_url
|
13
|
+
end
|
14
|
+
|
15
|
+
def content
|
16
|
+
"See #{file_url}."
|
17
|
+
end
|
18
|
+
|
19
|
+
def read
|
20
|
+
"What's New:\n" "See #{file_name}: #{file_url}."
|
21
|
+
end
|
22
|
+
|
23
|
+
private
|
24
|
+
|
25
|
+
attr_reader :release
|
26
|
+
|
27
|
+
def release_html_url
|
28
|
+
release.html_url.sub(%r(/releases/.+), "/releases".freeze)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -1,25 +1,62 @@
|
|
1
|
+
require "octokit"
|
2
|
+
|
1
3
|
module Whatsnew
|
2
4
|
class RemoteFiles
|
3
|
-
|
4
|
-
|
5
|
-
|
5
|
+
REPO_NOT_FOUND = Class.new(Exception)
|
6
|
+
REPO_NOT_FOUND_MESSAGE = "This repository cannot be found. Specify OAuth token if this is a private repository.".freeze
|
7
|
+
INVALID_OAUTH_TOKEN = Class.new(Exception)
|
8
|
+
|
9
|
+
def initialize(repo, access_token = nil)
|
10
|
+
@repo = repo
|
11
|
+
@token =
|
12
|
+
access_token ||
|
13
|
+
ENV.fetch("OAUTH_ACCESS_TOKEN") { prints_no_token_warning }
|
14
|
+
|
15
|
+
if token && token.size != 40
|
16
|
+
abort "ERROR: OAuth token should be 40-char long.".freeze
|
6
17
|
end
|
7
18
|
end
|
8
19
|
|
9
20
|
def to_news_file
|
10
|
-
if
|
11
|
-
NewsFile.new(
|
21
|
+
if contents = find_from_contents
|
22
|
+
NewsFile.new(contents)
|
23
|
+
elsif releases = find_from_releases
|
24
|
+
ReleaseFile.new(releases)
|
12
25
|
else
|
13
26
|
NoNewsFile.new
|
14
27
|
end
|
28
|
+
rescue Octokit::NotFound
|
29
|
+
raise REPO_NOT_FOUND, REPO_NOT_FOUND_MESSAGE
|
30
|
+
rescue Octokit::Unauthorized
|
31
|
+
raise INVALID_OAUTH_TOKEN, "ERROR: Your OAuth token: #{token} is invalid or revoked."
|
15
32
|
end
|
16
33
|
|
17
34
|
private
|
18
35
|
|
19
|
-
attr_reader :
|
36
|
+
attr_reader :repo, :token
|
37
|
+
|
38
|
+
def prints_no_token_warning
|
39
|
+
puts "WARNING: No OAuth token is provided.".freeze
|
40
|
+
end
|
41
|
+
|
42
|
+
def client
|
43
|
+
@client ||= Octokit::Client.new(access_token: token)
|
44
|
+
end
|
45
|
+
|
46
|
+
def find_from_contents
|
47
|
+
if resources = client.contents(repo)
|
48
|
+
resources.find do |resource|
|
49
|
+
resource.name =~ FILES_TO_SEARCH_REGEXP
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
20
53
|
|
21
|
-
def
|
22
|
-
|
54
|
+
def find_from_releases
|
55
|
+
if resources = client.releases(repo)
|
56
|
+
resources.find do |release|
|
57
|
+
release.respond_to?(:body) && !release.body.empty?
|
58
|
+
end
|
59
|
+
end
|
23
60
|
end
|
24
61
|
end
|
25
62
|
end
|
data/lib/whatsnew/version.rb
CHANGED
data/lib/whatsnew.rb
CHANGED
@@ -1,13 +1,19 @@
|
|
1
1
|
require "whatsnew/version"
|
2
|
-
require "whatsnew/
|
2
|
+
require "whatsnew/constants"
|
3
|
+
|
4
|
+
require "whatsnew/no_news_file"
|
5
|
+
|
6
|
+
require "whatsnew/local_news_file"
|
3
7
|
require "whatsnew/local_files"
|
8
|
+
|
4
9
|
require "whatsnew/news_file"
|
5
|
-
require "whatsnew/
|
10
|
+
require "whatsnew/release_file"
|
11
|
+
require "whatsnew/remote_files"
|
12
|
+
|
6
13
|
require "whatsnew/project"
|
7
14
|
|
8
15
|
module Whatsnew
|
9
|
-
|
10
|
-
|
11
|
-
Whatsnew::Project.new(path_or_resources).news_file
|
16
|
+
def self.about(path_or_repo, access_token = nil)
|
17
|
+
Project.new(path_or_repo, access_token).news_file
|
12
18
|
end
|
13
19
|
end
|
data/whatsnew.gemspec
CHANGED
@@ -20,4 +20,7 @@ Gem::Specification.new do |spec|
|
|
20
20
|
spec.require_paths = ["lib"]
|
21
21
|
|
22
22
|
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
23
|
+
|
24
|
+
spec.add_dependency "thor", [">= 0.19.1", "< 2"]
|
25
|
+
spec.add_dependency "octokit", [">= 4.1.1", "< 5"]
|
23
26
|
end
|
metadata
CHANGED
@@ -1,15 +1,55 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: whatsnew
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Juanito Fatas
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
12
|
-
dependencies:
|
11
|
+
date: 2015-12-26 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: thor
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 0.19.1
|
20
|
+
- - "<"
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: '2'
|
23
|
+
type: :runtime
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
requirements:
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 0.19.1
|
30
|
+
- - "<"
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '2'
|
33
|
+
- !ruby/object:Gem::Dependency
|
34
|
+
name: octokit
|
35
|
+
requirement: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - ">="
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: 4.1.1
|
40
|
+
- - "<"
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
version: '5'
|
43
|
+
type: :runtime
|
44
|
+
prerelease: false
|
45
|
+
version_requirements: !ruby/object:Gem::Requirement
|
46
|
+
requirements:
|
47
|
+
- - ">="
|
48
|
+
- !ruby/object:Gem::Version
|
49
|
+
version: 4.1.1
|
50
|
+
- - "<"
|
51
|
+
- !ruby/object:Gem::Version
|
52
|
+
version: '5'
|
13
53
|
description: Find out what's new about a project
|
14
54
|
email:
|
15
55
|
- katehuang0320@gmail.com
|
@@ -19,10 +59,10 @@ extensions: []
|
|
19
59
|
extra_rdoc_files: []
|
20
60
|
files:
|
21
61
|
- ".gitignore"
|
62
|
+
- ".rspec"
|
22
63
|
- ".travis.yml"
|
23
64
|
- CHANGELOG.md
|
24
65
|
- CONTRIBUTING.md
|
25
|
-
- DEVELOPMENT.md
|
26
66
|
- Gemfile
|
27
67
|
- LICENSE.md
|
28
68
|
- README.md
|
@@ -30,10 +70,14 @@ files:
|
|
30
70
|
- bin/dev
|
31
71
|
- bin/whatsnew
|
32
72
|
- lib/whatsnew.rb
|
73
|
+
- lib/whatsnew/cli.rb
|
74
|
+
- lib/whatsnew/constants.rb
|
33
75
|
- lib/whatsnew/local_files.rb
|
76
|
+
- lib/whatsnew/local_news_file.rb
|
34
77
|
- lib/whatsnew/news_file.rb
|
35
78
|
- lib/whatsnew/no_news_file.rb
|
36
79
|
- lib/whatsnew/project.rb
|
80
|
+
- lib/whatsnew/release_file.rb
|
37
81
|
- lib/whatsnew/remote_files.rb
|
38
82
|
- lib/whatsnew/version.rb
|
39
83
|
- whatsnew.gemspec
|
@@ -57,9 +101,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
57
101
|
version: '0'
|
58
102
|
requirements: []
|
59
103
|
rubyforge_project:
|
60
|
-
rubygems_version: 2.4.
|
104
|
+
rubygems_version: 2.4.5.1
|
61
105
|
signing_key:
|
62
106
|
specification_version: 4
|
63
107
|
summary: Find out what's new about a project
|
64
108
|
test_files: []
|
65
|
-
has_rdoc:
|