Skip to content
Snippets Groups Projects
Commit 1ab4e0b0 authored by Arnaud Levy's avatar Arnaud Levy
Browse files

endpoint

parent 9bcecab1
No related branches found
No related tags found
No related merge requests found
...@@ -67,7 +67,7 @@ class Admin::Communication::WebsitesController < Admin::Communication::Applicati ...@@ -67,7 +67,7 @@ class Admin::Communication::WebsitesController < Admin::Communication::Applicati
def website_params def website_params
params.require(:communication_website).permit( 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
end end
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
# id :uuid not null, primary key # id :uuid not null, primary key
# about_type :string indexed => [about_id] # about_type :string indexed => [about_id]
# access_token :string # access_token :string
# git_endpoint :string
# git_provider :integer default("github") # git_provider :integer default("github")
# name :string # name :string
# repository :string # repository :string
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
# id :uuid not null, primary key # id :uuid not null, primary key
# about_type :string indexed => [about_id] # about_type :string indexed => [about_id]
# access_token :string # access_token :string
# git_endpoint :string
# git_provider :integer default("github") # git_provider :integer default("github")
# name :string # name :string
# repository :string # repository :string
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
# id :uuid not null, primary key # id :uuid not null, primary key
# about_type :string indexed => [about_id] # about_type :string indexed => [about_id]
# access_token :string # access_token :string
# git_endpoint :string
# git_provider :integer default("github") # git_provider :integer default("github")
# name :string # name :string
# repository :string # repository :string
......
class Git::Providers::Abstract 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 @access_token = access_token
@repository = repository @repository = repository
end end
......
class Git::Providers::Gitlab < Git::Providers::Abstract class Git::Providers::Gitlab < Git::Providers::Abstract
DEFAULT_ENDPOINT = 'https://gitlab.com/api/v4'
def create_file(path, content) def create_file(path, content)
batch << { batch << {
action: 'create', action: 'create',
...@@ -59,9 +61,14 @@ class Git::Providers::Gitlab < Git::Providers::Abstract ...@@ -59,9 +61,14 @@ class Git::Providers::Gitlab < Git::Providers::Abstract
protected protected
def endpoint
@endpoint.blank? ? DEFAULT_ENDPOINT
: @endpoint
end
def client def client
@client ||= Gitlab.client( @client ||= Gitlab.client(
endpoint: 'https://gitlab.com/api/v4', endpoint: endpoint,
private_token: access_token private_token: access_token
) )
end end
......
...@@ -34,7 +34,9 @@ class Git::Repository ...@@ -34,7 +34,9 @@ class Git::Repository
protected protected
def provider def provider
@provider ||= provider_class.new(website&.access_token, website&.repository) @provider ||= provider_class.new website&.git_endpoint,
website&.access_token,
website&.repository
end end
def provider_class def provider_class
......
...@@ -53,13 +53,12 @@ ...@@ -53,13 +53,12 @@
<%= f.input :git_provider, include_blank: false %> <%= f.input :git_provider, include_blank: false %>
</div> </div>
<div class="col-md-6"> <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 %> <%= f.input :access_token %>
</div>
<div class="col-md-6">
<%= f.input :repository %> <%= f.input :repository %>
</div> </div>
</div> </div>
</div> </div>
</div> </div>
</div> </div>
......
class AddGitEndpointToCommunicationWebsites < ActiveRecord::Migration[6.1]
def change
add_column :communication_websites, :git_endpoint, :string
end
end
...@@ -10,7 +10,7 @@ ...@@ -10,7 +10,7 @@
# #
# It's strongly recommended that you check this file into your version control system. # 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 # These are extensions that must be enabled in order to support this database
enable_extension "pgcrypto" enable_extension "pgcrypto"
...@@ -356,6 +356,7 @@ ActiveRecord::Schema.define(version: 2022_02_24_144107) do ...@@ -356,6 +356,7 @@ ActiveRecord::Schema.define(version: 2022_02_24_144107) do
t.string "static_pathname_researchers", default: "researchers" t.string "static_pathname_researchers", default: "researchers"
t.string "static_pathname_teachers", default: "teachers" t.string "static_pathname_teachers", default: "teachers"
t.integer "git_provider", default: 0 t.integer "git_provider", default: 0
t.string "git_endpoint"
t.index ["about_type", "about_id"], name: "index_communication_websites_on_about" t.index ["about_type", "about_id"], name: "index_communication_websites_on_about"
t.index ["university_id"], name: "index_communication_websites_on_university_id" t.index ["university_id"], name: "index_communication_websites_on_university_id"
end end
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
# id :uuid not null, primary key # id :uuid not null, primary key
# about_type :string indexed => [about_id] # about_type :string indexed => [about_id]
# access_token :string # access_token :string
# git_endpoint :string
# git_provider :integer default("github") # git_provider :integer default("github")
# name :string # name :string
# repository :string # repository :string
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment