Read about our upcoming Code of Conduct on this issue

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

4
  def execute(project, user, oldrev, newrev, ref)
5
    project.repository.expire_cache
6

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

10
    EventCreateService.new.push(project, user, @push_data)
11
    project.execute_hooks(@push_data.dup, :tag_push_hooks)
Douwe Maan's avatar
Douwe Maan committed
12
    project.execute_services(@push_data.dup, :tag_push_hooks)
13
    CreateCommitBuildsService.new.execute(project, @user, @push_data)
14
    ProjectCacheWorker.perform_async(project.id)
Douwe Maan's avatar
Douwe Maan committed
15

16
    true
17
18
19
20
  end

  private

Douwe Maan's avatar
Douwe Maan committed
21
  def build_push_data(oldrev, newrev, ref)
22
23
24
25
26
27
28
    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
29
        commit = project.commit(tag.target)
30
31
32
33
34
35
36
        commits = [commit].compact
        message = tag.message
      end
    end

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