Skip to content

Commit 12cffbb

Browse files
committed
remove existing changeLog'd API integration
- support existing badges
1 parent ef630be commit 12cffbb

File tree

3 files changed

+6
-100
lines changed

3 files changed

+6
-100
lines changed

app/models/badges/changelogd.rb

Lines changed: 2 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
# TODO: broken
2-
!class Changelogd < BadgeBase
1+
class Changelogd < BadgeBase
32
describe "Changelog'd",
43
skill: 'Open Source',
54
description: "Have an original repo featured on the Changelog show",
@@ -8,72 +7,8 @@
87
weight: 2,
98
providers: :github
109

11-
API_URI = "http://thechangelog.com/api/read" # tagged=episode & tagged=github
12-
REPO = /([http|https]*:\/\/github\.com\/[\w | \-]*\/[\w | \-]*)/i
13-
USERNAME = /github\.com\/([\w | \-]*)\/[\w | \-]*/i
14-
REPO_NAME = /github\.com\/[\S|\D]*\/([\S|\D]*)/i
15-
16-
def reasons
17-
@reasons ||= begin
18-
links = user.facts.select do |fact|
19-
fact.tagged?('changedlog')
20-
end.collect do |fact|
21-
begin
22-
match = fact.url.match(REPO_NAME)
23-
{ match[1] => fact.url }
24-
rescue
25-
{ fact.url => fact.url }
26-
end
27-
end
28-
{ links: links }
29-
end
30-
end
31-
3210
def award?
33-
!reasons[:links].empty?
11+
false
3412
end
3513

36-
class << self
37-
def perform
38-
create_assignments! all_repos
39-
end
40-
41-
def quick_refresh
42-
create_assignments! latest_repos
43-
end
44-
45-
def refresh
46-
perform
47-
end
48-
49-
def create_assignments!(repos)
50-
repos.each do |repo_url|
51-
match = repo_url.match(USERNAME)
52-
break if match.nil?
53-
github_username = match[1]
54-
Fact.append!("#{repo_url}:changedlogd", "github:#{github_username}", "Repo featured on Changelogd", Time.now, repo_url, ['repo', 'changedlog'])
55-
end
56-
end
57-
58-
def latest_repos
59-
repos_in(API_URI).flatten.uniq
60-
end
61-
62-
def all_repos
63-
repos = []
64-
(1...20).each do |time|
65-
start = ((time * 50) + 1) - 50
66-
repos << repos_in(API_URI + "?start=#{start}&num=50")
67-
end
68-
repos.flatten.uniq
69-
end
70-
71-
def repos_in(url)
72-
res = Servant.get(url)
73-
doc = Nokogiri::HTML(res.to_s)
74-
doc.xpath('//post/link-description').collect do |element|
75-
element.content.scan(REPO)
76-
end
77-
end
78-
end
7914
end

lib/tasks/facts.rake

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
namespace :facts do
22
# PRODUCTION: RUNS DAILY
33
task system: :environment do
4-
puts "Changelogd"
5-
Changelogd.refresh
64
puts "Ashcat"
75
Ashcat.perform
86
end

spec/models/badges/changelogd_spec.rb

Lines changed: 4 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,13 @@
11
require 'spec_helper'
22

3-
RSpec.describe Changelogd, type: :model, skip: true do
4-
it 'should award a user if there is a tag' do
5-
stub_request(:get, Changelogd::API_URI).to_return(body: File.read(File.join(Rails.root, 'spec', 'fixtures', 'changelogd_feed.xml')))
6-
Changelogd.quick_refresh
7-
8-
user = Fabricate(:user, github: 'CloudMade')
9-
10-
changelogd = Changelogd.new(user)
11-
expect(changelogd.award?).to eq(true)
12-
expect(changelogd.reasons[:links].first['Leaflet']).to eq('http://github.com/CloudMade/Leaflet')
13-
end
14-
3+
RSpec.describe Changelogd, type: :model do
154
it 'should have a name and description' do
165
expect(Changelogd.name).not_to be_blank
176
expect(Changelogd.description).not_to be_blank
187
end
198

20-
it 'should should find github projects' do
21-
stub_request(:get, Changelogd::API_URI).to_return(body: File.read(File.join(Rails.root, 'spec', 'fixtures', 'changelogd_feed.xml')))
22-
expect(Changelogd.latest_repos.first).to eq('http://github.com/CloudMade/Leaflet')
23-
end
24-
25-
it 'should create a fact' do
26-
stub_request(:get, Changelogd::API_URI).to_return(body: File.read(File.join(Rails.root, 'spec', 'fixtures', 'changelogd_feed.xml')))
27-
Changelogd.quick_refresh
28-
fact = Fact.where(identity: 'http://github.com/CloudMade/Leaflet:changedlogd').first
29-
expect(fact).not_to be_nil
30-
end
31-
32-
it 'should find the first and last project', functional: true, slow: true, skip: 'resource not found' do
33-
expect(Changelogd.all_repos).to include('http://github.com/kennethreitz/tablib')
34-
expect(Changelogd.all_repos).to include('http://github.com/johnsheehan/RestSharp')
35-
end
36-
37-
it 'should find repos in episodes too', functional: true, skip: 'resource not found' do
38-
expect(Changelogd.all_repos).to include('https://github.com/geemus/excon')
9+
it 'is not awardable' do
10+
user = Fabricate(:user, github: 'codebender')
11+
expect(Changelogd.new(user).award?).to be false
3912
end
4013
end

0 commit comments

Comments
 (0)