summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTakuya Noguchi <takninnovationresearch@gmail.com>2018-08-30 12:00:18 +0200
committerTakuya Noguchi <takninnovationresearch@gmail.com>2018-08-31 10:27:41 +0900
commit7a57e59e1af9c2e3439c3d079515ea9164d16451 (patch)
tree7b382d5412eb98080f81660c1ca834884b969cdc
parent3a0f3082af181c027df53cc367fc345f7fa52340 (diff)
downloadgitlab-ce-7a57e59e1af9c2e3439c3d079515ea9164d16451.tar.gz
Use sample data for push event when no commits created
-rw-r--r--changelogs/unreleased/50564-chat-service-refactoring.yml5
-rw-r--r--lib/gitlab/data_builder/push.rb8
2 files changed, 11 insertions, 2 deletions
diff --git a/changelogs/unreleased/50564-chat-service-refactoring.yml b/changelogs/unreleased/50564-chat-service-refactoring.yml
new file mode 100644
index 00000000000..aec5e8fab0a
--- /dev/null
+++ b/changelogs/unreleased/50564-chat-service-refactoring.yml
@@ -0,0 +1,5 @@
+---
+title: Use sample data for push event when no commits created
+merge_request: 21440
+author: Takuya Noguchi
+type: fixed
diff --git a/lib/gitlab/data_builder/push.rb b/lib/gitlab/data_builder/push.rb
index c169c8fe135..b498f113859 100644
--- a/lib/gitlab/data_builder/push.rb
+++ b/lib/gitlab/data_builder/push.rb
@@ -97,11 +97,15 @@ module Gitlab
}
end
- # This method provide a sample data generated with
+ # This method provides a sample data generated with
# existing project and commits to test webhooks
def build_sample(project, user)
+ # Use sample data if repo has no commit
+ # (expect the case of test service configuration settings)
+ return sample_data if project.empty_repo?
+
ref = "#{Gitlab::Git::BRANCH_REF_PREFIX}#{project.default_branch}"
- commits = project.repository.commits(project.default_branch.to_s, limit: 3) rescue []
+ commits = project.repository.commits(project.default_branch.to_s, limit: 3)
build(project, user, commits.last&.id, commits.first&.id, ref, commits)
end