debian-mirror-gitlab/spec/support/helpers/api_internal_base_helpers.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

90 lines
2.3 KiB
Ruby
Raw Permalink Normal View History

2021-01-03 14:25:43 +05:30
# frozen_string_literal: true
2022-10-11 01:57:18 +05:30
require_relative 'gitlab_shell_helpers'
2021-01-03 14:25:43 +05:30
module APIInternalBaseHelpers
2022-10-11 01:57:18 +05:30
include GitlabShellHelpers
2021-01-03 14:25:43 +05:30
def gl_repository_for(container)
case container
when ProjectWiki
Gitlab::GlRepository::WIKI.identifier_for_container(container)
when Project
Gitlab::GlRepository::PROJECT.identifier_for_container(container)
when Snippet
Gitlab::GlRepository::SNIPPET.identifier_for_container(container)
end
end
def full_path_for(container)
case container
when PersonalSnippet
"snippets/#{container.id}"
when ProjectSnippet
"#{container.project.full_path}/snippets/#{container.id}"
else
container.full_path
end
end
def pull(key, container, protocol = 'ssh')
post(
api("/internal/allowed"),
params: {
key_id: key.id,
project: full_path_for(container),
gl_repository: gl_repository_for(container),
action: 'git-upload-pack',
protocol: protocol
2022-10-11 01:57:18 +05:30
},
headers: gitlab_shell_internal_api_request_header
2021-01-03 14:25:43 +05:30
)
end
def push(key, container, protocol = 'ssh', env: nil, changes: nil)
2023-06-20 00:43:36 +05:30
push_with_path(
key,
full_path: full_path_for(container),
gl_repository: gl_repository_for(container),
protocol: protocol,
env: env,
changes: changes
)
2021-01-03 14:25:43 +05:30
end
def push_with_path(key, full_path:, gl_repository: nil, protocol: 'ssh', env: nil, changes: nil)
changes ||= 'd14d6c0abdd253381df51a723d58691b2ee1ab08 570e7b2abdd848b95f2f578043fc23bd6f6fd24d refs/heads/master'
params = {
changes: changes,
key_id: key.id,
project: full_path,
action: 'git-receive-pack',
protocol: protocol,
env: env
}
params[:gl_repository] = gl_repository if gl_repository
post(
api("/internal/allowed"),
2022-10-11 01:57:18 +05:30
params: params,
headers: gitlab_shell_internal_api_request_header
2021-01-03 14:25:43 +05:30
)
end
def archive(key, container)
post(
api("/internal/allowed"),
params: {
ref: 'master',
key_id: key.id,
project: full_path_for(container),
gl_repository: gl_repository_for(container),
action: 'git-upload-archive',
protocol: 'ssh'
2022-10-11 01:57:18 +05:30
},
headers: gitlab_shell_internal_api_request_header
2021-01-03 14:25:43 +05:30
)
end
end