git_tag_push_service.rb 948 Bytes
Newer Older
1
2
class GitTagPushService
  attr_accessor :project, :user, :push_data
3

4
  def execute(project, user, oldrev, newrev, ref)
5
    @project, @user = project, user
6

Douwe Maan's avatar
Douwe Maan committed
7
    @push_data = build_push_data(oldrev, newrev, ref)
8

9
    EventCreateService.new.push(project, user, @push_data)
10
    project.execute_hooks(@push_data.dup, :tag_push_hooks)
Douwe Maan's avatar
Douwe Maan committed
11
    project.execute_services(@push_data.dup, :tag_push_hooks)
12

Douwe Maan's avatar
Douwe Maan committed
13
14
    project.repository.expire_cache

15
    true
16
17
18
19
  end

  private

Douwe Maan's avatar
Douwe Maan committed
20
  def build_push_data(oldrev, newrev, ref)
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
    commits = []
    message = nil

    if !Gitlab::Git.blank_ref?(newrev)
      tag_name = Gitlab::Git.ref_name(ref)
      tag = project.repository.find_tag(tag_name)
      if tag && tag.target == newrev
        commit = project.repository.commit(tag.target)
        commits = [commit].compact
        message = tag.message
      end
    end

    Gitlab::PushDataBuilder.
      build(project, user, oldrev, newrev, ref, commits, message)
36
37
  end
end