badgerbadgerbadger 0.3.1 → 0.4.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: 63132b8d500ee333f3fe6863f0400946fbc5eb9e
4
- data.tar.gz: fd48a9db56e240b6ed0ce88f56a79f829148b8ce
3
+ metadata.gz: 6c290bb11da1c9bd67b11daa9f0dd1a734dce612
4
+ data.tar.gz: 5262999603b13416c27d83bf98de0d25b9a31883
5
5
  SHA512:
6
- metadata.gz: 804a07ca25f61c6f6f903606a7bceb37e25371ac039e7fdf7f1db96dca00c57f62de06169d305194279d5617940641955968ad0ae09f68673a30c47d63aae591
7
- data.tar.gz: 87dce7e9fc0b1de21375cf7a54d45ab40372765b95d5ff0d68ebf05ce5ee98d6690bcff85b1a466a9e9feb0d6afd508b231540187d9c9d1f7526ed1883aec1a7
6
+ metadata.gz: 3fb86368c205671bf9e6d4a6107b31c5a4223740efb16054aed7491c97cd750ca3aaf20413784440a924d1b53e956ada96314613670acbfef2f2adec1f41e563
7
+ data.tar.gz: 96141314900a00beb62b70384f288b800cba8dcdd86f4491b3ad384b21a69075f233ea5212c126abc8a9729a4aa66a79b7a5c7222c27d17e8a5ea7b9b284df9d
data/.gitignore CHANGED
@@ -15,4 +15,5 @@ spec/reports
15
15
  test/tmp
16
16
  test/version_tmp
17
17
  tmp
18
- .idea
18
+ .idea
19
+ TODO
@@ -0,0 +1 @@
1
+ badge_service: img.shields.io
@@ -0,0 +1,22 @@
1
+ # license_name: - as found in a gemspec
2
+ # url: - where the license lives
3
+ # regex: - text to look for in the license file
4
+ # badge-text: - text to use in the generated badge, if different from license_name
5
+
6
+ mit:
7
+ url: http://%s.mit-license.org
8
+ regex: The MIT License
9
+
10
+ apache:
11
+ url: http://www.apache.org/licenses/LICENSE-2.0.html
12
+ regex: Apache License
13
+
14
+ gpl-2.0:
15
+ url: http://www.gnu.org/licenses/gpl-2.0.html
16
+ badge_text: gpl2
17
+ regex: GNU GENERAL PUBLIC LICENSE.*Version 2
18
+
19
+ gpl-3.0:
20
+ url: http://www.gnu.org/licenses/gpl-3.0.html
21
+ badge_text: gpl3
22
+ regex: GNU GENERAL PUBLIC LICENSE.*Version 3/
@@ -1,29 +1,26 @@
1
- services:
2
- defaults:
3
- travis:
4
- alt_text: Build Status
5
- url: travis-ci.org
6
- badge_slug: travis
1
+ defaults:
2
+ travis:
3
+ alt_text: Build Status
4
+ url: travis-ci.org
5
+ badge_slug: travis
7
6
 
8
- coveralls:
9
- alt_text: Coverage Status
10
- url: coveralls.io/r
11
- badge_slug: coveralls
7
+ coveralls:
8
+ alt_text: Coverage Status
9
+ url: coveralls.io/r
10
+ badge_slug: coveralls
12
11
 
13
- gemnasium:
14
- alt_text: Dependency Status
15
- url: gemnasium.com
16
- badge_slug: gemnasium
12
+ gemnasium:
13
+ alt_text: Dependency Status
14
+ url: gemnasium.com
15
+ badge_slug: gemnasium
17
16
 
18
- codeclimate:
19
- alt_text: Code Climate
20
- url: codeclimate.com/github
21
- badge_slug: codeclimate/github
17
+ codeclimate:
18
+ alt_text: Code Climate
19
+ url: codeclimate.com/github
20
+ badge_slug: codeclimate/github
22
21
 
23
- extras:
24
- mit:
25
- alt_text: License
26
- badge_path: ":license-mit-blue.svg"
27
- url: http://%s.mit-license.org
28
-
29
- badge_service: img.shields.io
22
+ extras:
23
+ mit:
24
+ alt_text: License
25
+ badge_path: ":license-mit-blue.svg"
26
+ url: http://%s.mit-license.org
@@ -58,16 +58,16 @@ Feature: Badge Robot
58
58
  [![Code Climate](http://img.shields.io/codeclimate/github/doge/wow.svg)](https://codeclimate.com/github/doge/wow)
59
59
  """
60
60
 
61
- Scenario: Generate additional badges
62
- When I successfully run `badger badge --also mit /tmp/wow_repo`
63
- Then the output should contain:
64
- """
65
- [![Build Status](http://img.shields.io/travis/doge/wow.svg)](https://travis-ci.org/doge/wow)
66
- [![Coverage Status](http://img.shields.io/coveralls/doge/wow.svg)](https://coveralls.io/r/doge/wow)
67
- [![Dependency Status](http://img.shields.io/gemnasium/doge/wow.svg)](https://gemnasium.com/doge/wow)
68
- [![Code Climate](http://img.shields.io/codeclimate/github/doge/wow.svg)](https://codeclimate.com/github/doge/wow)
69
- [![License](http://img.shields.io/:license-mit-blue.svg)](http://doge.mit-license.org)
70
- """
61
+ # Scenario: Generate additional badges
62
+ # When I successfully run `badger badge --also mit /tmp/wow_repo`
63
+ # Then the output should contain:
64
+ # """
65
+ #[![Build Status](http://img.shields.io/travis/doge/wow.svg)](https://travis-ci.org/doge/wow)
66
+ #[![Coverage Status](http://img.shields.io/coveralls/doge/wow.svg)](https://coveralls.io/r/doge/wow)
67
+ #[![Dependency Status](http://img.shields.io/gemnasium/doge/wow.svg)](https://gemnasium.com/doge/wow)
68
+ #[![Code Climate](http://img.shields.io/codeclimate/github/doge/wow.svg)](https://codeclimate.com/github/doge/wow)
69
+ #[![License](http://img.shields.io/:license-mit-blue.svg)](http://doge.mit-license.org)
70
+ # """
71
71
 
72
72
  @gemspec
73
73
  Scenario: Generate badges based on gemspec
@@ -82,14 +82,14 @@ Feature: Badge Robot
82
82
  [![License](http://img.shields.io/:license-mit-blue.svg)](http://doge.mit-license.org)
83
83
  """
84
84
 
85
- @gemspec
86
- Scenario: gemspec and --also mit
87
- Given I successfully run `badger badge --also mit /tmp/wow_repo`
88
- Then the output should not contain:
89
- """
90
- [![License](http://img.shields.io/:license-mit-blue.svg)](http://doge.mit-license.org)
91
- [![License](http://img.shields.io/:license-mit-blue.svg)](http://doge.mit-license.org)
92
- """
85
+ # @gemspec
86
+ # Scenario: gemspec and --also mit
87
+ # Given I successfully run `badger badge --also mit /tmp/wow_repo`
88
+ # Then the output should not contain:
89
+ # """
90
+ #[![License](http://img.shields.io/:license-mit-blue.svg)](http://doge.mit-license.org)
91
+ #[![License](http://img.shields.io/:license-mit-blue.svg)](http://doge.mit-license.org)
92
+ # """
93
93
 
94
94
  Scenario: handle a non-git-repo gracefully
95
95
  When I run `badger badge /tmp`
@@ -0,0 +1,45 @@
1
+ Feature: Badge Robot
2
+
3
+ Background:
4
+ Given git remote is "https://github.com/doge/wow.git"
5
+
6
+ @license @mit
7
+ Scenario: Generate MIT license
8
+ When I successfully run `badger badge /tmp/wow_repo`
9
+ Then the output should contain:
10
+ """
11
+ ![License](http://img.shields.io/:license-mit-blue.svg)](http://doge.mit-license.org)
12
+ """
13
+ And the output should not contain:
14
+ """
15
+ Apache
16
+ """
17
+ And the output should not contain:
18
+ """
19
+ ![License](http://img.shields.io/:license-mit-blue.svg)](http://doge.mit-license.org)
20
+ ![License](http://img.shields.io/:license-mit-blue.svg)](http://doge.mit-license.org)
21
+ """
22
+
23
+ @license @apache
24
+ Scenario: Generate Apache license
25
+ When I successfully run `badger badge /tmp/wow_repo`
26
+ Then the output should contain:
27
+ """
28
+ ![License](http://img.shields.io/:license-apache-blue.svg)](http://www.apache.org/licenses/LICENSE-2.0.html)
29
+ """
30
+ And the output should not contain:
31
+ """
32
+ GPL
33
+ """
34
+
35
+ @license @gpl2
36
+ Scenario: Generate GPL2 license
37
+ When I successfully run `badger badge /tmp/wow_repo`
38
+ Then the output should contain:
39
+ """
40
+ ![License](http://img.shields.io/:license-gpl2-blue.svg)](http://www.gnu.org/licenses/gpl-2.0.html)
41
+ """
42
+ And the output should not contain:
43
+ """
44
+ MIT
45
+ """
@@ -23,6 +23,32 @@ Before '@no-remote' do
23
23
  end
24
24
 
25
25
  After '@no-remote' do
26
- # FileUtils.remove_dir '/tmp/not_wow', :force => true
26
+ FileUtils.remove_dir '/tmp/not_wow', :force => true
27
27
  end
28
28
 
29
+ Before '@mit' do
30
+ f = File.open '/tmp/wow_repo/LICENSE.md', 'w'
31
+ f.write "The MIT License (MIT)\n"
32
+ f.close
33
+ end
34
+
35
+ Before '@apache' do
36
+ f = File.open '/tmp/wow_repo/LICENSE.md', 'w'
37
+ f.write "Apache License\n"
38
+ f.write "Version 2.0\n"
39
+ f.close
40
+ end
41
+
42
+ Before '@gpl2' do
43
+ f = File.open '/tmp/wow_repo/LICENSE.md', 'w'
44
+ f.write "GNU GENERAL PUBLIC LICENSE\n"
45
+ f.write "Version 2\n"
46
+ f.close
47
+ end
48
+
49
+ Before '@gpl3' do
50
+ f = File.open '/tmp/wow_repo/LICENSE.md', 'w'
51
+ f.write "GNU GENERAL PUBLIC LICENSE\n"
52
+ f.write "Version 3\n"
53
+ f.close
54
+ end
@@ -3,6 +3,7 @@ require 'git'
3
3
  require 'badger/version'
4
4
  require 'badger/badger'
5
5
  require 'badger/service'
6
+ require 'badger/license'
6
7
 
7
8
  module Badger
8
9
 
@@ -2,32 +2,31 @@ require 'yaml'
2
2
 
3
3
  module Badger
4
4
  class Badger
5
+ attr_reader :licenses, :badge_service
6
+
5
7
  def initialize url
6
8
  @github_slug = github_slug url
7
9
  @blacklist = []
8
10
 
9
- yaml = YAML.load(
10
- File.open(
11
- File.join(
12
- File.dirname(__FILE__),
13
- '..',
14
- '..',
15
- 'config/services.yaml'
16
- )
17
- )
18
- )
19
-
20
- @services = yaml['services']['defaults']
21
- @extras = yaml['services']['extras']
22
- @badge_service = yaml['badge_service']
23
- @extra_badges = []
11
+ @licenses = YAML.load(File.open(File.join(File.dirname(__FILE__), '..', '..', 'config/licenses.yaml')))
12
+ yaml = YAML.load(File.open(File.join(File.dirname(__FILE__), '..', '..', 'config/services.yaml')))
13
+ @services = yaml['defaults']
14
+ @extras = yaml['extras']
15
+ @config = YAML.load(File.open(File.join(File.dirname(__FILE__), '..', '..', 'config/config.yaml')))
16
+
17
+ @badge_service = @config['badge_service']
24
18
 
19
+ @extra_badges = []
25
20
  end
26
21
 
27
22
  def github_slug url
28
23
  @github_slug ||= /.*github\.com.(.*)\.git/.match(url)[1]
29
24
  end
30
25
 
26
+ def owner
27
+ @owner ||= @github_slug.split('/')[0]
28
+ end
29
+
31
30
  def badge
32
31
  s = []
33
32
  @services.each_pair do |k, h|
@@ -47,6 +46,11 @@ module Badger
47
46
  s.uniq
48
47
  end
49
48
 
49
+ def license type
50
+ @license = License.new self, type
51
+ @extra_badges << @license.badge
52
+ end
53
+
50
54
  def remove items
51
55
  items = [items] unless items.class.name == 'Array'
52
56
  items.each do |item|
@@ -68,20 +72,10 @@ module Badger
68
72
  items = [items] unless items.class.name == 'Array'
69
73
  s = ''
70
74
  items.each do |item|
71
-
72
- if @extras[item]
73
- e = @extras[item]
74
-
75
- owner = @github_slug.split('/')[0]
76
- t = e['url'] % owner
77
- s = "[![%s](http://%s/%s)](%s)" % [
78
- e['alt_text'],
79
- @badge_service,
80
- e['badge_path'],
81
- t
82
- ]
75
+ if @licenses[item]
76
+ @license = License.new self, item
77
+ s << @license.badge
83
78
  end
84
-
85
79
  @extra_badges << s
86
80
  end
87
81
  end
@@ -97,17 +91,15 @@ module Badger
97
91
 
98
92
  @extra_badges << rg
99
93
 
100
- lc = ''
101
- owner = @github_slug.split('/')[0]
102
- license = (lines.select { |l| /license/.match l })[0].split(/\s/)[-1]
103
- if /MIT/i.match license
104
- lc << "[![License](http://%s/:license-mit-blue.svg)](http://%s.mit-license.org)" % [
105
- @badge_service,
106
- owner
107
- ]
94
+ spec_license = (lines.select { |l| /license/.match l })[0].split(/\s/)[-1][1..-2]
108
95
 
109
- @extra_badges << lc
96
+ @licenses.each_pair do |k, v|
97
+ if /#{k}/im.match spec_license
98
+ @license = License.new self, spec_license
99
+ end
110
100
  end
101
+
102
+ @extra_badges << @license.badge
111
103
  end
112
104
 
113
105
  def to_s
@@ -15,21 +15,28 @@ Generates badges for Github READMEs. The default services are:
15
15
 
16
16
  * Gemnasium
17
17
 
18
- Extra badges: currently only one extra badge is supported, a link to the MIT license from here: https://github.com/remy/mit-license, e.g.
18
+ If a gemspec is found, the following badges will also be generated:
19
19
 
20
- [![License](http://img.shields.io/:license-mit-blue.svg)](http://doge.mit-license.org)
20
+ * [License] badge, linking to the appropriate license
21
21
 
22
+ * [Gem version] badge, linking to rubygems.org
22
23
 
23
- If a gemspec is found, the following badges will also be generated:
24
+ If a license file is found, a license badge will be generated. Currently supported licenses are:
24
25
 
25
- * [License: MIT] badge (presuming an MIT license is specified, linked as above)
26
+ * MIT
27
+
28
+ * Apache
29
+
30
+ * GPL-2
31
+
32
+ * GPL-3
33
+
34
+ The supported license details are in https://github.com/pikesley/badger/blob/master/config/licenses.yaml, if you're using a different license, send a PR! And if your gemspec license conflicts with your LICENSE file, you should probably fix that.
26
35
 
27
- * [Gem version] badge, linking to rubygems.org
28
36
 
29
37
  LONGDESC
30
38
  option :not, desc: 'Exclude these services (comma-separated list)'
31
39
  option :only, desc: 'Generate for *only* these services (comma-separated list)'
32
- option :also, desc: 'Include this extra service (currently only \'mit\')'
33
40
 
34
41
  def badge dir = '.'
35
42
  begin
@@ -57,6 +64,17 @@ If a gemspec is found, the following badges will also be generated:
57
64
  @badger.gemspec lines
58
65
  end
59
66
 
67
+ license_file = (Dir.entries dir).select { |i| /LICENSE/i.match i }[0]
68
+
69
+ if license_file
70
+ words = File.open(File.join(dir, license_file), 'r').read
71
+ @badger.licenses.each_pair do |k, v|
72
+ if /#{v['regex']}/im.match words
73
+ @badger.license k
74
+ end
75
+ end
76
+ end
77
+
60
78
  puts @badger.to_s
61
79
  end
62
80
 
@@ -0,0 +1,27 @@
1
+ module Badger
2
+ class License
3
+ def initialize badger, type
4
+ @badger = badger
5
+ @type = type.downcase
6
+ end
7
+
8
+ def badge
9
+ return nil unless config = @badger.licenses[@type]
10
+
11
+ @url = config['url']
12
+ if /%s/.match @url
13
+ @url = @url % @badger.owner
14
+ end
15
+
16
+ badge_text = @type unless badge_text = config['badge_text']
17
+
18
+ s = "[![License](http://%s/:license-%s-blue.svg)](%s)" % [
19
+ @badger.badge_service,
20
+ badge_text,
21
+ @url
22
+ ]
23
+
24
+ s
25
+ end
26
+ end
27
+ end
@@ -1,3 +1,3 @@
1
1
  module Badger
2
- VERSION = "0.3.1"
2
+ VERSION = "0.4.0"
3
3
  end
@@ -14,6 +14,10 @@ module Badger
14
14
  it 'for an ssh url' do
15
15
  @badger.github_slug('git@github.com:doge/wow.git').should eql('doge/wow')
16
16
  end
17
+
18
+ it 'should have the owner' do
19
+ @badger.owner.should eql 'doge'
20
+ end
17
21
  end
18
22
 
19
23
  it 'should generate a badge list' do
@@ -64,5 +68,27 @@ module Badger
64
68
  @badger.badge[5].should == "[![License](http://img.shields.io/:license-mit-blue.svg)](http://doge.mit-license.org)"
65
69
  end
66
70
  end
71
+
72
+ context 'licenses' do
73
+ it 'should generate an MIT badge' do
74
+ @badger.license 'mit'
75
+ @badger.badge[4].should == "[![License](http://img.shields.io/:license-mit-blue.svg)](http://doge.mit-license.org)"
76
+ end
77
+
78
+ it 'should generate an Apache badge' do
79
+ @badger.license 'apache'
80
+ @badger.badge[4].should == "[![License](http://img.shields.io/:license-apache-blue.svg)](http://www.apache.org/licenses/LICENSE-2.0.html)"
81
+ end
82
+
83
+ it 'should generate a GPL3 badge' do
84
+ @badger.license 'gpl-3.0'
85
+ @badger.badge[4].should == "[![License](http://img.shields.io/:license-gpl3-blue.svg)](http://www.gnu.org/licenses/gpl-3.0.html)"
86
+ end
87
+
88
+ it 'should generate nothing for an unknown license' do
89
+ @badger.license 'doge-license'
90
+ @badger.badge[4].should == nil
91
+ end
92
+ end
67
93
  end
68
94
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: badgerbadgerbadger
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - pikesley
@@ -211,14 +211,18 @@ files:
211
211
  - Rakefile
212
212
  - badger.gemspec
213
213
  - bin/badger
214
+ - config/config.yaml
215
+ - config/licenses.yaml
214
216
  - config/services.yaml
215
217
  - features/badger.feature
218
+ - features/licenses.feature
216
219
  - features/step_definitions/badger_steps.rb
217
220
  - features/support/env.rb
218
221
  - features/support/hooks.rb
219
222
  - lib/badger.rb
220
223
  - lib/badger/badger.rb
221
224
  - lib/badger/cli.rb
225
+ - lib/badger/license.rb
222
226
  - lib/badger/service.rb
223
227
  - lib/badger/version.rb
224
228
  - spec/badger_spec.rb
@@ -250,6 +254,7 @@ summary: Badge-Driven Development made easy. Generate a set of Github badges for
250
254
  project without cutting-n-pasting every time
251
255
  test_files:
252
256
  - features/badger.feature
257
+ - features/licenses.feature
253
258
  - features/step_definitions/badger_steps.rb
254
259
  - features/support/env.rb
255
260
  - features/support/hooks.rb