33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
|
# File 'lib/gitlab_mr_release/cli.rb', line 33
def create
Dotenv.load(*GITLAB_ENV_FILES)
assert_env("GITLAB_API_ENDPOINT")
assert_env("GITLAB_API_PRIVATE_TOKEN")
assert_env("GITLAB_PROJECT_NAME")
assert_option_or_env(:source, "DEFAULT_SOURCE_BRANCH")
assert_option_or_env(:target, "DEFAULT_TARGET_BRANCH")
template = File.read(template_file)
project = GitlabMrRelease::Project.new(
api_endpoint: ENV["GITLAB_API_ENDPOINT"],
private_token: ENV["GITLAB_API_PRIVATE_TOKEN"],
project_name: ENV["GITLAB_PROJECT_NAME"],
)
unless project.api_version >= 4
raise InvalidApiVersionError, "'#{ENV["GITLAB_API_ENDPOINT"]}' seems not to be GitLab API v4+. gitlab_mr_release requires GitLab API v4+"
end
mr = project.create_merge_request(
source_branch: source_branch,
target_branch: target_branch,
labels: labels,
title: generate_title,
template: template,
)
mr_url = "#{project.web_url}/merge_requests/#{mr.iid}"
message = <<-EOS
MergeRequest is created
[Title] #{mr.title}
[Description]
#{mr.description}
[Url] #{mr_url}
EOS
puts message
end
|