2016-09-02 12:03:32 +00:00
|
|
|
module CycleAnalyticsHelpers
|
2017-03-23 13:08:39 +00:00
|
|
|
def create_commit_referencing_issue(issue, branch_name: nil)
|
|
|
|
project.repository.add_branch(user, branch_name || generate(:branch), 'master')
|
2016-09-20 04:24:42 +00:00
|
|
|
create_commit("Commit for ##{issue.iid}", issue.project, user, branch_name)
|
|
|
|
end
|
|
|
|
|
2016-09-26 04:33:57 +00:00
|
|
|
def create_commit(message, project, user, branch_name, count: 1)
|
2016-09-20 05:47:36 +00:00
|
|
|
oldrev = project.repository.commit(branch_name).sha
|
2016-09-26 04:33:57 +00:00
|
|
|
commit_shas = Array.new(count) do |index|
|
2017-03-23 13:08:39 +00:00
|
|
|
commit_sha = project.repository.create_file(user, generate(:branch), "content", message: message, branch_name: branch_name)
|
2016-09-26 04:33:57 +00:00
|
|
|
project.repository.commit(commit_sha)
|
|
|
|
|
|
|
|
commit_sha
|
|
|
|
end
|
2016-09-20 04:24:42 +00:00
|
|
|
|
|
|
|
GitPushService.new(project,
|
|
|
|
user,
|
2016-09-20 05:47:36 +00:00
|
|
|
oldrev: oldrev,
|
2016-09-26 04:33:57 +00:00
|
|
|
newrev: commit_shas.last,
|
2016-09-20 04:24:42 +00:00
|
|
|
ref: 'refs/heads/master').execute
|
2016-09-07 08:59:12 +00:00
|
|
|
end
|
2016-09-02 12:03:32 +00:00
|
|
|
|
2016-09-20 05:47:36 +00:00
|
|
|
def create_merge_request_closing_issue(issue, message: nil, source_branch: nil)
|
|
|
|
if !source_branch || project.repository.commit(source_branch).blank?
|
2017-03-23 13:08:39 +00:00
|
|
|
source_branch = generate(:branch)
|
2016-09-20 05:47:36 +00:00
|
|
|
project.repository.add_branch(user, source_branch, 'master')
|
|
|
|
end
|
|
|
|
|
2017-02-15 23:28:29 +00:00
|
|
|
sha = project.repository.create_file(
|
2016-12-08 11:11:52 +00:00
|
|
|
user,
|
2017-03-23 13:08:39 +00:00
|
|
|
generate(:branch),
|
2016-12-08 11:11:52 +00:00
|
|
|
'content',
|
|
|
|
message: 'commit message',
|
2017-02-15 23:28:29 +00:00
|
|
|
branch_name: source_branch)
|
2016-09-07 08:59:12 +00:00
|
|
|
project.repository.commit(sha)
|
2016-09-02 12:03:32 +00:00
|
|
|
|
2016-09-07 08:59:12 +00:00
|
|
|
opts = {
|
|
|
|
title: 'Awesome merge_request',
|
|
|
|
description: message || "Fixes #{issue.to_reference}",
|
|
|
|
source_branch: source_branch,
|
|
|
|
target_branch: 'master'
|
|
|
|
}
|
2016-09-02 12:03:32 +00:00
|
|
|
|
2016-09-07 08:59:12 +00:00
|
|
|
MergeRequests::CreateService.new(project, user, opts).execute
|
|
|
|
end
|
2016-09-02 12:03:32 +00:00
|
|
|
|
2016-09-07 08:59:12 +00:00
|
|
|
def merge_merge_requests_closing_issue(issue)
|
2016-11-01 20:18:51 +00:00
|
|
|
merge_requests = issue.closed_by_merge_requests(user)
|
|
|
|
|
2016-09-07 08:59:12 +00:00
|
|
|
merge_requests.each { |merge_request| MergeRequests::MergeService.new(project, user).execute(merge_request) }
|
|
|
|
end
|
2016-09-02 12:03:32 +00:00
|
|
|
|
2016-09-07 08:59:12 +00:00
|
|
|
def deploy_master(environment: 'production')
|
|
|
|
CreateDeploymentService.new(project, user, {
|
|
|
|
environment: environment,
|
|
|
|
ref: 'master',
|
|
|
|
tag: false,
|
|
|
|
sha: project.repository.commit('master').sha
|
|
|
|
}).execute
|
2016-09-02 12:03:32 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
RSpec.configure do |config|
|
2016-09-07 08:59:12 +00:00
|
|
|
config.include CycleAnalyticsHelpers
|
2016-09-02 12:03:32 +00:00
|
|
|
end
|