2016-09-29 09:46:39 +05:30
|
|
|
module CycleAnalyticsHelpers
|
2017-08-17 22:00:37 +05:30
|
|
|
def create_commit_referencing_issue(issue, branch_name: generate(:branch))
|
2016-09-29 09:46:39 +05:30
|
|
|
project.repository.add_branch(user, branch_name, 'master')
|
|
|
|
create_commit("Commit for ##{issue.iid}", issue.project, user, branch_name)
|
|
|
|
end
|
|
|
|
|
2016-10-01 15:18:49 +05:30
|
|
|
def create_commit(message, project, user, branch_name, count: 1)
|
2016-09-29 09:46:39 +05:30
|
|
|
oldrev = project.repository.commit(branch_name).sha
|
2016-10-01 15:18:49 +05:30
|
|
|
commit_shas = Array.new(count) do |index|
|
2017-08-17 22:00:37 +05:30
|
|
|
commit_sha = project.repository.create_file(user, generate(:branch), "content", message: message, branch_name: branch_name)
|
2016-10-01 15:18:49 +05:30
|
|
|
project.repository.commit(commit_sha)
|
|
|
|
|
|
|
|
commit_sha
|
|
|
|
end
|
2016-09-29 09:46:39 +05:30
|
|
|
|
|
|
|
GitPushService.new(project,
|
|
|
|
user,
|
|
|
|
oldrev: oldrev,
|
2016-10-01 15:18:49 +05:30
|
|
|
newrev: commit_shas.last,
|
2016-09-29 09:46:39 +05:30
|
|
|
ref: 'refs/heads/master').execute
|
|
|
|
end
|
|
|
|
|
|
|
|
def create_merge_request_closing_issue(issue, message: nil, source_branch: nil)
|
|
|
|
if !source_branch || project.repository.commit(source_branch).blank?
|
2017-08-17 22:00:37 +05:30
|
|
|
source_branch = generate(:branch)
|
2016-09-29 09:46:39 +05:30
|
|
|
project.repository.add_branch(user, source_branch, 'master')
|
|
|
|
end
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
sha = project.repository.create_file(
|
|
|
|
user,
|
|
|
|
generate(:branch),
|
|
|
|
'content',
|
|
|
|
message: 'commit message',
|
|
|
|
branch_name: source_branch)
|
2016-09-29 09:46:39 +05:30
|
|
|
project.repository.commit(sha)
|
|
|
|
|
|
|
|
opts = {
|
|
|
|
title: 'Awesome merge_request',
|
|
|
|
description: message || "Fixes #{issue.to_reference}",
|
|
|
|
source_branch: source_branch,
|
|
|
|
target_branch: 'master'
|
|
|
|
}
|
|
|
|
|
|
|
|
MergeRequests::CreateService.new(project, user, opts).execute
|
|
|
|
end
|
|
|
|
|
|
|
|
def merge_merge_requests_closing_issue(issue)
|
2016-11-24 13:41:30 +05:30
|
|
|
merge_requests = issue.closed_by_merge_requests(user)
|
|
|
|
|
2016-09-29 09:46:39 +05:30
|
|
|
merge_requests.each { |merge_request| MergeRequests::MergeService.new(project, user).execute(merge_request) }
|
|
|
|
end
|
|
|
|
|
|
|
|
def deploy_master(environment: 'production')
|
|
|
|
CreateDeploymentService.new(project, user, {
|
|
|
|
environment: environment,
|
|
|
|
ref: 'master',
|
|
|
|
tag: false,
|
|
|
|
sha: project.repository.commit('master').sha
|
|
|
|
}).execute
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
RSpec.configure do |config|
|
|
|
|
config.include CycleAnalyticsHelpers
|
|
|
|
end
|