Class: Retag::Repo

Inherits:
Object
  • Object
show all
Includes:
Utils
Defined in:
lib/retag/repo.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Utils

#cmd!, #dockerauth

Constructor Details

#initialize(repo, branch) ⇒ Repo

Returns a new instance of Repo.



8
9
10
11
12
# File 'lib/retag/repo.rb', line 8

def initialize(repo, branch)
  @repo = repo
  @branch = branch
  @gitlab = Gitlab.client
end

Instance Attribute Details

#branchObject (readonly)

Returns the value of attribute branch.



6
7
8
# File 'lib/retag/repo.rb', line 6

def branch
  @branch
end

#nameObject (readonly)

Returns the value of attribute name.



6
7
8
# File 'lib/retag/repo.rb', line 6

def name
  @name
end

#repoObject (readonly)

Returns the value of attribute repo.



6
7
8
# File 'lib/retag/repo.rb', line 6

def repo
  @repo
end

#revisionObject (readonly)

Returns the value of attribute revision.



6
7
8
# File 'lib/retag/repo.rb', line 6

def revision
  @revision
end

Instance Method Details

#tag!(tag, message: nil) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/retag/repo.rb', line 14

def tag!(tag, message: nil)
  begin
    result = @gitlab.tag(name, tag)
    if result.to_h.dig('commit', 'short_id').to_s == revision
      # Success: tag with same revision already exists
      return true
    end
  rescue Gitlab::Error::NotFound
    # Success: there is no such tag
  end
  
  @gitlab.create_tag(name, tag, revision, message)
end