Commit 56d64409588726e1ee12bbb96c3ec3ae0bdadf7b

Authored by Genadi Samokovarov
1 parent 0d1cab60
Exists in master and in 1 other branch production

Support GitHub Enterprise repository links

Let companies or groups that run their own GitHub Enterprise installs be
able to link their own repositories.

That's the case with our company and we can't easily link the internal
repositories.
app/models/app.rb
... ... @@ -99,7 +99,7 @@ class App
99 99 end
100 100  
101 101 def github_url
102   - "https://github.com/#{github_repo}" if github_repo?
  102 + "#{Errbit::Config.github_url}/#{github_repo}" if github_repo?
103 103 end
104 104  
105 105 def github_url_to_file(file)
... ... @@ -196,8 +196,10 @@ class App
196 196  
197 197 def normalize_github_repo
198 198 return if github_repo.blank?
  199 + github_host = URI.parse(Errbit::Config.github_url).host
  200 + github_host = Regexp.escape(github_host)
199 201 github_repo.strip!
200   - github_repo.sub!(/(git@|https?:\/\/)github\.com(\/|:)/, '')
  202 + github_repo.sub!(/(git@|https?:\/\/)#{github_host}(\/|:)/, '')
201 203 github_repo.sub!(/\.git$/, '')
202 204 end
203 205 end
... ...
config/config.example.yml
... ... @@ -98,6 +98,10 @@ github_secret: 'GITHUB_SECRET'
98 98 # [] - No permission to create issues on any repos.
99 99 github_access_scope: ['repo']
100 100  
  101 +# Change this to point to the URL of your GitHub Enterprise installation, if
  102 +# you want to link local repositories.
  103 +github_url: https://github.com
  104 +
101 105 # Configure SMTP settings. If you are running Errbit on Heroku,
102 106 # sendgrid will be configured by default.
103 107 # ------------------------------------------------------------------------
... ...
config/initializers/_load_config.rb
... ... @@ -21,6 +21,7 @@ unless defined?(Errbit::Config)
21 21 Errbit::Config.use_gravatar = ENV['ERRBIT_USE_GRAVATAR']
22 22 Errbit::Config.gravatar_default = ENV['ERRBIT_GRAVATAR_DEFAULT']
23 23  
  24 + Errbit::Config.github_url = ENV['GITHUB_URL']
24 25 Errbit::Config.github_authentication = ENV['GITHUB_AUTHENTICATION']
25 26 Errbit::Config.github_client_id = ENV['GITHUB_CLIENT_ID']
26 27 Errbit::Config.github_secret = ENV['GITHUB_SECRET']
... ... @@ -64,6 +65,10 @@ default_config.each do |k,v|
64 65 Errbit::Config.send("#{k}=", v) if Errbit::Config.send(k) === nil
65 66 end
66 67  
  68 +# Make sure the GitHub link doesn't end with a slash, so we don't have to deal
  69 +# with it later on in the code.
  70 +Errbit::Config.github_url.gsub!(/\/*\z/, '')
  71 +
67 72 # Disable GitHub oauth if gem is missing
68 73 Errbit::Config.github_authentication = false unless defined?(OmniAuth::Strategies::GitHub)
69 74  
... ...