2018-01-19 08:04:14 -05:00
|
|
|
module Gitlab
|
|
|
|
module Checks
|
2018-01-25 07:26:52 -05:00
|
|
|
class ProjectCreated
|
|
|
|
PROJECT_CREATED = "project_created".freeze
|
2018-01-19 08:04:14 -05:00
|
|
|
|
|
|
|
def initialize(user, project, protocol)
|
|
|
|
@user = user
|
|
|
|
@project = project
|
|
|
|
@protocol = protocol
|
|
|
|
end
|
|
|
|
|
2018-01-25 07:26:52 -05:00
|
|
|
def self.fetch_project_created_message(user_id, project_id)
|
|
|
|
project_created_key = project_created_message_key(user_id, project_id)
|
2018-01-19 08:04:14 -05:00
|
|
|
|
|
|
|
Gitlab::Redis::SharedState.with do |redis|
|
2018-01-25 07:26:52 -05:00
|
|
|
message = redis.get(project_created_key)
|
|
|
|
redis.del(project_created_key)
|
2018-01-19 08:04:14 -05:00
|
|
|
message
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-01-25 07:26:52 -05:00
|
|
|
def add_project_created_message
|
2018-01-22 13:10:56 -05:00
|
|
|
return unless user.present? && project.present?
|
|
|
|
|
2018-01-19 08:04:14 -05:00
|
|
|
Gitlab::Redis::SharedState.with do |redis|
|
2018-01-25 07:26:52 -05:00
|
|
|
key = self.class.project_created_message_key(user.id, project.id)
|
|
|
|
redis.setex(key, 5.minutes, project_created_message)
|
2018-01-19 08:04:14 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-01-25 07:26:52 -05:00
|
|
|
def project_created_message
|
2018-01-19 08:04:14 -05:00
|
|
|
<<~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
|
|
|
|
|
2018-01-25 07:26:52 -05:00
|
|
|
def self.project_created_message_key(user_id, project_id)
|
|
|
|
"#{PROJECT_CREATED}:#{user_id}:#{project_id}"
|
2018-01-19 08:04:14 -05:00
|
|
|
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
|