2016-09-02 08:03:32 -04:00
|
|
|
module CycleAnalyticsHelpers
|
2016-09-20 01:47:36 -04:00
|
|
|
def create_commit_referencing_issue(issue, branch_name: random_git_name)
|
2016-09-20 00:24:42 -04:00
|
|
|
project.repository.add_branch(user, branch_name, 'master')
|
|
|
|
create_commit("Commit for ##{issue.iid}", issue.project, user, branch_name)
|
|
|
|
end
|
|
|
|
|
2016-09-26 00:33:57 -04:00
|
|
|
def create_commit(message, project, user, branch_name, count: 1)
|
2016-09-20 01:47:36 -04:00
|
|
|
oldrev = project.repository.commit(branch_name).sha
|
2016-09-26 00:33:57 -04:00
|
|
|
commit_shas = Array.new(count) do |index|
|
|
|
|
filename = random_git_name
|
2016-09-20 00:24:42 -04:00
|
|
|
|
2016-09-26 00:33:57 -04:00
|
|
|
options = {
|
|
|
|
committer: project.repository.user_to_committer(user),
|
|
|
|
author: project.repository.user_to_committer(user),
|
|
|
|
commit: { message: message, branch: branch_name, update_ref: true },
|
|
|
|
file: { content: "content", path: filename, update: false }
|
|
|
|
}
|
2016-09-20 00:24:42 -04:00
|
|
|
|
2016-09-26 00:33:57 -04:00
|
|
|
commit_sha = Gitlab::Git::Blob.commit(project.repository, options)
|
|
|
|
project.repository.commit(commit_sha)
|
|
|
|
|
|
|
|
commit_sha
|
|
|
|
end
|
2016-09-20 00:24:42 -04:00
|
|
|
|
|
|
|
GitPushService.new(project,
|
|
|
|
user,
|
2016-09-20 01:47:36 -04:00
|
|
|
oldrev: oldrev,
|
2016-09-26 00:33:57 -04:00
|
|
|
newrev: commit_shas.last,
|
2016-09-20 00:24:42 -04:00
|
|
|
ref: 'refs/heads/master').execute
|
2016-09-07 04:59:12 -04:00
|
|
|
end
|
2016-09-02 08:03:32 -04:00
|
|
|
|
2016-09-20 01:47:36 -04:00
|
|
|
def create_merge_request_closing_issue(issue, message: nil, source_branch: nil)
|
|
|
|
if !source_branch || project.repository.commit(source_branch).blank?
|
|
|
|
source_branch = random_git_name
|
|
|
|
project.repository.add_branch(user, source_branch, 'master')
|
|
|
|
end
|
|
|
|
|
2016-09-07 04:59:12 -04:00
|
|
|
sha = project.repository.commit_file(user, random_git_name, "content", "commit message", source_branch, false)
|
|
|
|
project.repository.commit(sha)
|
2016-09-02 08:03:32 -04:00
|
|
|
|
2016-09-07 04:59:12 -04:00
|
|
|
opts = {
|
|
|
|
title: 'Awesome merge_request',
|
|
|
|
description: message || "Fixes #{issue.to_reference}",
|
|
|
|
source_branch: source_branch,
|
|
|
|
target_branch: 'master'
|
|
|
|
}
|
2016-09-02 08:03:32 -04:00
|
|
|
|
2016-09-07 04:59:12 -04:00
|
|
|
MergeRequests::CreateService.new(project, user, opts).execute
|
|
|
|
end
|
2016-09-02 08:03:32 -04:00
|
|
|
|
2016-09-07 04:59:12 -04:00
|
|
|
def merge_merge_requests_closing_issue(issue)
|
|
|
|
merge_requests = issue.closed_by_merge_requests
|
|
|
|
merge_requests.each { |merge_request| MergeRequests::MergeService.new(project, user).execute(merge_request) }
|
|
|
|
end
|
2016-09-02 08:03:32 -04:00
|
|
|
|
2016-09-07 04:59:12 -04: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 08:03:32 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
RSpec.configure do |config|
|
2016-09-07 04:59:12 -04:00
|
|
|
config.include CycleAnalyticsHelpers
|
2016-09-02 08:03:32 -04:00
|
|
|
end
|