Commit 2b2d1d9f690355a7c7d3f83ecf323802ce4dcede

Authored by Nathan Broadbent
1 parent 14a18a0c
Exists in master and in 1 other branch production

Renamed :github_url field to :github_repo in App model. (with implicit https://github.com/)

app/helpers/notices_helper.rb
@@ -11,7 +11,7 @@ module NoticesHelper @@ -11,7 +11,7 @@ module NoticesHelper
11 def link_to_source_file(app, line, &block) 11 def link_to_source_file(app, line, &block)
12 text = capture_haml(&block) 12 text = capture_haml(&block)
13 if in_app_backtrace_line?(line) 13 if in_app_backtrace_line?(line)
14 - return link_to_github(app, line, text) if app.github_url? 14 + return link_to_github(app, line, text) if app.github_repo?
15 if app.issue_tracker && app.issue_tracker.respond_to?(:url_to_file) 15 if app.issue_tracker && app.issue_tracker.respond_to?(:url_to_file)
16 # Return link to file on tracker if issue tracker supports this 16 # Return link to file on tracker if issue tracker supports this
17 return link_to_issue_tracker_file(app, line, text) 17 return link_to_issue_tracker_file(app, line, text)
app/models/app.rb
@@ -4,7 +4,7 @@ class App @@ -4,7 +4,7 @@ class App
4 4
5 field :name, :type => String 5 field :name, :type => String
6 field :api_key 6 field :api_key
7 - field :github_url 7 + field :github_repo
8 field :resolve_errs_on_deploy, :type => Boolean, :default => false 8 field :resolve_errs_on_deploy, :type => Boolean, :default => false
9 field :notify_all_users, :type => Boolean, :default => false 9 field :notify_all_users, :type => Boolean, :default => false
10 field :notify_on_errs, :type => Boolean, :default => true 10 field :notify_on_errs, :type => Boolean, :default => true
@@ -28,7 +28,7 @@ class App @@ -28,7 +28,7 @@ class App
28 has_many :problems, :inverse_of => :app, :dependent => :destroy 28 has_many :problems, :inverse_of => :app, :dependent => :destroy
29 29
30 before_validation :generate_api_key, :on => :create 30 before_validation :generate_api_key, :on => :create
31 - before_save :normalize_github_url 31 + before_save :normalize_github_repo
32 after_update :store_cached_attributes_on_problems 32 after_update :store_cached_attributes_on_problems
33 33
34 validates_presence_of :name, :api_key 34 validates_presence_of :name, :api_key
@@ -112,14 +112,19 @@ class App @@ -112,14 +112,19 @@ class App
112 alias :notify_on_deploys? :notify_on_deploys 112 alias :notify_on_deploys? :notify_on_deploys
113 113
114 114
115 - def github_url?  
116 - self.github_url.present? 115 + def github_repo?
  116 + self.github_repo.present?
  117 + end
  118 +
  119 + def github_url
  120 + "https://github.com/#{github_repo}" if github_repo?
117 end 121 end
118 122
119 def github_url_to_file(file) 123 def github_url_to_file(file)
120 - "#{self.github_url}/blob/master#{file}" 124 + "#{github_url}/blob/master#{file}"
121 end 125 end
122 126
  127 +
123 def issue_tracker_configured? 128 def issue_tracker_configured?
124 !!(issue_tracker && issue_tracker.class < IssueTracker && issue_tracker.project_id.present?) 129 !!(issue_tracker && issue_tracker.class < IssueTracker && issue_tracker.project_id.present?)
125 end 130 end
@@ -167,11 +172,11 @@ class App @@ -167,11 +172,11 @@ class App
167 end 172 end
168 end 173 end
169 174
170 - def normalize_github_url  
171 - return if self.github_url.blank?  
172 - self.github_url.gsub!(%r{^http://|git@}, 'https://')  
173 - self.github_url.gsub!(/github\.com:/, 'github.com/')  
174 - self.github_url.gsub!(/\.git$/, '') 175 + def normalize_github_repo
  176 + return if github_repo.blank?
  177 + github_repo.strip!
  178 + github_repo.sub!(/(git@|https?:\/\/)github\.com(\/|:)/, '')
  179 + github_repo.sub!(/\.git$/, '')
175 end 180 end
176 end 181 end
177 182
app/views/apps/_fields.html.haml
@@ -5,8 +5,8 @@ @@ -5,8 +5,8 @@
5 = f.text_field :name 5 = f.text_field :name
6 6
7 %div 7 %div
8 - = f.label :github_url  
9 - = f.text_field :github_url 8 + = f.label :github_repo
  9 + = f.text_field :github_repo, :placeholder => "errbit/errbit from https://github.com/errbit/errbit"
10 10
11 %fieldset 11 %fieldset
12 %legend Notifications 12 %legend Notifications
app/views/apps/show.html.haml
@@ -41,7 +41,7 @@ @@ -41,7 +41,7 @@
41 %td 41 %td
42 %em Sadly, no one is watching this app 42 %em Sadly, no one is watching this app
43 43
44 -- if @app.github_url? 44 +- if @app.github_repo?
45 %h3#repository_toggle 45 %h3#repository_toggle
46 Repository 46 Repository
47 %span.click_span (show/hide) 47 %span.click_span (show/hide)
@@ -49,10 +49,10 @@ @@ -49,10 +49,10 @@
49 %table.repository 49 %table.repository
50 %thead 50 %thead
51 %tr 51 %tr
52 - %th GitHub 52 + %th GitHub Repo
53 %tbody 53 %tbody
54 %tr 54 %tr
55 - %td= link_to(@app.github_url, @app.github_url, :target => '_blank') 55 + %td= link_to(@app.github_repo, @app.github_url, :target => '_blank')
56 56
57 %h3#deploys_toggle 57 %h3#deploys_toggle
58 Latest Deploys 58 Latest Deploys
db/migrate/20120603112130_change_github_url_to_github_repo.rb 0 → 100644
@@ -0,0 +1,18 @@ @@ -0,0 +1,18 @@
  1 +class ChangeGithubUrlToGithubRepo < Mongoid::Migration
  2 + def self.up
  3 + App.collection.update({}, {'$rename' => {'github_url' => 'github_repo'}}, multi: true, safe: true)
  4 + App.all.each do |app|
  5 + app.send :normalize_github_repo
  6 + app.save!
  7 + end
  8 + end
  9 +
  10 + def self.down
  11 + App.collection.update({}, {'$rename' => {'github_repo' => 'github_url'}}, multi: true, safe: true)
  12 + App.all.each do |app|
  13 + unless app.github_repo.include?("github.com")
  14 + app.update_attribute :github_url, "https://github.com/" << app.github_url
  15 + end
  16 + end
  17 + end
  18 +end
lib/overrides/hoptoad_notifier/hoptoad_notifier.rb
@@ -9,10 +9,8 @@ HoptoadNotifier.module_eval do @@ -9,10 +9,8 @@ HoptoadNotifier.module_eval do
9 # Log the error internally if we are not in a development environment. 9 # Log the error internally if we are not in a development environment.
10 if configuration.public? 10 if configuration.public?
11 app = App.find_or_initialize_by(:name => "Self.Errbit") 11 app = App.find_or_initialize_by(:name => "Self.Errbit")
12 - if app.new?  
13 - app.github_url = "https://github.com/errbit/errbit.git"  
14 - app.save!  
15 - end 12 + app.github_repo = "errbit/errbit"
  13 + app.save!
16 notice.send("api_key=", app.api_key) 14 notice.send("api_key=", app.api_key)
17 15
18 # Create notice internally. 16 # Create notice internally.
spec/controllers/apps_controller_spec.rb
@@ -177,12 +177,12 @@ describe AppsController do @@ -177,12 +177,12 @@ describe AppsController do
177 177
178 it "should copy attributes from an existing app" do 178 it "should copy attributes from an existing app" do
179 @app = Fabricate(:app, :name => "do not copy", 179 @app = Fabricate(:app, :name => "do not copy",
180 - :github_url => "github.com/test/example") 180 + :github_repo => "test/example")
181 get :new, :copy_attributes_from => @app.id 181 get :new, :copy_attributes_from => @app.id
182 assigns(:app).should be_a(App) 182 assigns(:app).should be_a(App)
183 assigns(:app).should be_new_record 183 assigns(:app).should be_new_record
184 assigns(:app).name.should be_blank 184 assigns(:app).name.should be_blank
185 - assigns(:app).github_url.should == "github.com/test/example" 185 + assigns(:app).github_repo.should == "test/example"
186 end 186 end
187 end 187 end
188 188
spec/models/app_spec.rb
@@ -37,53 +37,53 @@ describe App do @@ -37,53 +37,53 @@ describe App do
37 app.api_key.should match(/^[a-f0-9]{32}$/) 37 app.api_key.should match(/^[a-f0-9]{32}$/)
38 end 38 end
39 39
40 - it 'is fine with blank github urls' do  
41 - app = Fabricate.build(:app, :github_url => "") 40 + it 'is fine with blank github repos' do
  41 + app = Fabricate.build(:app, :github_repo => "")
42 app.save 42 app.save
43 - app.github_url.should == "" 43 + app.github_repo.should == ""
44 end 44 end
45 45
46 - it 'does not touch https github urls' do  
47 - app = Fabricate.build(:app, :github_url => "https://github.com/errbit/errbit") 46 + it 'doesnt touch github user/repo' do
  47 + app = Fabricate.build(:app, :github_repo => "errbit/errbit")
48 app.save 48 app.save
49 - app.github_url.should == "https://github.com/errbit/errbit" 49 + app.github_repo.should == "errbit/errbit"
50 end 50 end
51 51
52 - it 'normalizes http github urls' do  
53 - app = Fabricate.build(:app, :github_url => "http://github.com/errbit/errbit") 52 + it 'removes domain from https github repos' do
  53 + app = Fabricate.build(:app, :github_repo => "https://github.com/errbit/errbit")
54 app.save 54 app.save
55 - app.github_url.should == "https://github.com/errbit/errbit" 55 + app.github_repo.should == "errbit/errbit"
56 end 56 end
57 57
58 - it 'normalizes public git repo as a github url' do  
59 - app = Fabricate.build(:app, :github_url => "https://github.com/errbit/errbit.git") 58 + it 'normalizes public git repo as a github repo' do
  59 + app = Fabricate.build(:app, :github_repo => "https://github.com/errbit/errbit.git")
60 app.save 60 app.save
61 - app.github_url.should == "https://github.com/errbit/errbit" 61 + app.github_repo.should == "errbit/errbit"
62 end 62 end
63 63
64 - it 'normalizes private git repo as a github url' do  
65 - app = Fabricate.build(:app, :github_url => "git@github.com:errbit/errbit.git") 64 + it 'normalizes private git repo as a github repo' do
  65 + app = Fabricate.build(:app, :github_repo => "git@github.com:errbit/errbit.git")
66 app.save 66 app.save
67 - app.github_url.should == "https://github.com/errbit/errbit" 67 + app.github_repo.should == "errbit/errbit"
68 end 68 end
69 end 69 end
70 70
71 context '#github_url_to_file' do 71 context '#github_url_to_file' do
72 it 'resolves to full path to file' do 72 it 'resolves to full path to file' do
73 - app = Fabricate(:app, :github_url => "https://github.com/errbit/errbit") 73 + app = Fabricate(:app, :github_repo => "errbit/errbit")
74 app.github_url_to_file('/path/to/file').should == "https://github.com/errbit/errbit/blob/master/path/to/file" 74 app.github_url_to_file('/path/to/file').should == "https://github.com/errbit/errbit/blob/master/path/to/file"
75 end 75 end
76 end 76 end
77 77
78 - context '#github_url?' do  
79 - it 'is true when there is a github_url' do  
80 - app = Fabricate(:app, :github_url => "https://github.com/errbit/errbit")  
81 - app.github_url?.should be_true 78 + context '#github_repo?' do
  79 + it 'is true when there is a github_repo' do
  80 + app = Fabricate(:app, :github_repo => "errbit/errbit")
  81 + app.github_repo?.should be_true
82 end 82 end
83 83
84 - it 'is false when no github_url' do 84 + it 'is false when no github_repo' do
85 app = Fabricate(:app) 85 app = Fabricate(:app)
86 - app.github_url?.should be_false 86 + app.github_repo?.should be_false
87 end 87 end
88 end 88 end
89 89
@@ -102,12 +102,12 @@ describe App do @@ -102,12 +102,12 @@ describe App do
102 102
103 context "copying attributes from existing app" do 103 context "copying attributes from existing app" do
104 it "should only copy the necessary fields" do 104 it "should only copy the necessary fields" do
105 - @app, @copy_app = Fabricate(:app, :name => "app", :github_url => "url"),  
106 - Fabricate(:app, :name => "copy_app", :github_url => "copy url") 105 + @app, @copy_app = Fabricate(:app, :name => "app", :github_repo => "url"),
  106 + Fabricate(:app, :name => "copy_app", :github_repo => "copy url")
107 @copy_watcher = Fabricate(:watcher, :email => "copywatcher@example.com", :app => @copy_app) 107 @copy_watcher = Fabricate(:watcher, :email => "copywatcher@example.com", :app => @copy_app)
108 @app.copy_attributes_from(@copy_app.id) 108 @app.copy_attributes_from(@copy_app.id)
109 @app.name.should == "app" 109 @app.name.should == "app"
110 - @app.github_url.should == "copy url" 110 + @app.github_repo.should == "copy url"
111 @app.watchers.first.email.should == "copywatcher@example.com" 111 @app.watchers.first.email.should == "copywatcher@example.com"
112 end 112 end
113 end 113 end