debian-mirror-gitlab/lib/gitlab/checks/post_push_message.rb

63 lines
1.5 KiB
Ruby
Raw Normal View History

2018-12-13 13:39:08 +05:30
# frozen_string_literal: true
2018-03-17 18:26:18 +05:30
module Gitlab
module Checks
class PostPushMessage
2020-04-08 14:13:33 +05:30
def initialize(repository, user, protocol)
@repository = repository
2018-03-17 18:26:18 +05:30
@user = user
@protocol = protocol
end
2021-09-30 23:02:18 +05:30
def self.fetch_message(user, repository)
key = message_key(user, repository)
# Also check for messages in the legacy key
# TODO: Remove in the next release
# https://gitlab.com/gitlab-org/gitlab/-/issues/292030
legacy_key = legacy_message_key(user, repository) if respond_to?(:legacy_message_key)
2018-03-17 18:26:18 +05:30
Gitlab::Redis::SharedState.with do |redis|
message = redis.get(key)
redis.del(key)
2021-09-30 23:02:18 +05:30
if legacy_key
legacy_message = redis.get(legacy_key)
redis.del(legacy_key)
end
legacy_message || message
2018-03-17 18:26:18 +05:30
end
end
def add_message
2021-09-30 23:02:18 +05:30
return unless user && repository
2018-03-17 18:26:18 +05:30
Gitlab::Redis::SharedState.with do |redis|
2021-09-30 23:02:18 +05:30
key = self.class.message_key(user, repository)
2018-03-17 18:26:18 +05:30
redis.setex(key, 5.minutes, message)
end
end
def message
raise NotImplementedError
end
protected
2020-04-08 14:13:33 +05:30
attr_reader :repository, :user, :protocol
delegate :project, to: :repository, allow_nil: true
delegate :container, to: :repository, allow_nil: false
2018-03-17 18:26:18 +05:30
2021-09-30 23:02:18 +05:30
def self.message_key(user, repository)
2018-03-17 18:26:18 +05:30
raise NotImplementedError
end
def url_to_repo
2021-01-03 14:25:43 +05:30
protocol == 'ssh' ? container.ssh_url_to_repo : container.http_url_to_repo
2018-03-17 18:26:18 +05:30
end
end
end
end