Class: Gitomator::GitHub::TaggingProvider
Class Method Summary
collapse
Instance Method Summary
collapse
-
#add_tags(repo, issue_or_pr_id, *tags) ⇒ Object
-
#delete_metadata(repo, tag) ⇒ Object
-
#metadata(repo, tag = nil) ⇒ Object
-
#remove_tag(repo, id_or_name, tag) ⇒ Object
-
#search(repo, label) ⇒ Object
Enumerable of object identifiers.
-
#set_metadata(repo, tag, metadata) ⇒ Object
-
#tags(repo, id_or_name) ⇒ Object
#initialize, #name
Class Method Details
Returns GitHub hosting provider.
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
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
|
88
89
90
|
# File 'lib/gitomator/github/tagging_provider.rb', line 88
def delete_metadata(repo, tag)
@gh.delete_label!(@repo_name_resolver.full_name(repo), tag)
end
|
57
58
59
60
61
62
63
64
65
66
67
68
69
|
# File 'lib/gitomator/github/tagging_provider.rb', line 57
def metadata(repo, tag=nil)
repo = @repo_name_resolver.full_name(repo)
if tag
begin
@gh.label(repo, tag).to_h
rescue Octokit::NotFound
return nil
end
else
@gh.labels(repo).map {|r| [r.name, r.to_h]}.to_h
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 }
end
|
#search(repo, label) ⇒ Object
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}
else
raise "Unimplemented! Search only supports a single tag at the moment."
end
end
|
73
74
75
76
77
78
79
80
81
82
83
84
85
|
# File 'lib/gitomator/github/tagging_provider.rb', line 73
def set_metadata(repo, tag, metadata)
repo = @repo_name_resolver.full_name(repo)
color = metadata[:color] || metadata['color']
raise "The only supported metadata property is 'color'" if color.nil?
if metadata(repo, tag).nil?
@gh.add_label(repo, tag, color).to_h
else
@gh.update_label(repo, tag, {:color => color}).to_h
end
end
|
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
|