Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTiago Botelho <tiagonbotelho@hotmail.com>2018-01-25 15:26:52 +0300
committerTiago Botelho <tiagonbotelho@hotmail.com>2018-02-06 16:35:35 +0300
commite42a548f1dac02577d0c1731fef508dab68c45a5 (patch)
tree9781b82ec0da58683ebeb0fd0ba2062a9ce10e43 /lib/gitlab/checks/project_created.rb
parentbc78ae6985ee37f9ac2ffc2dbf6f445078d16038 (diff)
Move new project on push logic to a service
Diffstat (limited to 'lib/gitlab/checks/project_created.rb')
-rw-r--r--lib/gitlab/checks/project_created.rb62
1 files changed, 62 insertions, 0 deletions
diff --git a/lib/gitlab/checks/project_created.rb b/lib/gitlab/checks/project_created.rb
new file mode 100644
index 00000000000..f05e8b4a7e8
--- /dev/null
+++ b/lib/gitlab/checks/project_created.rb
@@ -0,0 +1,62 @@
+module Gitlab
+ module Checks
+ class ProjectCreated
+ PROJECT_CREATED = "project_created".freeze
+
+ def initialize(user, project, protocol)
+ @user = user
+ @project = project
+ @protocol = protocol
+ end
+
+ def self.fetch_project_created_message(user_id, project_id)
+ project_created_key = project_created_message_key(user_id, project_id)
+
+ Gitlab::Redis::SharedState.with do |redis|
+ message = redis.get(project_created_key)
+ redis.del(project_created_key)
+ message
+ end
+ end
+
+ def add_project_created_message
+ return unless user.present? && project.present?
+
+ Gitlab::Redis::SharedState.with do |redis|
+ key = self.class.project_created_message_key(user.id, project.id)
+ redis.setex(key, 5.minutes, project_created_message)
+ end
+ end
+
+ def project_created_message
+ <<~MESSAGE.strip_heredoc
+
+ The private project #{project.full_path} was created.
+
+ To configure the remote, run:
+ git remote add origin #{git_url}
+
+ To view the project, visit:
+ #{project_url}
+
+ MESSAGE
+ end
+
+ private
+
+ attr_reader :project, :user, :protocol
+
+ def self.project_created_message_key(user_id, project_id)
+ "#{PROJECT_CREATED}:#{user_id}:#{project_id}"
+ end
+
+ def project_url
+ Gitlab::Routing.url_helpers.project_url(project)
+ end
+
+ def git_url
+ protocol == 'ssh' ? project.ssh_url_to_repo : project.http_url_to_repo
+ end
+ end
+ end
+end