2020-07-28 23:09:34 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
FactoryBot.define do
|
|
|
|
factory :go_module_commit, class: 'Commit' do
|
|
|
|
skip_create
|
|
|
|
|
|
|
|
transient do
|
|
|
|
files { { 'foo.txt' => 'content' } }
|
|
|
|
message { 'Message' }
|
2022-11-25 23:54:43 +05:30
|
|
|
# rubocop: disable RSpec/FactoryBot/InlineAssociation
|
2021-04-17 20:07:23 +05:30
|
|
|
# We need a persisted project so we can create commits and tags
|
|
|
|
# in `commit` otherwise linting this factory with `build` strategy
|
|
|
|
# will fail.
|
2020-07-28 23:09:34 +05:30
|
|
|
project { create(:project, :repository) }
|
2022-11-25 23:54:43 +05:30
|
|
|
# rubocop: enable RSpec/FactoryBot/InlineAssociation
|
2020-07-28 23:09:34 +05:30
|
|
|
|
|
|
|
service do
|
|
|
|
Files::MultiService.new(
|
|
|
|
project,
|
2022-04-04 11:22:00 +05:30
|
|
|
project.first_owner,
|
2020-07-28 23:09:34 +05:30
|
|
|
commit_message: message,
|
|
|
|
start_branch: project.repository.root_ref || 'master',
|
|
|
|
branch_name: project.repository.root_ref || 'master',
|
|
|
|
actions: files.map do |path, content|
|
|
|
|
{ action: :create, file_path: path, content: content }
|
|
|
|
end
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
|
|
|
tag { nil }
|
|
|
|
tag_message { nil }
|
|
|
|
|
|
|
|
commit do
|
|
|
|
r = service.execute
|
|
|
|
|
|
|
|
raise "operation failed: #{r}" unless r[:status] == :success
|
|
|
|
|
|
|
|
commit = project.repository.commit_by(oid: r[:result])
|
|
|
|
|
|
|
|
if tag
|
2022-04-04 11:22:00 +05:30
|
|
|
r = Tags::CreateService.new(project, project.first_owner).execute(tag, commit.sha, tag_message)
|
2020-07-28 23:09:34 +05:30
|
|
|
|
|
|
|
raise "operation failed: #{r}" unless r[:status] == :success
|
|
|
|
end
|
|
|
|
|
|
|
|
commit
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
trait :files do
|
|
|
|
transient do
|
|
|
|
message { 'Add files' }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
trait :package do
|
|
|
|
transient do
|
2021-04-17 20:07:23 +05:30
|
|
|
path { 'pkg' }
|
2020-07-28 23:09:34 +05:30
|
|
|
message { 'Add package' }
|
|
|
|
files { { "#{path}/b.go" => "package b\nfunc Bye() { println(\"Goodbye world!\") }\n" } }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
trait :module do
|
|
|
|
transient do
|
|
|
|
name { nil }
|
|
|
|
message { 'Add module' }
|
|
|
|
host_prefix { "#{::Gitlab.config.gitlab.host}/#{project.path_with_namespace}" }
|
|
|
|
|
|
|
|
url { name ? "#{host_prefix}/#{name}" : host_prefix }
|
2021-04-17 20:07:23 +05:30
|
|
|
path { "#{name}/" }
|
2020-07-28 23:09:34 +05:30
|
|
|
|
|
|
|
files do
|
|
|
|
{
|
|
|
|
"#{path}go.mod" => "module #{url}\n",
|
|
|
|
"#{path}a.go" => "package a\nfunc Hi() { println(\"Hello world!\") }\n"
|
|
|
|
}
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
initialize_with do
|
|
|
|
commit
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|