diff --git a/app/controllers/admin/communication/websites_controller.rb b/app/controllers/admin/communication/websites_controller.rb index f8e537d9de8fcd438335b3e8d4f7f5451c87e272..ff18a21ad50334d73d5ef45b2fed4fe49a875d36 100644 --- a/app/controllers/admin/communication/websites_controller.rb +++ b/app/controllers/admin/communication/websites_controller.rb @@ -67,7 +67,7 @@ class Admin::Communication::WebsitesController < Admin::Communication::Applicati def website_params params.require(:communication_website).permit( - :name, :url, :repository, :access_token, :about_type, :about_id, :git_provider + :name, :url, :repository, :access_token, :about_type, :about_id, :git_provider, :git_endpoint ) end end diff --git a/app/models/communication/website.rb b/app/models/communication/website.rb index c55bf171232e202408c374d47f96273230ae7946..b72ab03ad9624fe10a4dd3cc7de6b2f2f10aa7cc 100644 --- a/app/models/communication/website.rb +++ b/app/models/communication/website.rb @@ -5,6 +5,7 @@ # id :uuid not null, primary key # about_type :string indexed => [about_id] # access_token :string +# git_endpoint :string # git_provider :integer default("github") # name :string # repository :string diff --git a/app/models/communication/website/configs/base_url.rb b/app/models/communication/website/configs/base_url.rb index dfaa1d5cb24c1d90ea681ab5812ab083515972cb..ffae459359e38b6ebbd72a6ba4deff313e44175a 100644 --- a/app/models/communication/website/configs/base_url.rb +++ b/app/models/communication/website/configs/base_url.rb @@ -5,6 +5,7 @@ # id :uuid not null, primary key # about_type :string indexed => [about_id] # access_token :string +# git_endpoint :string # git_provider :integer default("github") # name :string # repository :string diff --git a/app/models/communication/website/configs/permalinks.rb b/app/models/communication/website/configs/permalinks.rb index 13ffdd2c68a36f26ed2afb61cf1abcd108a085b1..0f269522ac9088f6e58be42e405358bfc6719c50 100644 --- a/app/models/communication/website/configs/permalinks.rb +++ b/app/models/communication/website/configs/permalinks.rb @@ -5,6 +5,7 @@ # id :uuid not null, primary key # about_type :string indexed => [about_id] # access_token :string +# git_endpoint :string # git_provider :integer default("github") # name :string # repository :string diff --git a/app/services/git/providers/abstract.rb b/app/services/git/providers/abstract.rb index 90b9081a91d3518646c75dfc3bd4a24088f62b6b..bd3778d0fbb64eee2d209b25dc45563c194177ae 100644 --- a/app/services/git/providers/abstract.rb +++ b/app/services/git/providers/abstract.rb @@ -1,7 +1,8 @@ class Git::Providers::Abstract - attr_reader :access_token, :repository + attr_reader :endpoint, :access_token, :repository - def initialize(access_token, repository) + def initialize(endpoint, access_token, repository) + @endpoint = endpoint @access_token = access_token @repository = repository end diff --git a/app/services/git/providers/gitlab.rb b/app/services/git/providers/gitlab.rb index b549e9c411b90487d977057ce3e0cbfa6f297ca8..937b9c9044126723f2f208bc7d5cc2bd7079c066 100644 --- a/app/services/git/providers/gitlab.rb +++ b/app/services/git/providers/gitlab.rb @@ -1,4 +1,6 @@ class Git::Providers::Gitlab < Git::Providers::Abstract + DEFAULT_ENDPOINT = 'https://gitlab.com/api/v4' + def create_file(path, content) batch << { action: 'create', @@ -59,9 +61,14 @@ class Git::Providers::Gitlab < Git::Providers::Abstract protected + def endpoint + @endpoint.blank? ? DEFAULT_ENDPOINT + : @endpoint + end + def client @client ||= Gitlab.client( - endpoint: 'https://gitlab.com/api/v4', + endpoint: endpoint, private_token: access_token ) end diff --git a/app/services/git/repository.rb b/app/services/git/repository.rb index 1397acb8589ca807cbe0ea27d7f71c5d39cdbe7b..3186045655e3f5ad0f23cacc119f135d9f17a59d 100644 --- a/app/services/git/repository.rb +++ b/app/services/git/repository.rb @@ -34,7 +34,9 @@ class Git::Repository protected def provider - @provider ||= provider_class.new(website&.access_token, website&.repository) + @provider ||= provider_class.new website&.git_endpoint, + website&.access_token, + website&.repository end def provider_class diff --git a/app/views/admin/communication/websites/_form.html.erb b/app/views/admin/communication/websites/_form.html.erb index 8227d6c685d56791d0fd7e641ae6ea08e181278d..0c21118ca61b6d3f4fdbf48e47dc6c70968f240d 100644 --- a/app/views/admin/communication/websites/_form.html.erb +++ b/app/views/admin/communication/websites/_form.html.erb @@ -53,13 +53,12 @@ <%= f.input :git_provider, include_blank: false %> </div> <div class="col-md-6"> + <%= f.input :git_endpoint, + placeholder: 'If blank, default will be used (https://gitlab.com/api/v4)' %> <%= f.input :access_token %> - </div> - <div class="col-md-6"> <%= f.input :repository %> </div> </div> - </div> </div> </div> diff --git a/db/migrate/20220225101556_add_git_endpoint_to_communication_websites.rb b/db/migrate/20220225101556_add_git_endpoint_to_communication_websites.rb new file mode 100644 index 0000000000000000000000000000000000000000..8a821a2c68129f4e6a06875240dcd7852dceda6a --- /dev/null +++ b/db/migrate/20220225101556_add_git_endpoint_to_communication_websites.rb @@ -0,0 +1,5 @@ +class AddGitEndpointToCommunicationWebsites < ActiveRecord::Migration[6.1] + def change + add_column :communication_websites, :git_endpoint, :string + end +end diff --git a/db/schema.rb b/db/schema.rb index 51b023ae3fb403a78aa62d9b93b681df8f841f8e..1bfa2d8e9ac3941e73ad135453296854ac07cf72 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 2022_02_24_144107) do +ActiveRecord::Schema.define(version: 2022_02_25_101556) do # These are extensions that must be enabled in order to support this database enable_extension "pgcrypto" @@ -356,6 +356,7 @@ ActiveRecord::Schema.define(version: 2022_02_24_144107) do t.string "static_pathname_researchers", default: "researchers" t.string "static_pathname_teachers", default: "teachers" t.integer "git_provider", default: 0 + t.string "git_endpoint" t.index ["about_type", "about_id"], name: "index_communication_websites_on_about" t.index ["university_id"], name: "index_communication_websites_on_university_id" end diff --git a/test/fixtures/communication/websites.yml b/test/fixtures/communication/websites.yml index ba99545b9d5a739e2ffdb89276a538f6ad3dfb4a..33965b28a8dd69b5dbcc9a665aa1e1a116fd2b17 100644 --- a/test/fixtures/communication/websites.yml +++ b/test/fixtures/communication/websites.yml @@ -5,6 +5,7 @@ # id :uuid not null, primary key # about_type :string indexed => [about_id] # access_token :string +# git_endpoint :string # git_provider :integer default("github") # name :string # repository :string