Class: SupportOps::GitLab::Badges

Inherits:
Base
  • Object
show all
Defined in:
lib/support_ops_gitlab/gitlab/badges.rb

Overview

Defines the class Badges within the module SupportOps::GitLab.

Author:

  • Jason Colyer

Since:

  • 1.0.0

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#activate!, #approve!, attributes, #badges, #ban!, #block!, client, #client=, #commits, configure, #contributors, #create_support_pin!, #deactivate!, define_attributes, #diffs, #disable_2fa!, #discussions, #emails, #encoded_path, #events, #find, #find!, #gpg_keys, #hard_delete!, #impersonations, #initialize, #issues, #jobs, #latest_pipeline, #members, #memberships, #merge_requests, #move!, #notes, #paid?, #pats, #pipeline_variables, #pipelines, #preferences, #projects, readonly_attributes, #reject!, #revoke!, #rotate!, #ssh_keys, #status, #store_original_attributes, #subscribe!, #support_pin, to_hash, #tokens, #unban!, #unblock!, #unsubscribe!, #webhooks

Constructor Details

This class inherits a constructor from SupportOps::GitLab::Base

Instance Attribute Details

#group_idInteger

The ID of the group the badge is in

Returns:

  • (Integer)

    the current value of group_id



25
26
27
# File 'lib/support_ops_gitlab/gitlab/badges.rb', line 25

def group_id
  @group_id
end

#idInteger

The ID of the badge

Returns:

  • (Integer)

    the current value of id



25
26
27
# File 'lib/support_ops_gitlab/gitlab/badges.rb', line 25

def id
  @id
end

#image_urlString

URL of the badge image

Returns:

  • (String)

    the current value of image_url



25
26
27
# File 'lib/support_ops_gitlab/gitlab/badges.rb', line 25

def image_url
  @image_url
end

#kindString

The type of badge it is (project or group)

Returns:

  • (String)

    the current value of kind



25
26
27
# File 'lib/support_ops_gitlab/gitlab/badges.rb', line 25

def kind
  @kind
end

URL of the badge link

Returns:

  • (String)

    the current value of link_url



25
26
27
# File 'lib/support_ops_gitlab/gitlab/badges.rb', line 25

def link_url
  @link_url
end

#nameString

Name of the badge

Returns:

  • (String)

    the current value of name



25
26
27
# File 'lib/support_ops_gitlab/gitlab/badges.rb', line 25

def name
  @name
end

#project_idInteger

The ID of the project the badge is in

Returns:

  • (Integer)

    the current value of project_id



25
26
27
# File 'lib/support_ops_gitlab/gitlab/badges.rb', line 25

def project_id
  @project_id
end

#rendered_image_urlString

The URL of the rendered badge image

Returns:

  • (String)

    the current value of rendered_image_url



25
26
27
# File 'lib/support_ops_gitlab/gitlab/badges.rb', line 25

def rendered_image_url
  @rendered_image_url
end

The URL of the rendered badge link

Returns:

  • (String)

    the current value of rendered_link_url



25
26
27
# File 'lib/support_ops_gitlab/gitlab/badges.rb', line 25

def rendered_link_url
  @rendered_link_url
end

Class Method Details

.list(**args) ⇒ Array

List all badges

overload list(key: value)

@param group_id [Integer semi-optional] The ID of the group to get
  badges from
@param name [String optional] Name of the badges to return
  (case-sensitive)
@param project_id [Integer semi-optional] The ID of the project to get
  badges from

#see

https://docs.gitlab.com/api/group_badges/#list-all-badges-of-a-group
GitLab API > Groups > Badges > List all badges of a group

#see

https://docs.gitlab.com/api/project_badges/#list-all-badges-of-a-project
GitLab API > Project > Badges > List all badges of a project

Examples:

require 'support_ops_gitlab'

SupportOps::GitLab::Configuration.configure do |config|
  config.url = 'https://gitlab.example.com/api/v4'
  config.token = 'abc123'
end

tokens = SupportOps::GitLab::ProjectAccessTokens.list(project_id: 5, limit: 10)
pp tokens.count
# => 10
pp tokens.last.revoked
# => false

Returns:

  • (Array)

Author:

  • Jason Colyer

Since:

  • 1.0.0



142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
# File 'lib/support_ops_gitlab/gitlab/badges.rb', line 142

def self.list(**args)
  args[:group_id] = nil unless args[:group_id]
  args[:project_id] = nil unless args[:project_id]
  args[:name] = nil unless args[:name]
  params = ''
  params += "name=#{args[:name]}&" unless args[:name].nil?
  url = if args[:group_id].nil? && !args[:project_id].nil?
          "projects/#{args[:project_id]}/badges"
        elsif !args[:group_id].nil? && args[:project_id].nil?
          "groups/#{args[:group_id]}/badges"
        else
          raise 'You have to provide a group_id or a project_id (and you cannot provide both)'
        end
  array = []
  page = 1
  loop do
    response = client.connection.get("#{url}?#{params}&page=#{page}&per_page=100")
    body = Oj.load(response.body)
    array += body.map do |b|
      if args[:group_id].nil? && !args[:project_id].nil?
        b['project_id'] = args[:project_id]
      elsif !args[:group_id].nil? && args[:project_id].nil?
        b['group_id'] = args[:group_id]
      else
        raise 'You have to provide a group_id or a project_id (and you cannot provide both)'
      end
      Badges.new(b)
    end
    break if body.count < 100

    page += 1
  end
  array
end

Instance Method Details

#delete!Boolean

Note:

This is inherited from SupportOps::GitLab::Base#delete!

Deletes a badge

Examples:

require 'support_ops_gitlab'

SupportOps::GitLab::Configuration.configure do |config|
  config.token = ENV.fetch('GL_TOKEN')
  config.url = 'https://gitlab.com/api/v4'
end

badges = SupportOps::GitLab::Badges.list(project_id: 123)
badge = badges.last
badge.delete!

Returns:

  • (Boolean)

See Also:

Author:

  • Jason Colyer

Since:

  • 1.0.0



24
# File 'lib/support_ops_gitlab/gitlab/badges.rb', line 24

def delete!; end

#save!Object

Note:

This is inherited from SupportOps::GitLab::Base#save!

Creates/updates a badge

Examples:

require 'support_ops_gitlab'

SupportOps::GitLab::Configuration.configure do |config|
  config.token = ENV.fetch('GL_TOKEN')
  config.url = 'https://gitlab.com/api/v4'
end

new_badge = SupportOps::GitLab::Badges.new
new_badge.name = 'Awesome Badge'
new_badge.link_url = 'https://google.com'
new_badge.image_url = 'https://img.shields.io/badge/Awesome-Badge-purple'
new_badge.group_id = 1

new_badge.save!

pp new_badge.id
# => 33
require 'support_ops_gitlab'

SupportOps::GitLab::Configuration.configure do |config|
  config.token = ENV.fetch('GL_TOKEN')
  config.url = 'https://gitlab.com/api/v4'
end

badges = SupportOps::GitLab::Badges.list(project_id: 123)
badge = badges.last
badge.link_url = 'https://duckduckgo.com/'

badge.save!

pp badge.rendered_link_url
# => "https://duckduckgo.com/"

Returns:

See Also:

Author:

  • Jason Colyer

Since:

  • 1.0.0



53
# File 'lib/support_ops_gitlab/gitlab/badges.rb', line 53

def save!; end