Skip to content
Snippets Groups Projects
Commit 143ee798 authored by alexisben's avatar alexisben
Browse files

Merge branch 'master' of github.com:noesya/osuny into feature/blocks

parents e5763c1d 7c8cf3e7
No related branches found
No related tags found
No related merge requests found
......@@ -9,4 +9,10 @@ class Git::Providers::Abstract
def valid?
repository.present? && access_token.present?
end
protected
def batch
@batch ||= []
end
end
......@@ -60,10 +60,6 @@ class Git::Providers::Github < Git::Providers::Abstract
@client ||= Octokit::Client.new access_token: access_token
end
def batch
@batch ||= []
end
def default_branch
@default_branch ||= client.repo(repository)[:default_branch]
end
......
class Git::Providers::Gitlab < Git::Providers::Abstract
def create_file(path, content)
batch << {
action: 'create',
file_path: path,
content: content
}
end
def update_file(path, previous_path, content)
file = find_in_tree previous_path
return if file.nil?
if previous_path != path
batch << {
action: 'move',
file_path: path,
previous_path: previous_path
}
end
batch << {
action: 'update',
file_path: path,
content: content
}
end
def destroy_file(path)
file = find path
return if file.nil?
batch << {
action: 'delete',
file_path: path,
}
end
def push(commit_message)
return if !valid? || batch.empty?
client.create_commit repository,
'main',
commit_message,
batch
true
end
# https://gitlab.com/gitlab-org/gitlab/-/issues/23504
def git_sha(path)
begin
file = find path
sha = file['content_sha256']
rescue
sha = nil
end
sha
end
protected
def client
@client ||= Gitlab.client(
endpoint: 'https://gitlab.com/api/v4',
private_token: access_token
)
end
def find(path)
client.get_file repository,
path,
'main'
rescue
nil
end
end
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