Class: Gitomator::GitHub::TaggingProvider

Inherits:
BaseProvider show all
Defined in:
lib/gitomator/github/tagging_provider.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from BaseProvider

#initialize, #name

Constructor Details

This class inherits a constructor from Gitomator::GitHub::BaseProvider

Class Method Details

.from_config(config = {}) ⇒ Gitomator::GitHub::HostingProvider

Returns GitHub hosting provider.

Parameters:

  • config (Hash<String,Object>) (defaults to: {})

Returns:



16
17
18
19
# File 'lib/gitomator/github/tagging_provider.rb', line 16

def self.from_config(config = {})
  return new(Gitomator::GitHub::github_client_from_config(config),
             config['organization'])
end

Instance Method Details

#add_tags(repo, issue_or_pr_id, *tags) ⇒ Object



24
25
26
27
28
# File 'lib/gitomator/github/tagging_provider.rb', line 24

def add_tags(repo, issue_or_pr_id, *tags)
  @gh.add_labels_to_an_issue(@repo_name_resolver.full_name(repo),
    issue_or_pr_id, tags
  ).map { |r| r.to_h }
end

#delete_metadata(repo, tag) ⇒ Object



88
89
90
# File 'lib/gitomator/github/tagging_provider.rb', line 88

def (repo, tag)
  @gh.delete_label!(@repo_name_resolver.full_name(repo), tag)
end

#metadata(repo, tag = nil) ⇒ Object



57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/gitomator/github/tagging_provider.rb', line 57

def (repo, tag=nil)
  repo = @repo_name_resolver.full_name(repo)

  if tag
    begin
      @gh.label(repo, tag).to_h   # Return metadata (Hash<Symbol,String>)
    rescue Octokit::NotFound
      return nil
    end
  else
    @gh.labels(repo).map {|r| [r.name, r.to_h]}.to_h  # Return Hash<String,Hash<Symbol,String>>, mapping tags to their metadata
  end
end

#remove_tag(repo, id_or_name, tag) ⇒ Object



30
31
32
33
# File 'lib/gitomator/github/tagging_provider.rb', line 30

def remove_tag(repo, id_or_name, tag)
  @gh.remove_label(@repo_name_resolver.full_name(repo), id_or_name, tag)
          .map { |r| r.to_h }  # Make the result a regular Ruby Hash
end

#search(repo, label) ⇒ Object

Returns Enumerable of object identifiers.

Returns:

  • Enumerable of object identifiers.



45
46
47
48
49
50
51
52
53
54
# File 'lib/gitomator/github/tagging_provider.rb', line 45

def search(repo, label)
  if label.is_a? String
    q = "repo:#{@repo_name_resolver.full_name(repo)} type:issue|pr label:\"#{label}\""
    @gh.search_issues(q)
      .items.map {|item| item.number}  # Make the result an array of issue/or id's
  else
    raise "Unimplemented! Search only supports a single tag at the moment."
  end

end

#set_metadata(repo, tag, metadata) ⇒ Object



73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'lib/gitomator/github/tagging_provider.rb', line 73

def (repo, tag, )
  repo = @repo_name_resolver.full_name(repo)
  color = [:color] || ['color']
  raise "The only supported metadata property is 'color'" if color.nil?
  # TODO: Validate the color string (6-char-long Hex string. Any other formats supproted by GitHub?)

  if (repo, tag).nil?
    @gh.add_label(repo, tag, color).to_h
  else
    @gh.update_label(repo, tag, {:color => color}).to_h
  end

end

#tags(repo, id_or_name) ⇒ Object



36
37
38
39
# File 'lib/gitomator/github/tagging_provider.rb', line 36

def tags(repo, id_or_name)
  repo = @repo_name_resolver.full_name(repo)
  @gh.labels_for_issue(repo, id_or_name).map {|r| r.name }
end