debian-mirror-gitlab/spec/support/helpers/repo_helpers.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

169 lines
4.5 KiB
Ruby
Raw Normal View History

2019-10-12 21:52:04 +05:30
# frozen_string_literal: true
2014-09-02 18:07:02 +05:30
module RepoHelpers
extend self
# Text file in repo
#
# Ex.
#
# # Get object
# blob = RepoHelpers.text_blob
#
# blob.path # => 'files/js/commit.js.coffee'
# blob.data # => 'class Commit...'
#
2019-07-31 22:56:46 +05:30
# Build the options hash that's passed to Rugged::Commit#create
2014-09-02 18:07:02 +05:30
def sample_blob
OpenStruct.new(
oid: '5f53439ca4b009096571d3c8bc3d09d30e7431b3',
path: "files/js/commit.js.coffee",
data: <<eos
class Commit
constructor: ->
$('.files .diff-file').each ->
new CommitFile(this)
@Commit = Commit
eos
)
end
def sample_commit
OpenStruct.new(
id: "570e7b2abdd848b95f2f578043fc23bd6f6fd24d",
2020-04-22 19:07:51 +05:30
sha: "570e7b2abdd848b95f2f578043fc23bd6f6fd24d",
2014-09-02 18:07:02 +05:30
parent_id: '6f6d7e7ed97bb5f0054f2b1df789b39ca89b6ff9',
author_full_name: "Dmitriy Zaporozhets",
author_email: "dmitriy.zaporozhets@gmail.com",
files_changed_count: 2,
line_code: '2f6fcd96b88b36ce98c38da085c795a27d92a3dd_15_14',
line_code_path: 'files/ruby/popen.rb',
del_line_code: '2f6fcd96b88b36ce98c38da085c795a27d92a3dd_13_13',
2023-05-27 22:25:52 +05:30
referenced_by: [],
2014-09-02 18:07:02 +05:30
message: <<eos
Change some files
Signed-off-by: Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
eos
)
end
2017-08-17 22:00:37 +05:30
2015-04-26 12:48:37 +05:30
def another_sample_commit
OpenStruct.new(
2015-12-23 02:04:40 +05:30
id: "e56497bb5f03a90a51293fc6d516788730953899",
2020-04-22 19:07:51 +05:30
sha: "e56497bb5f03a90a51293fc6d516788730953899",
2015-12-23 02:04:40 +05:30
parent_id: '4cd80ccab63c82b4bad16faa5193fbd2aa06df40',
author_full_name: "Sytse Sijbrandij",
author_email: "sytse@gitlab.com",
files_changed_count: 1,
2023-05-27 22:25:52 +05:30
referenced_by: [],
2015-12-23 02:04:40 +05:30
message: <<eos
2015-04-26 12:48:37 +05:30
Add directory structure for tree_helper spec
This directory structure is needed for a testing the method flatten_tree(tree) in the TreeHelper module
2019-12-04 20:38:33 +05:30
See [merge request #275](https://gitlab.com/gitlab-org/gitlab-foss/merge_requests/275#note_732774)
2015-04-26 12:48:37 +05:30
See merge request !2
eos
)
end
2014-09-02 18:07:02 +05:30
def sample_big_commit
OpenStruct.new(
id: "913c66a37b4a45b9769037c55c2d238bd0942d2e",
2020-04-22 19:07:51 +05:30
sha: "913c66a37b4a45b9769037c55c2d238bd0942d2e",
2014-09-02 18:07:02 +05:30
author_full_name: "Dmitriy Zaporozhets",
author_email: "dmitriy.zaporozhets@gmail.com",
2023-05-27 22:25:52 +05:30
referenced_by: [],
2014-09-02 18:07:02 +05:30
message: <<eos
Files, encoding and much more
Signed-off-by: Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
eos
)
end
def sample_image_commit
OpenStruct.new(
id: "2f63565e7aac07bcdadb654e253078b727143ec4",
2020-04-22 19:07:51 +05:30
sha: "2f63565e7aac07bcdadb654e253078b727143ec4",
2014-09-02 18:07:02 +05:30
author_full_name: "Dmitriy Zaporozhets",
author_email: "dmitriy.zaporozhets@gmail.com",
old_blob_id: '33f3729a45c02fc67d00adb1b8bca394b0e761d9',
new_blob_id: '2f63565e7aac07bcdadb654e253078b727143ec4',
2023-05-27 22:25:52 +05:30
referenced_by: [],
2014-09-02 18:07:02 +05:30
message: <<eos
Modified image
Signed-off-by: Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
eos
)
end
2019-12-21 20:55:43 +05:30
def sample_compare(extra_changes = [])
2014-09-02 18:07:02 +05:30
changes = [
{
line_code: 'a5cc2925ca8258af241be7e5b0381edf30266302_20_20',
2017-09-10 17:25:29 +05:30
file_path: '.gitignore'
2014-09-02 18:07:02 +05:30
},
{
line_code: '7445606fbf8f3683cd42bdc54b05d7a0bc2dfc44_4_6',
2017-09-10 17:25:29 +05:30
file_path: '.gitmodules'
2014-09-02 18:07:02 +05:30
}
2019-12-21 20:55:43 +05:30
] + extra_changes
2014-09-02 18:07:02 +05:30
2017-08-17 22:00:37 +05:30
commits = %w(
5937ac0a7beb003549fc5fd26fc247adbce4a52e
570e7b2abdd848b95f2f578043fc23bd6f6fd24d
6f6d7e7ed97bb5f0054f2b1df789b39ca89b6ff9
d14d6c0abdd253381df51a723d58691b2ee1ab08
c1acaa58bbcbc3eafe538cb8274ba387047b69f8
).reverse # last commit is recent one
2014-09-02 18:07:02 +05:30
OpenStruct.new(
source_branch: 'master',
target_branch: 'feature',
changes: changes,
commits: commits
)
end
2019-05-03 19:53:19 +05:30
def create_file_in_repo(
2020-11-24 15:15:51 +05:30
project, start_branch, branch_name, filename, content,
2019-05-03 19:53:19 +05:30
commit_message: 'Add new content')
Files::CreateService.new(
project,
2022-04-04 11:22:00 +05:30
project.first_owner,
2019-05-03 19:53:19 +05:30
commit_message: commit_message,
start_branch: start_branch,
branch_name: branch_name,
file_path: filename,
file_content: content
).execute
end
2023-03-04 22:38:38 +05:30
def create_and_delete_files(project, files, &block)
files.each do |filename, content|
project.repository.create_file(
project.creator,
filename,
content,
message: "Automatically created file #{filename}",
branch_name: project.default_branch_or_main
)
end
yield
ensure
files.each do |filename, _content|
project.repository.delete_file(
project.creator,
filename,
message: "Automatically deleted file #{filename}",
branch_name: project.default_branch_or_main
)
end
end
2014-09-02 18:07:02 +05:30
end