mirror of
https://github.com/discourse/discourse.git
synced 2024-11-22 10:57:04 +08:00
97e2b353f6
Followup 560e8aff75
GitHub auth tokens cannot be made with permissions to
access multiple organisations. This is quite limiting.
This commit changes the site setting to be a "secret list"
type, which allows for a key/value mapping where the value
is treated like a password in the UI.
Now when a GitHub URL is requested for oneboxing, the
org name from the URL is used to determine which token
to use for the request.
Just in case anyone used the old site setting already,
there is a migration to create a `default` entry
with that token in the new list setting, and for
a period of time we will consider that token valid to
use for all GitHub oneboxes as well.
43 lines
973 B
Ruby
43 lines
973 B
Ruby
# frozen_string_literal: true
|
|
|
|
require_relative "../mixins/git_blob_onebox"
|
|
|
|
module Onebox
|
|
module Engine
|
|
class GitlabBlobOnebox
|
|
def self.git_regexp
|
|
%r{^https?://(www\.)?gitlab\.com.*/blob/}
|
|
end
|
|
|
|
def self.onebox_name
|
|
"gitlabblob"
|
|
end
|
|
|
|
include Onebox::Mixins::GitBlobOnebox
|
|
|
|
def i18n
|
|
{
|
|
truncated_file: I18n.t("onebox.gitlab.truncated_file"),
|
|
show_original: I18n.t("onebox.gitlab.show_original"),
|
|
}
|
|
end
|
|
|
|
def raw_regexp
|
|
%r{gitlab\.com/(?<user>[^/]+)/(?<repo>[^/]+)/blob/(?<sha1>[^/]+)/(?<file>[^#]+)(#(L(?<from>[^-]*)(-L(?<to>.*))?))?}mi
|
|
end
|
|
|
|
def raw_template(m)
|
|
"https://gitlab.com/#{m[:user]}/#{m[:repo]}/raw/#{m[:sha1]}/#{m[:file]}"
|
|
end
|
|
|
|
def title
|
|
Sanitize.fragment(Onebox::Helpers.uri_unencode(link).sub(%r{^https?\://gitlab\.com/}, ""))
|
|
end
|
|
|
|
def auth_headers(_match)
|
|
{}
|
|
end
|
|
end
|
|
end
|
|
end
|