Module: Gitlab::Client::ProjectBadges

Included in:
Gitlab::Client
Defined in:
lib/gitlab/client/project_badges.rb

Overview

Defines methods related to project badges.

Instance Method Summary collapse

Instance Method Details

#add_project_badge(project, options = {}) ⇒ Gitlab::ObjectifiedHash

Adds a badge to a project.

Examples:

Gitlab.add_project_badge(5, { link_url: 'https://abc.com/gitlab/gitlab-ce/commits/master', image_url: 'https://shields.io/my/badge1' })

Parameters:

  • project (Integer, String)

    The ID or name of a project.

  • options (Hash) (defaults to: {})

    A customizable set of options.

Options Hash (options):

  • :link_url(required) (String)

    URL of the badge link

  • :image_url(required) (String)

    URL of the badge image

Returns:



40
41
42
# File 'lib/gitlab/client/project_badges.rb', line 40

def add_project_badge(project, options = {})
  post("/projects/#{url_encode project}/badges", body: options)
end

#edit_project_badge(project, badge_id, options = {}) ⇒ Gitlab::ObjectifiedHash

Updates a badge of a project..

Examples:

Gitlab.edit_project_badge(5, 1, { link_url: 'https://abc.com/gitlab/gitlab-ce/commits/master', image_url: 'https://shields.io/my/badge1' })

Parameters:

  • project (Integer, String)

    The ID or name of a project.

  • badge_id (Integer)

    The badge ID.

  • options (Hash) (defaults to: {})

    A customizable set of options.

Options Hash (options):

  • :link_url(optional) (String)

    URL of the badge link

  • :image_url(optional) (String)

    URL of the badge image

Returns:



55
56
57
# File 'lib/gitlab/client/project_badges.rb', line 55

def edit_project_badge(project, badge_id, options = {})
  put("/projects/#{url_encode project}/badges/#{badge_id}", body: options)
end

#preview_project_badge(project, link_url, image_url) ⇒ Gitlab::ObjectifiedHash

Preview a badge from a project.

Examples:

Gitlab.preview_project_badge(3, 'https://abc.com/gitlab/gitlab-ce/commits/master', 'https://shields.io/my/badge1')

Parameters:

  • project (Integer, String)

    The ID or name of a project.

  • :link_url (String)

    URL of the badge link

  • :image_url (String)

    URL of the badge image

Returns:

  • (Gitlab::ObjectifiedHash)

    Returns how the link_url and image_url final URLs would be after resolving the placeholder interpolation.



80
81
82
83
# File 'lib/gitlab/client/project_badges.rb', line 80

def preview_project_badge(project, link_url, image_url)
  query = { link_url: link_url, image_url: image_url }
  get("/projects/#{url_encode project}/badges/render", query: query)
end

#project_badge(project, badge_id) ⇒ Gitlab::ObjectifiedHash

Gets a badge of a project.

Examples:

Gitlab.project_badge(5, 42)

Parameters:

  • project (Integer, String)

    The ID or name of a project.

  • badge_id (Integer)

    The badge ID.

Returns:



26
27
28
# File 'lib/gitlab/client/project_badges.rb', line 26

def project_badge(project, badge_id)
  get("/projects/#{url_encode project}/badges/#{badge_id}")
end

#project_badges(project) ⇒ Array<Gitlab::ObjectifiedHash>

Gets a list of a projects badges and its group badges.

Examples:

Gitlab.project_badges(5)

Parameters:

  • project (Integer, String)

    The ID or name of a project.

Returns:



14
15
16
# File 'lib/gitlab/client/project_badges.rb', line 14

def project_badges(project)
  get("/projects/#{url_encode project}/badges")
end

#remove_project_badge(project, badge_id) ⇒ nil

Removes a badge from a project. Only projects badges will be removed by using this endpoint.

Examples:

Gitlab.remove_project_badge(5, 42)

Parameters:

  • project (Integer, String)

    The ID or name of a project.

  • badge_id (Integer)

    The badge ID.

Returns:

  • (nil)

    This API call returns an empty response body.



67
68
69
# File 'lib/gitlab/client/project_badges.rb', line 67

def remove_project_badge(project, badge_id)
  delete("/projects/#{url_encode project}/badges/#{badge_id}")
end