summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--app/models/concerns/issuable.rb6
-rw-r--r--app/models/project_wiki.rb2
-rw-r--r--app/services/issuable_base_service.rb8
-rw-r--r--app/services/issues/base_service.rb8
-rw-r--r--app/services/merge_requests/base_service.rb8
-rw-r--r--changelogs/unreleased/39573-hashed-storage-backup.yml5
-rw-r--r--changelogs/unreleased/40122-only-one-note-webhook-is-triggered-when-a-comment-with-time-spent-is-added.yml5
-rw-r--r--doc/user/project/pages/getting_started_part_one.md2
-rw-r--r--lib/backup/repository.rb24
-rw-r--r--lib/gitlab/ee_compat_check.rb6
-rw-r--r--lib/gitlab/hook_data/issue_builder.rb1
-rw-r--r--lib/gitlab/hook_data/merge_request_builder.rb1
-rw-r--r--spec/lib/gitlab/hook_data/issuable_builder_spec.rb7
-rw-r--r--spec/models/concerns/issuable_spec.rb37
-rw-r--r--spec/models/project_wiki_spec.rb4
-rw-r--r--spec/services/merge_requests/update_service_spec.rb2
16 files changed, 90 insertions, 36 deletions
diff --git a/app/models/concerns/issuable.rb b/app/models/concerns/issuable.rb
index c008fb91a16..35090181bd9 100644
--- a/app/models/concerns/issuable.rb
+++ b/app/models/concerns/issuable.rb
@@ -255,7 +255,7 @@ module Issuable
participants(user).include?(user)
end
- def to_hook_data(user, old_labels: [], old_assignees: [])
+ def to_hook_data(user, old_labels: [], old_assignees: [], old_total_time_spent: nil)
changes = previous_changes
if old_labels != labels
@@ -270,6 +270,10 @@ module Issuable
end
end
+ if old_total_time_spent != total_time_spent
+ changes[:total_time_spent] = [old_total_time_spent, total_time_spent]
+ end
+
Gitlab::HookData::IssuableBuilder.new(self).build(user: user, changes: changes)
end
diff --git a/app/models/project_wiki.rb b/app/models/project_wiki.rb
index 43de6809178..3eecbea8cbf 100644
--- a/app/models/project_wiki.rb
+++ b/app/models/project_wiki.rb
@@ -21,7 +21,7 @@ class ProjectWiki
end
delegate :empty?, to: :pages
- delegate :repository_storage_path, to: :project
+ delegate :repository_storage_path, :hashed_storage?, to: :project
def path
@project.path + '.wiki'
diff --git a/app/services/issuable_base_service.rb b/app/services/issuable_base_service.rb
index 90865867ff0..39a7299ff60 100644
--- a/app/services/issuable_base_service.rb
+++ b/app/services/issuable_base_service.rb
@@ -172,6 +172,7 @@ class IssuableBaseService < BaseService
old_labels = issuable.labels.to_a
old_mentioned_users = issuable.mentioned_users.to_a
old_assignees = issuable.assignees.to_a
+ old_total_time_spent = issuable.total_time_spent
label_ids = process_label_ids(params, existing_label_ids: issuable.label_ids)
params[:label_ids] = label_ids if labels_changing?(issuable.label_ids, label_ids)
@@ -208,7 +209,12 @@ class IssuableBaseService < BaseService
invalidate_cache_counts(issuable, users: affected_assignees.compact)
after_update(issuable)
issuable.create_new_cross_references!(current_user)
- execute_hooks(issuable, 'update', old_labels: old_labels, old_assignees: old_assignees)
+ execute_hooks(
+ issuable,
+ 'update',
+ old_labels: old_labels,
+ old_assignees: old_assignees,
+ old_total_time_spent: old_total_time_spent)
issuable.update_project_counter_caches if update_project_counters
end
diff --git a/app/services/issues/base_service.rb b/app/services/issues/base_service.rb
index b680eaf5a49..0f711bcc3cf 100644
--- a/app/services/issues/base_service.rb
+++ b/app/services/issues/base_service.rb
@@ -1,7 +1,7 @@
module Issues
class BaseService < ::IssuableBaseService
- def hook_data(issue, action, old_labels: [], old_assignees: [])
- hook_data = issue.to_hook_data(current_user, old_labels: old_labels, old_assignees: old_assignees)
+ def hook_data(issue, action, old_labels: [], old_assignees: [], old_total_time_spent: nil)
+ hook_data = issue.to_hook_data(current_user, old_labels: old_labels, old_assignees: old_assignees, old_total_time_spent: old_total_time_spent)
hook_data[:object_attributes][:action] = action
hook_data
@@ -22,8 +22,8 @@ module Issues
issue, issue.project, current_user, old_assignees)
end
- def execute_hooks(issue, action = 'open', old_labels: [], old_assignees: [])
- issue_data = hook_data(issue, action, old_labels: old_labels, old_assignees: old_assignees)
+ def execute_hooks(issue, action = 'open', old_labels: [], old_assignees: [], old_total_time_spent: nil)
+ issue_data = hook_data(issue, action, old_labels: old_labels, old_assignees: old_assignees, old_total_time_spent: old_total_time_spent)
hooks_scope = issue.confidential? ? :confidential_issue_hooks : :issue_hooks
issue.project.execute_hooks(issue_data, hooks_scope)
issue.project.execute_services(issue_data, hooks_scope)
diff --git a/app/services/merge_requests/base_service.rb b/app/services/merge_requests/base_service.rb
index 112606a82d7..d3938b065bc 100644
--- a/app/services/merge_requests/base_service.rb
+++ b/app/services/merge_requests/base_service.rb
@@ -18,8 +18,8 @@ module MergeRequests
super if changed_title
end
- def hook_data(merge_request, action, old_rev: nil, old_labels: [], old_assignees: [])
- hook_data = merge_request.to_hook_data(current_user, old_labels: old_labels, old_assignees: old_assignees)
+ def hook_data(merge_request, action, old_rev: nil, old_labels: [], old_assignees: [], old_total_time_spent: nil)
+ hook_data = merge_request.to_hook_data(current_user, old_labels: old_labels, old_assignees: old_assignees, old_total_time_spent: old_total_time_spent)
hook_data[:object_attributes][:action] = action
if old_rev && !Gitlab::Git.blank_ref?(old_rev)
hook_data[:object_attributes][:oldrev] = old_rev
@@ -28,9 +28,9 @@ module MergeRequests
hook_data
end
- def execute_hooks(merge_request, action = 'open', old_rev: nil, old_labels: [], old_assignees: [])
+ def execute_hooks(merge_request, action = 'open', old_rev: nil, old_labels: [], old_assignees: [], old_total_time_spent: nil)
if merge_request.project
- merge_data = hook_data(merge_request, action, old_rev: old_rev, old_labels: old_labels, old_assignees: old_assignees)
+ merge_data = hook_data(merge_request, action, old_rev: old_rev, old_labels: old_labels, old_assignees: old_assignees, old_total_time_spent: old_total_time_spent)
merge_request.project.execute_hooks(merge_data, :merge_request_hooks)
merge_request.project.execute_services(merge_data, :merge_request_hooks)
end
diff --git a/changelogs/unreleased/39573-hashed-storage-backup.yml b/changelogs/unreleased/39573-hashed-storage-backup.yml
new file mode 100644
index 00000000000..40ee589c8cc
--- /dev/null
+++ b/changelogs/unreleased/39573-hashed-storage-backup.yml
@@ -0,0 +1,5 @@
+---
+title: Fix gitlab:backup rake for hashed storage based repositories
+merge_request: 15400
+author:
+type: fixed
diff --git a/changelogs/unreleased/40122-only-one-note-webhook-is-triggered-when-a-comment-with-time-spent-is-added.yml b/changelogs/unreleased/40122-only-one-note-webhook-is-triggered-when-a-comment-with-time-spent-is-added.yml
new file mode 100644
index 00000000000..a2ae2059c47
--- /dev/null
+++ b/changelogs/unreleased/40122-only-one-note-webhook-is-triggered-when-a-comment-with-time-spent-is-added.yml
@@ -0,0 +1,5 @@
+---
+title: Add total_time_spent to the `changes` hash in issuable Webhook payloads
+merge_request: 15381
+author:
+type: changed
diff --git a/doc/user/project/pages/getting_started_part_one.md b/doc/user/project/pages/getting_started_part_one.md
index 453e10184f0..1e19f422d94 100644
--- a/doc/user/project/pages/getting_started_part_one.md
+++ b/doc/user/project/pages/getting_started_part_one.md
@@ -62,7 +62,7 @@ which is highly recommendable and much faster than hardcoding.
If you set up a GitLab Pages project on GitLab.com,
it will automatically be accessible under a
-[subdomain of `namespace.pages.io`](introduction.md#gitlab-pages-on-gitlab-com).
+[subdomain of `namespace.gitlab.io`](introduction.md#gitlab-pages-on-gitlab-com).
The `namespace` is defined by your username on GitLab.com,
or the group name you created this project under.
diff --git a/lib/backup/repository.rb b/lib/backup/repository.rb
index 3ad09a1b421..b6d273b98c2 100644
--- a/lib/backup/repository.rb
+++ b/lib/backup/repository.rb
@@ -7,12 +7,16 @@ module Backup
prepare
Project.find_each(batch_size: 1000) do |project|
- progress.print " * #{project.full_path} ... "
+ progress.print " * #{display_repo_path(project)} ... "
path_to_project_repo = path_to_repo(project)
path_to_project_bundle = path_to_bundle(project)
- # Create namespace dir if missing
- FileUtils.mkdir_p(File.join(backup_repos_path, project.namespace.full_path)) if project.namespace
+ # Create namespace dir or hashed path if missing
+ if project.hashed_storage?(:repository)
+ FileUtils.mkdir_p(File.dirname(File.join(backup_repos_path, project.disk_path)))
+ else
+ FileUtils.mkdir_p(File.join(backup_repos_path, project.namespace.full_path)) if project.namespace
+ end
if empty_repo?(project)
progress.puts "[SKIPPED]".color(:cyan)
@@ -42,7 +46,7 @@ module Backup
path_to_wiki_bundle = path_to_bundle(wiki)
if File.exist?(path_to_wiki_repo)
- progress.print " * #{wiki.full_path} ... "
+ progress.print " * #{display_repo_path(wiki)} ... "
if empty_repo?(wiki)
progress.puts " [SKIPPED]".color(:cyan)
else
@@ -71,7 +75,7 @@ module Backup
end
Project.find_each(batch_size: 1000) do |project|
- progress.print " * #{project.full_path} ... "
+ progress.print " * #{display_repo_path(project)} ... "
path_to_project_repo = path_to_repo(project)
path_to_project_bundle = path_to_bundle(project)
@@ -104,7 +108,7 @@ module Backup
path_to_wiki_bundle = path_to_bundle(wiki)
if File.exist?(path_to_wiki_bundle)
- progress.print " * #{wiki.full_path} ... "
+ progress.print " * #{display_repo_path(wiki)} ... "
# If a wiki bundle exists, first remove the empty repo
# that was initialized with ProjectWiki.new() and then
@@ -185,14 +189,14 @@ module Backup
def progress_warn(project, cmd, output)
progress.puts "[WARNING] Executing #{cmd}".color(:orange)
- progress.puts "Ignoring error on #{project.full_path} - #{output}".color(:orange)
+ progress.puts "Ignoring error on #{display_repo_path(project)} - #{output}".color(:orange)
end
def empty_repo?(project_or_wiki)
project_or_wiki.repository.expire_exists_cache # protect backups from stale cache
project_or_wiki.repository.empty_repo?
rescue => e
- progress.puts "Ignoring repository error and continuing backing up project: #{project_or_wiki.full_path} - #{e.message}".color(:orange)
+ progress.puts "Ignoring repository error and continuing backing up project: #{display_repo_path(project_or_wiki)} - #{e.message}".color(:orange)
false
end
@@ -204,5 +208,9 @@ module Backup
def progress
$progress
end
+
+ def display_repo_path(project)
+ project.hashed_storage?(:repository) ? "#{project.full_path} (#{project.disk_path})" : project.full_path
+ end
end
end
diff --git a/lib/gitlab/ee_compat_check.rb b/lib/gitlab/ee_compat_check.rb
index 0ea534a5fd0..efc2e46d289 100644
--- a/lib/gitlab/ee_compat_check.rb
+++ b/lib/gitlab/ee_compat_check.rb
@@ -193,7 +193,7 @@ module Gitlab
# Repository is initially cloned with a depth of 20 so we need to fetch
# deeper in the case the branch has more than 20 commits on top of master
fetch(branch: branch, depth: depth)
- fetch(branch: 'master', depth: depth)
+ fetch(branch: 'master', depth: depth, remote: DEFAULT_CE_PROJECT_URL)
merge_base_found?
end
@@ -201,10 +201,10 @@ module Gitlab
raise "\n#{branch} is too far behind master, please rebase it!\n" unless success
end
- def fetch(branch:, depth:)
+ def fetch(branch:, depth:, remote: 'origin')
step(
"Fetching deeper...",
- %W[git fetch --depth=#{depth} --prune origin +refs/heads/#{branch}:refs/remotes/origin/#{branch}]
+ %W[git fetch --depth=#{depth} --prune #{remote} +refs/heads/#{branch}:refs/remotes/origin/#{branch}]
) do |output, status|
raise "Fetch failed: #{output}" unless status.zero?
end
diff --git a/lib/gitlab/hook_data/issue_builder.rb b/lib/gitlab/hook_data/issue_builder.rb
index 196f2b6b34c..e29dd0d5b0e 100644
--- a/lib/gitlab/hook_data/issue_builder.rb
+++ b/lib/gitlab/hook_data/issue_builder.rb
@@ -28,6 +28,7 @@ module Gitlab
SAFE_HOOK_RELATIONS = %i[
assignees
labels
+ total_time_spent
].freeze
attr_accessor :issue
diff --git a/lib/gitlab/hook_data/merge_request_builder.rb b/lib/gitlab/hook_data/merge_request_builder.rb
index 503452c8ff3..ae9b68eb648 100644
--- a/lib/gitlab/hook_data/merge_request_builder.rb
+++ b/lib/gitlab/hook_data/merge_request_builder.rb
@@ -33,6 +33,7 @@ module Gitlab
SAFE_HOOK_RELATIONS = %i[
assignee
labels
+ total_time_spent
].freeze
attr_accessor :merge_request
diff --git a/spec/lib/gitlab/hook_data/issuable_builder_spec.rb b/spec/lib/gitlab/hook_data/issuable_builder_spec.rb
index 30da56bec16..26529c4759d 100644
--- a/spec/lib/gitlab/hook_data/issuable_builder_spec.rb
+++ b/spec/lib/gitlab/hook_data/issuable_builder_spec.rb
@@ -41,7 +41,8 @@ describe Gitlab::HookData::IssuableBuilder do
labels: [
[{ id: 1, title: 'foo' }],
[{ id: 1, title: 'foo' }, { id: 2, title: 'bar' }]
- ]
+ ],
+ total_time_spent: [1, 2]
}
end
let(:data) { builder.build(user: user, changes: changes) }
@@ -53,6 +54,10 @@ describe Gitlab::HookData::IssuableBuilder do
labels: {
previous: [{ id: 1, title: 'foo' }],
current: [{ id: 1, title: 'foo' }, { id: 2, title: 'bar' }]
+ },
+ total_time_spent: {
+ previous: 1,
+ current: 2
}
}))
end
diff --git a/spec/models/concerns/issuable_spec.rb b/spec/models/concerns/issuable_spec.rb
index ba57301a3c9..4dfbb14952e 100644
--- a/spec/models/concerns/issuable_spec.rb
+++ b/spec/models/concerns/issuable_spec.rb
@@ -265,25 +265,44 @@ describe Issuable do
end
describe '#to_hook_data' do
+ let(:builder) { double }
+
context 'labels are updated' do
let(:labels) { create_list(:label, 2) }
before do
issue.update(labels: [labels[1]])
+ expect(Gitlab::HookData::IssuableBuilder)
+ .to receive(:new).with(issue).and_return(builder)
end
it 'delegates to Gitlab::HookData::IssuableBuilder#build' do
- builder = double
+ expect(builder).to receive(:build).with(
+ user: user,
+ changes: hash_including(
+ 'labels' => [[labels[0].hook_attrs], [labels[1].hook_attrs]]
+ ))
+ issue.to_hook_data(user, old_labels: [labels[0]])
+ end
+ end
+
+ context 'total_time_spent is updated' do
+ before do
+ issue.spend_time(duration: 2, user: user, spent_at: Time.now)
+ issue.save
expect(Gitlab::HookData::IssuableBuilder)
.to receive(:new).with(issue).and_return(builder)
+ end
+
+ it 'delegates to Gitlab::HookData::IssuableBuilder#build' do
expect(builder).to receive(:build).with(
user: user,
changes: hash_including(
- 'labels' => [[labels[0].hook_attrs], [labels[1].hook_attrs]]
+ 'total_time_spent' => [1, 2]
))
- issue.to_hook_data(user, old_labels: [labels[0]])
+ issue.to_hook_data(user, old_total_time_spent: 1)
end
end
@@ -292,13 +311,11 @@ describe Issuable do
before do
issue.assignees << user << user2
+ expect(Gitlab::HookData::IssuableBuilder)
+ .to receive(:new).with(issue).and_return(builder)
end
it 'delegates to Gitlab::HookData::IssuableBuilder#build' do
- builder = double
-
- expect(Gitlab::HookData::IssuableBuilder)
- .to receive(:new).with(issue).and_return(builder)
expect(builder).to receive(:build).with(
user: user,
changes: hash_including(
@@ -316,13 +333,11 @@ describe Issuable do
before do
merge_request.update(assignee: user)
merge_request.update(assignee: user2)
+ expect(Gitlab::HookData::IssuableBuilder)
+ .to receive(:new).with(merge_request).and_return(builder)
end
it 'delegates to Gitlab::HookData::IssuableBuilder#build' do
- builder = double
-
- expect(Gitlab::HookData::IssuableBuilder)
- .to receive(:new).with(merge_request).and_return(builder)
expect(builder).to receive(:build).with(
user: user,
changes: hash_including(
diff --git a/spec/models/project_wiki_spec.rb b/spec/models/project_wiki_spec.rb
index 3d46434fc27..929086305ba 100644
--- a/spec/models/project_wiki_spec.rb
+++ b/spec/models/project_wiki_spec.rb
@@ -10,6 +10,10 @@ describe ProjectWiki do
subject { project_wiki }
+ it { is_expected.to delegate_method(:empty?).to :pages }
+ it { is_expected.to delegate_method(:repository_storage_path).to :project }
+ it { is_expected.to delegate_method(:hashed_storage?).to :project }
+
describe "#path_with_namespace" do
it "returns the project path with namespace with the .wiki extension" do
expect(subject.path_with_namespace).to eq(project.full_path + '.wiki')
diff --git a/spec/services/merge_requests/update_service_spec.rb b/spec/services/merge_requests/update_service_spec.rb
index 98409be4236..5ce6ca70c83 100644
--- a/spec/services/merge_requests/update_service_spec.rb
+++ b/spec/services/merge_requests/update_service_spec.rb
@@ -80,7 +80,7 @@ describe MergeRequests::UpdateService, :mailer do
it 'executes hooks with update action' do
expect(service)
.to have_received(:execute_hooks)
- .with(@merge_request, 'update', old_labels: [], old_assignees: [user3])
+ .with(@merge_request, 'update', old_labels: [], old_assignees: [user3], old_total_time_spent: 0)
end
it 'sends email to user2 about assign of new merge request and email to user3 about merge request unassignment' do