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_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 path 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:


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

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

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

Adds a project push rule.

Examples:

Gitlab.add_push_rule(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:

See Also:


256
257
258
# File 'lib/gitlab/client/projects.rb', line 256

def add_push_rule(id, options={})
  post("/projects/#{url_encode id}/push_rule", body: options)
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 path 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:


125
126
127
# File 'lib/gitlab/client/projects.rb', line 125

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

#create_deploy_key(project, title, key, options = {}) ⇒ Gitlab::ObjectifiedHash

Creates a new deploy key.

Examples:

Gitlab.create_deploy_key(42, 'My Key', 'Key contents', can_push: true)

Parameters:

  • project (Integer, String)

    The ID or path of a project.

  • title (String)

    The title of a deploy key.

  • key (String)

    The content of a deploy key.

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

    A customizable set of options.

Returns:


347
348
349
# File 'lib/gitlab/client/projects.rb', line 347

def create_deploy_key(project, title, key, options = {})
  post("/projects/#{url_encode project}/deploy_keys", body: { title: title, key: key }.merge(options))
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, String)

    The ID or path 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:


397
398
399
# File 'lib/gitlab/client/projects.rb', line 397

def create_fork(id, options={})
  post("/projects/#{url_encode id}/fork", 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.

  • :path (String)

    Repository name for new project. (Default is lowercase name with dashes)

  • :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:


71
72
73
74
# File 'lib/gitlab/client/projects.rb', line 71

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, String)

    The ID or path of a project.

  • id (Integer)

    The ID of a deploy key.

Returns:


383
384
385
# File 'lib/gitlab/client/projects.rb', line 383

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

#delete_project(id) ⇒ Gitlab::ObjectifiedHash

Deletes a project.

Examples:

Gitlab.delete_project(4)

Parameters:

  • id (Integer, String)

    The ID or path of a project.

Returns:


83
84
85
# File 'lib/gitlab/client/projects.rb', line 83

def delete_project(id)
  delete("/projects/#{url_encode 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 path of a project.

  • id (String)

    The ID of the hook.

Returns:


229
230
231
# File 'lib/gitlab/client/projects.rb', line 229

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

#delete_push_rule(id) ⇒ Gitlab::ObjectifiedHash

Deletes a push rule from a project.

Examples:

Gitlab.delete_push_rule(42)

Parameters:

  • id (Integer)

    The ID of a project.

Returns:

See Also:


283
284
285
# File 'lib/gitlab/client/projects.rb', line 283

def delete_push_rule(id)
  delete("/projects/#{url_encode id}/push_rule")
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 or path of a project.

  • id (Integer)

    The ID of a deploy key.

Returns:


333
334
335
# File 'lib/gitlab/client/projects.rb', line 333

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

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

Gets a project deploy keys.

Examples:

Gitlab.deploy_keys(42)

Parameters:

  • project (Integer, String)

    The ID or path 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:


321
322
323
# File 'lib/gitlab/client/projects.rb', line 321

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

#disable_deploy_key(project, key) ⇒ Gitlab::ObjectifiedHash

Disables a deploy key at the project.

Examples:

Gitlab.disable_deploy_key(42, 66)

Parameters:

  • project (Integer, String)

    The ID or path of a project.

  • key (Integer)

    The ID of a deploy key.

Returns:


371
372
373
# File 'lib/gitlab/client/projects.rb', line 371

def disable_deploy_key(project, key)
  post("/projects/#{url_encode project}/deploy_keys/#{key}/disable", body: { id: project, key_id: key })
end

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

Updates an existing project.

(Any provided options will be passed to Gitlab. See Gitlab docs for all valid options)

Examples:

Gitlab.edit_project(42)
Gitlab.edit_project(42, { name: 'Project Name' })
Gitlab.edit_project('project-name', { name: 'New Project Name', path: 'new-project-patth' })

Parameters:

  • project (Integer, String)

    The ID or path 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 project's repository name, also used in Gitlab's URLs

  • :description (String)

    The description to show in Gitlab

Returns:


434
435
436
# File 'lib/gitlab/client/projects.rb', line 434

def edit_project(id, options={})
  put("/projects/#{url_encode id}", body: 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 path 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:


216
217
218
219
# File 'lib/gitlab/client/projects.rb', line 216

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

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

Updates a project push rule.

Examples:

Gitlab.edit_push_rule(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:

See Also:


271
272
273
# File 'lib/gitlab/client/projects.rb', line 271

def edit_push_rule(id, options={})
  put("/projects/#{url_encode id}/push_rule", body: options)
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 path 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:


139
140
141
# File 'lib/gitlab/client/projects.rb', line 139

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

#enable_deploy_key(project, key) ⇒ Gitlab::ObjectifiedHash

Enables a deploy key at the project.

Examples:

Gitlab.enable_deploy_key(42, 66)

Parameters:

  • project (Integer, String)

    The ID or path of a project.

  • key (Integer)

    The ID of a deploy key.

Returns:


359
360
361
# File 'lib/gitlab/client/projects.rb', line 359

def enable_deploy_key(project, key)
  post("/projects/#{url_encode project}/deploy_keys/#{key}/enable", body: { id: project, key_id: key })
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 path of a project.

  • id (Integer)

    The ID of the project it is forked from.

Returns:


295
296
297
# File 'lib/gitlab/client/projects.rb', line 295

def make_forked_from(project, id)
  post("/projects/#{url_encode 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 path of a project.

Returns:


46
47
48
# File 'lib/gitlab/client/projects.rb', line 46

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

#project_forks(id, options = {}) ⇒ Array<Gitlab::ObjectifiedHash>

Get a list of all visible projects across GitLab for the authenticated user. When accessed without authentication, only public projects are returned.

Note: This feature was introduced in GitLab 10.1

Examples:

Gitlab.project_forks(42)

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.

  • :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:


415
416
417
# File 'lib/gitlab/client/projects.rb', line 415

def project_forks(id, options={})
  get("/projects/#{url_encode id}/forks", 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 path of a project.

  • id (Integer)

    The ID of a hook.

Returns:


180
181
182
# File 'lib/gitlab/client/projects.rb', line 180

def project_hook(project, id)
  get("/projects/#{url_encode 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 path 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:


167
168
169
# File 'lib/gitlab/client/projects.rb', line 167

def project_hooks(project, options={})
  get("/projects/#{url_encode 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:


33
34
35
# File 'lib/gitlab/client/projects.rb', line 33

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

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

Gets a list of projects owned by the authenticated user.

(Any provided options will be passed to Gitlab. See Gitlab docs for all valid options)

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.

Returns:


16
17
18
# File 'lib/gitlab/client/projects.rb', line 16

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

#push_rule(id) ⇒ Gitlab::ObjectifiedHash

Gets a project push rule.

Examples:

Gitlab.push_rule(42)

Parameters:

  • id (Integer)

    The ID of a project.

Returns:

See Also:


241
242
243
# File 'lib/gitlab/client/projects.rb', line 241

def push_rule(id)
  get("/projects/#{url_encode id}/push_rule")
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 path of a project.

  • project (Integer)

    The ID of the project it is forked from

Returns:


307
308
309
# File 'lib/gitlab/client/projects.rb', line 307

def remove_forked(project)
  delete("/projects/#{url_encode 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 path of a project.

  • id (Integer)

    The ID of a user.

  • options (Hash)

    A customizable set of options.

Returns:


152
153
154
# File 'lib/gitlab/client/projects.rb', line 152

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

#share_project_with_group(project, id, group_access) ⇒ Object

Share project with group.

Examples:

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

Parameters:

  • project (Integer, String)

    The ID or path of a project.

  • id (Integer)

    The ID of a group.

  • group_access (Integer)

    The access level to project.


446
447
448
# File 'lib/gitlab/client/projects.rb', line 446

def share_project_with_group(project, id, group_access)
  post("/projects/#{url_encode project}/share", body: { group_id: id, group_access: group_access })
end

#star_project(id) ⇒ Gitlab::ObjectifiedHash

Stars a project.

Examples:

Gitlab.star_project(42)
Gitlab.star_project('gitlab-org/gitlab-ce')

Parameters:

  • id (Integer, String)

    The ID or path of a project.

Returns:

See Also:


471
472
473
# File 'lib/gitlab/client/projects.rb', line 471

def star_project(id)
  post("/projects/#{url_encode id}/star")
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 path of a project.

  • id (Integer)

    The ID of a project team member.

Returns:


111
112
113
# File 'lib/gitlab/client/projects.rb', line 111

def team_member(project, id)
  get("/projects/#{url_encode 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 path 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:


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

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

#unshare_project_with_group(project, id) ⇒ void

This method returns an undefined value.

Unshare project with group.

Examples:

Gitlab.unshare_project_with_group('gitlab', 2)

Parameters:

  • project (Integer, String)

    The ID or path of a project.

  • id (Integer)

    The ID of a group.


458
459
460
# File 'lib/gitlab/client/projects.rb', line 458

def unshare_project_with_group(project, id)
  delete("/projects/#{url_encode project}/share/#{id}")
end

#unstar_project(id) ⇒ Gitlab::ObjectifiedHash

Unstars a project.

Examples:

Gitlab.unstar_project(42)
Gitlab.unstar_project('gitlab-org/gitlab-ce')

Parameters:

  • id (Integer, String)

    The ID or path of a project.

Returns:

See Also:


484
485
486
# File 'lib/gitlab/client/projects.rb', line 484

def unstar_project(id)
  delete("/projects/#{url_encode id}/star")
end

#user_projects(user_id, options = {}) ⇒ Array<Gitlab::ObjectifiedHash>

Get a list of visible projects for the given user.

Examples:

Gitlab.user_projects(1)
Gitlab.user_projects(1, { order_by: 'last_activity_at' })
Gitlab.user_projects('username', { order_by: 'name', sort: 'asc' })

Parameters:

  • user_id (Integer, String)

    The ID or username of the user.

  • 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 projects ordered by id, name, path, created_at, updated_at, or last_activity_at fields.

  • :sort (String)

    Return projects sorted in asc or desc order.

Returns:

See Also:


503
504
505
# File 'lib/gitlab/client/projects.rb', line 503

def user_projects(user_id, options={})
  get("/users/#{url_encode user_id}/projects", query: options)
end