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

post_push_message.rb « checks « gitlab « lib - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: b3c981d252b615833fc50766a960d61ab6871124 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# frozen_string_literal: true

module Gitlab
  module Checks
    class PostPushMessage
      def initialize(repository, user, protocol)
        @repository = repository
        @user = user
        @protocol = protocol
      end

      def self.fetch_message(user_id, project_id)
        key = message_key(user_id, project_id)

        Gitlab::Redis::SharedState.with do |redis|
          message = redis.get(key)
          redis.del(key)
          message
        end
      end

      def add_message
        return unless user.present? && project.present?

        Gitlab::Redis::SharedState.with do |redis|
          key = self.class.message_key(user.id, project.id)
          redis.setex(key, 5.minutes, message)
        end
      end

      def message
        raise NotImplementedError
      end

      protected

      attr_reader :repository, :user, :protocol

      delegate :project, to: :repository, allow_nil: true
      delegate :container, to: :repository, allow_nil: false

      def self.message_key(user_id, project_id)
        raise NotImplementedError
      end

      def url_to_repo
        protocol == 'ssh' ? message_subject.ssh_url_to_repo : message_subject.http_url_to_repo
      end

      def message_subject
        repository.repo_type.wiki? ? project.wiki : container
      end
    end
  end
end