diff options
author | Tiago Botelho <tiagonbotelho@hotmail.com> | 2018-01-19 16:04:14 +0300 |
---|---|---|
committer | Tiago Botelho <tiagonbotelho@hotmail.com> | 2018-02-06 16:35:35 +0300 |
commit | 32b2ff26011a5274bdb8a3dd41ad360a67c3148a (patch) | |
tree | 56064e3de4e9ca505730bdf1af3597ba8ead499f /lib/gitlab/checks | |
parent | 35882e681b681f68a818bda9a8d2624edfecc219 (diff) |
Adds remote messsage when project is created in a push over SSH or HTTP
Diffstat (limited to 'lib/gitlab/checks')
-rw-r--r-- | lib/gitlab/checks/new_project.rb | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/lib/gitlab/checks/new_project.rb b/lib/gitlab/checks/new_project.rb new file mode 100644 index 00000000000..40d0acefaba --- /dev/null +++ b/lib/gitlab/checks/new_project.rb @@ -0,0 +1,60 @@ +module Gitlab + module Checks + class NewProject + NEW_PROJECT = "new_project".freeze + + def initialize(user, project, protocol) + @user = user + @project = project + @protocol = protocol + end + + def self.fetch_new_project_message(user_id, project_id) + new_project_key = new_project_message_key(user_id, project_id) + + Gitlab::Redis::SharedState.with do |redis| + message = redis.get(new_project_key) + redis.del(new_project_key) + message + end + end + + def add_new_project_message + Gitlab::Redis::SharedState.with do |redis| + key = self.class.new_project_message_key(user.id, project.id) + redis.setex(key, 5.minutes, new_project_message) + end + end + + def new_project_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.new_project_message_key(user_id, project_id) + "#{NEW_PROJECT}:#{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 |