Module: Gitlab::Client::Projects

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

Overview

Defines methods related to projects.

Instance Method Summary collapse

Instance Method Details

#add_git_hook(id, options = {}) ⇒ Gitlab::ObjectifiedHash

Examples:

Gitlab.add_git_hook(42, { deny_delete_tag: false, commit_message_regex: '\\b[A-Z]{3}-[0-9]+\\b' })

Parameters:

  • id (Integer)

    The ID of a project.

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

    A customizable set of options.

  • option (Boolean)

    :deny_delete_tag Do not allow users to remove git tags with git push (0 = false, 1 = true)

  • option (String)

    :commit_message_regex Commit message regex

Returns:



273
274
275
# File 'lib/gitlab/client/projects.rb', line 273

def add_git_hook(id, options={})
  post("/projects/#{id}/git_hook", body: options)
end

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

Adds a new hook to the project.

Examples:

Gitlab.add_project_hook(42, 'https://api.example.net/v1/webhooks/ci')

Parameters:

  • project (Integer, String)

    The ID or name of a project.

  • url (String)

    The hook URL.

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

    A customizable set of options.

  • option (Boolean)

    :push_events Trigger hook on push events (0 = false, 1 = true)

  • option (Boolean)

    :issues_events Trigger hook on issues events (0 = false, 1 = true)

  • option (Boolean)

    :merge_requests_events Trigger hook on merge_requests events (0 = false, 1 = true)

  • option (Boolean)

    :tag_push_events Trigger hook on push_tag events (0 = false, 1 = true)

Returns:



214
215
216
217
# File 'lib/gitlab/client/projects.rb', line 214

def add_project_hook(project, url, options={})
  body = { url: url }.merge(options)
  post("/projects/#{project}/hooks", body: body)
end

#add_team_member(project, id, access_level) ⇒ Gitlab::ObjectifiedHash

Adds a user to project team.

Examples:

Gitlab.add_team_member('gitlab', 2, 40)

Parameters:

  • project (Integer, String)

    The ID or name of a project.

  • id (Integer)

    The ID of a user.

  • access_level (Integer)

    The access level to project.

  • options (Hash)

    A customizable set of options.

Returns:



142
143
144
# File 'lib/gitlab/client/projects.rb', line 142

def add_team_member(project, id, access_level)
  post("/projects/#{project}/members", body: { user_id: id, access_level: access_level })
end

#create_deploy_key(project, title, key) ⇒ Gitlab::ObjectifiedHash

Creates a new deploy key.

Examples:

Gitlab.create_deploy_key(42, 'My Key', 'Key contents')

Parameters:

  • project (Integer)

    The ID of a project.

  • title (String)

    The title of a deploy key.

  • key (String)

    The content of a deploy key.

Returns:



363
364
365
# File 'lib/gitlab/client/projects.rb', line 363

def create_deploy_key(project, title, key)
  post("/projects/#{project}/keys", body: { title: title, key: key })
end

#create_fork(id, options = {}) ⇒ Gitlab::ObjectifiedHash

Forks a project into the user namespace.

Examples:

Gitlab.create_fork(42)
Gitlab.create_fork(42, { sudo: 'another_username' })

Parameters:

  • project (Integer)

    The ID of a project.

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

    A customizable set of options.

Options Hash (options):

  • :sudo (String)

    The username the project will be forked for

Returns:



389
390
391
# File 'lib/gitlab/client/projects.rb', line 389

def create_fork(id, options={})
  post("/projects/fork/#{id}", body: options)
end

#create_project(name, options = {}) ⇒ Gitlab::ObjectifiedHash

Creates a new project.

Examples:

Gitlab.create_project('gitlab')
Gitlab.create_project('viking', { description: 'Awesome project' })
Gitlab.create_project('Red', { wall_enabled: false })

Parameters:

  • name (String)

    The name of a project.

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

    A customizable set of options.

Options Hash (options):

  • :description (String)

    The description of a project.

  • :default_branch (String)

    The default branch of a project.

  • :namespace_id (String)

    The namespace in which to create a project.

  • :wiki_enabled (Boolean)

    The wiki integration for a project (0 = false, 1 = true).

  • :wall_enabled (Boolean)

    The wall functionality for a project (0 = false, 1 = true).

  • :issues_enabled (Boolean)

    The issues integration for a project (0 = false, 1 = true).

  • :snippets_enabled (Boolean)

    The snippets integration for a project (0 = false, 1 = true).

  • :merge_requests_enabled (Boolean)

    The merge requests functionality for a project (0 = false, 1 = true).

  • :public (Boolean)

    The setting for making a project public (0 = false, 1 = true).

  • :user_id (Integer)

    The user/owner id of a project.

Returns:



88
89
90
91
# File 'lib/gitlab/client/projects.rb', line 88

def create_project(name, options={})
  url = options[:user_id] ? "/projects/user/#{options[:user_id]}" : "/projects"
  post(url, body: { name: name }.merge(options))
end

#delete_deploy_key(project, id) ⇒ Gitlab::ObjectifiedHash

Deletes a deploy key from project.

Examples:

Gitlab.delete_deploy_key(42, 1)

Parameters:

  • project (Integer)

    The ID of a project.

  • id (Integer)

    The ID of a deploy key.

Returns:



375
376
377
# File 'lib/gitlab/client/projects.rb', line 375

def delete_deploy_key(project, id)
  delete("/projects/#{project}/keys/#{id}")
end

#delete_git_hook(id, options = {}) ⇒ Gitlab::ObjectifiedHash

Deletes a git hook from a project. See: docs.gitlab.com/ee/api/projects.html#delete-project-git-hook

Examples:

Gitlab.delete_git_hook(42)

Parameters:

  • id (Integer)

    The ID of a project.

Returns:



300
301
302
# File 'lib/gitlab/client/projects.rb', line 300

def delete_git_hook(id, options={})
  delete("/projects/#{id}/git_hook")
end

#delete_project(id) ⇒ Gitlab::ObjectifiedHash

Deletes a project.

Examples:

Gitlab.delete_project(4)

Parameters:

  • id (Integer, String)

    The ID or name of a project.

Returns:



100
101
102
# File 'lib/gitlab/client/projects.rb', line 100

def delete_project(id)
  delete("/projects/#{id}")
end

#delete_project_hook(project, id) ⇒ Gitlab::ObjectifiedHash

Deletes a hook from project.

Examples:

Gitlab.delete_project_hook('gitlab', 4)

Parameters:

  • project (Integer, String)

    The ID or name of a project.

  • id (String)

    The ID of the hook.

Returns:



246
247
248
# File 'lib/gitlab/client/projects.rb', line 246

def delete_project_hook(project, id)
  delete("/projects/#{project}/hooks/#{id}")
end

#deploy_key(project, id) ⇒ Gitlab::ObjectifiedHash

Gets a single project deploy key.

Examples:

Gitlab.deploy_key(42, 1)

Parameters:

  • project (Integer, String)

    The ID of a project.

  • id (Integer)

    The ID of a deploy key.

Returns:



350
351
352
# File 'lib/gitlab/client/projects.rb', line 350

def deploy_key(project, id)
  get("/projects/#{project}/keys/#{id}")
end

#deploy_keys(project, options = {}) ⇒ Array<Gitlab::ObjectifiedHash>

Gets a project deploy keys.

Examples:

Gitlab.deploy_keys(42)

Parameters:

  • project (Integer)

    The ID of a project.

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

    A customizable set of options.

Options Hash (options):

  • :page (Integer)

    The page number.

  • :per_page (Integer)

    The number of results per page.

Returns:



338
339
340
# File 'lib/gitlab/client/projects.rb', line 338

def deploy_keys(project, options={})
  get("/projects/#{project}/keys", query: options)
end

#edit_git_hook(id, options = {}) ⇒ Gitlab::ObjectifiedHash

Examples:

Gitlab.edit_git_hook(42, { deny_delete_tag: false, commit_message_regex: '\\b[A-Z]{3}-[0-9]+\\b' })

Parameters:

  • id (Integer)

    The ID of a project.

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

    A customizable set of options.

  • option (Boolean)

    :deny_delete_tag Do not allow users to remove git tags with git push (0 = false, 1 = true)

  • option (String)

    :commit_message_regex Commit message regex

Returns:



288
289
290
# File 'lib/gitlab/client/projects.rb', line 288

def edit_git_hook(id, options={})
  put("/projects/#{id}/git_hook", body: options)
end

#edit_project(id, options = {}) ⇒ Gitlab::ObjectifiedHash

Updates an existing project.

Examples:

Gitlab.edit_project(42)
Gitlab.edit_project(42, { name: 'project_name' })

Parameters:

  • project (Integer)

    The ID of a project.

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

    A customizable set of options.

Options Hash (options):

  • :name (String)

    The name of a project

  • :path (String)

    The name of a project

  • :description (String)

    The name of a project

Returns:



405
406
407
# File 'lib/gitlab/client/projects.rb', line 405

def edit_project(id, options={})
  put("/projects/#{id}", query: options)
end

#edit_project_hook(project, id, url, options = {}) ⇒ Gitlab::ObjectifiedHash

Updates a project hook URL.

Examples:

Gitlab.edit_project_hook(42, 1, 'https://api.example.net/v1/webhooks/ci')

Parameters:

  • project (Integer, String)

    The ID or name of a project.

  • id (Integer)

    The ID of the hook.

  • url (String)

    The hook URL.

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

    A customizable set of options.

  • option (Boolean)

    :push_events Trigger hook on push events (0 = false, 1 = true)

  • option (Boolean)

    :issues_events Trigger hook on issues events (0 = false, 1 = true)

  • option (Boolean)

    :merge_requests_events Trigger hook on merge_requests events (0 = false, 1 = true)

  • option (Boolean)

    :tag_push_events Trigger hook on push_tag events (0 = false, 1 = true)

Returns:



233
234
235
236
# File 'lib/gitlab/client/projects.rb', line 233

def edit_project_hook(project, id, url, options={})
  body = { url: url }.merge(options)
  put("/projects/#{project}/hooks/#{id}", body: body)
end

#edit_team_member(project, id, access_level) ⇒ Array<Gitlab::ObjectifiedHash>

Updates a team member's project access level.

Examples:

Gitlab.edit_team_member('gitlab', 3, 20)

Parameters:

  • project (Integer, String)

    The ID or name of a project.

  • id (Integer)

    The ID of a user.

  • access_level (Integer)

    The access level to project.

  • options (Hash)

    A customizable set of options.

Returns:



156
157
158
# File 'lib/gitlab/client/projects.rb', line 156

def edit_team_member(project, id, access_level)
  put("/projects/#{project}/members/#{id}", body: { access_level: access_level })
end

#git_hook(id) ⇒ Gitlab::ObjectifiedHash

Examples:

Gitlab.git_hook(42)

Parameters:

  • id (Integer)

    The ID of a project.

Returns:



258
259
260
# File 'lib/gitlab/client/projects.rb', line 258

def git_hook(id)
  get("/projects/#{id}/git_hook")
end

#make_forked_from(project, id) ⇒ Gitlab::ObjectifiedHash

Mark this project as forked from the other

Examples:

Gitlab.make_forked(42, 24)

Parameters:

  • project (Integer, String)

    The ID or name of a project.

  • id (Integer)

    The ID of the project it is forked from.

Returns:



312
313
314
# File 'lib/gitlab/client/projects.rb', line 312

def make_forked_from(project, id)
  post("/projects/#{project}/fork/#{id}")
end

#project(id) ⇒ Gitlab::ObjectifiedHash

Gets information about a project.

Examples:

Gitlab.project(3)
Gitlab.project('gitlab')

Parameters:

  • id (Integer, String)

    The ID or name of a project.

Returns:



49
50
51
# File 'lib/gitlab/client/projects.rb', line 49

def project(id)
  get("/projects/#{id}")
end

#project_events(project, options = {}) ⇒ Array<Gitlab::ObjectifiedHash>

Gets a list of project events.

Examples:

Gitlab.project_events(42)
Gitlab.project_events('gitlab')

Parameters:

  • project (Integer, String)

    The ID or name of a project.

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

    A customizable set of options.

Options Hash (options):

  • :page (Integer)

    The page number.

  • :per_page (Integer)

    The number of results per page.

Returns:



64
65
66
# File 'lib/gitlab/client/projects.rb', line 64

def project_events(project, options={})
  get("/projects/#{project}/events", query: options)
end

#project_hook(project, id) ⇒ Gitlab::ObjectifiedHash

Gets a project hook.

Examples:

Gitlab.project_hook(42, 5)
Gitlab.project_hook('gitlab', 5)

Parameters:

  • project (Integer, String)

    The ID or name of a project.

  • id (Integer)

    The ID of a hook.

Returns:



197
198
199
# File 'lib/gitlab/client/projects.rb', line 197

def project_hook(project, id)
  get("/projects/#{project}/hooks/#{id}")
end

#project_hooks(project, options = {}) ⇒ Array<Gitlab::ObjectifiedHash>

Gets a list of project hooks.

Examples:

Gitlab.project_hooks(42)
Gitlab.project_hooks('gitlab')

Parameters:

  • project (Integer, String)

    The ID or name of a project.

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

    A customizable set of options.

Options Hash (options):

  • :page (Integer)

    The page number.

  • :per_page (Integer)

    The number of results per page.

Returns:



184
185
186
# File 'lib/gitlab/client/projects.rb', line 184

def project_hooks(project, options={})
  get("/projects/#{project}/hooks", query: options)
end

#project_search(query, options = {}) ⇒ Array<Gitlab::ObjectifiedHash> Also known as: search_projects

Search for projects by name.

Examples:

Gitlab.project_search('gitlab')
Gitlab.project_search('gitlab', { order_by: 'last_activity_at' })
Gitlab.search_projects('gitlab', { order_by: 'name', sort: 'asc' })

Parameters:

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

    A customizable set of options.

Options Hash (options):

  • :per_page (String)

    Number of projects to return per page

  • :page (String)

    The page to retrieve

  • :order_by (String)

    Return requests ordered by id, name, created_at or last_activity_at fields

  • :sort (String)

    Return requests sorted in asc or desc order

Returns:



36
37
38
# File 'lib/gitlab/client/projects.rb', line 36

def project_search(query, options={})
  get("/projects/search/#{query}", query: options)
end

#projects(options = {}) ⇒ Array<Gitlab::ObjectifiedHash>

Gets a list of projects owned by the authenticated user.

Examples:

Gitlab.projects

Parameters:

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

    A customizable set of options.

Options Hash (options):

  • :page (Integer)

    The page number.

  • :per_page (Integer)

    The number of results per page.

  • :scope (String)

    Scope of projects. 'owned' for list of projects owned by the authenticated user, 'all' to get all projects (admin only)

Returns:



15
16
17
18
19
20
21
# File 'lib/gitlab/client/projects.rb', line 15

def projects(options={})
  if options[:scope]
    get("/projects/#{options[:scope]}", query: options)
  else
    get("/projects", query: options)
  end
end

#remove_forked(project) ⇒ Gitlab::ObjectifiedHash

Remove a forked_from relationship for a project.

Examples:

Gitlab.remove_forked(42)

Parameters:

  • project (Integer, String)

    The ID or name of a project.

  • project (Integer)

    The ID of the project it is forked from

Returns:



324
325
326
# File 'lib/gitlab/client/projects.rb', line 324

def remove_forked(project)
  delete("/projects/#{project}/fork")
end

#remove_team_member(project, id) ⇒ Gitlab::ObjectifiedHash

Removes a user from project team.

Examples:

Gitlab.remove_team_member('gitlab', 2)

Parameters:

  • project (Integer, String)

    The ID or name of a project.

  • id (Integer)

    The ID of a user.

  • options (Hash)

    A customizable set of options.

Returns:



169
170
171
# File 'lib/gitlab/client/projects.rb', line 169

def remove_team_member(project, id)
  delete("/projects/#{project}/members/#{id}")
end

#team_member(project, id) ⇒ Gitlab::ObjectifiedHash

Gets a project team member.

Examples:

Gitlab.team_member('gitlab', 2)

Parameters:

  • project (Integer, String)

    The ID or name of a project.

  • id (Integer)

    The ID of a project team member.

Returns:



128
129
130
# File 'lib/gitlab/client/projects.rb', line 128

def team_member(project, id)
  get("/projects/#{project}/members/#{id}")
end

#team_members(project, options = {}) ⇒ Array<Gitlab::ObjectifiedHash>

Gets a list of project team members.

Examples:

Gitlab.team_members(42)
Gitlab.team_members('gitlab')

Parameters:

  • project (Integer, String)

    The ID or name of a project.

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

    A customizable set of options.

Options Hash (options):

  • :query (String)

    The search query.

  • :page (Integer)

    The page number.

  • :per_page (Integer)

    The number of results per page.

Returns:



116
117
118
# File 'lib/gitlab/client/projects.rb', line 116

def team_members(project, options={})
  get("/projects/#{project}/members", query: options)
end