Skip to content

Commit

Permalink
Merge 200157a into bc86ee9
Browse files Browse the repository at this point in the history
  • Loading branch information
Sam Pikesley committed Jan 2, 2015
2 parents bc86ee9 + 200157a commit 1c46c9a
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 24 deletions.
12 changes: 12 additions & 0 deletions config/services.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,15 @@ codeclimate:
alt_text: Code Climate
url_path: codeclimate.com/github
badge_slug: codeclimate/github

pulls:
alt_text: Pending Pull-Requests
service_root: githubbadges.herokuapp.com
url_path: github.com
suffix: pulls

issues:
alt_text: Github Issues
service_root: githubbadges.herokuapp.com
url_path: github.com
suffix: issues
8 changes: 1 addition & 7 deletions lib/badger/badger.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,7 @@ def owner
end

def add service
if service == 'issues'
self << Badger.badge('Github Issues', "http://githubbadges.herokuapp.com/#{github_slug}/issues", "https://github.com/#{github_slug}/issues")
elsif service == 'pulls'
self << Badger.badge('Pending Pull-Requests', "http://githubbadges.herokuapp.com/#{github_slug}/pulls", "https://github.com/#{github_slug}/pulls")
else
self << Service.badge(service, github_slug)
end
self << Service.badge(service, github_slug)
self.delete nil
end

Expand Down
44 changes: 28 additions & 16 deletions lib/badger/service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,29 +5,41 @@ def self.badge name, github_slug
params = Config.instance.services[name]

scheme = params['scheme'] ||= 'http'
case params['offers_svg']
when true
base_url = '%s://%s' % [
scheme,
params['url_path']
]
else
base_url = 'http://%s/%s' % [
Config.instance.config['badge_service'],
params['badge_slug']
]

if params['service_root']
base_url = 'http://%s' % [
params['service_root']
]
else
base_url = 'http://%s/%s' % [
Config.instance.config['badge_service'],
params['badge_slug']
]
end

badge_url = '%s/%s' % [
base_url,
github_slug
base_url,
github_slug
]

target_url = 'https://%s/%s' % [
params['url_path'],
github_slug
params['url_path'],
github_slug
]

if params['suffix']
badge_url = suffixify badge_url, params['suffix']
target_url = suffixify target_url, params['suffix']
end

Badger.badge params['alt_text'], badge_url, target_url
end

def self.suffixify path, suffix
'%s/%s' % [
path,
suffix
]
end
end
end
end
2 changes: 1 addition & 1 deletion lib/badger/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module Badger
VERSION = "0.10.1"
VERSION = "0.10.2"
end
7 changes: 7 additions & 0 deletions spec/badger_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,13 @@ module Badger
end
end

context 'github pulls' do
it 'should have a pull-requests badge' do
@badger.add 'pulls'
expect(@badger[0]).to eq "[![Pending Pull-Requests](http://githubbadges.herokuapp.com/doge/wow/pulls.svg)](https://github.com/doge/wow/pulls)"
end
end

context 'output' do
it 'should produce some lines of text' do
@badger.add 'travis'
Expand Down

0 comments on commit 1c46c9a

Please sign in to comment.