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')


205
206
207
208
# File 'lib/gitlab/client/projects.rb', line 205

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' })

See Also:



264
265
266
# File 'lib/gitlab/client/projects.rb', line 264

def add_push_rule(id, options = {})
  post("/projects/#{url_encode id}/push_rule", body: options)
end

#add_team_member(project, id, access_level, options = {}) ⇒ Gitlab::ObjectifiedHash

Adds a user to project team.

Examples:

Gitlab.add_team_member('gitlab', 2, 40)
Gitlab.add_team_member('gitlab', 2, 40, { expires_at: "2018-12-31"})

Options Hash (options):

  • :expires_at (String)

    A date string in the format YEAR-MONTH-DAY.



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

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

#archive_project(id) ⇒ Gitlab::ObjectifiedHash

Archives a project.

Examples:

Gitlab.archive_project(4)


580
581
582
# File 'lib/gitlab/client/projects.rb', line 580

def archive_project(id)
  post("/projects/#{url_encode id}/archive")
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)


355
356
357
# File 'lib/gitlab/client/projects.rb', line 355

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' })

Options Hash (options):

  • :sudo (String)

    The username the project will be forked for



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

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 })

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).

  • :visibility (String)

    The setting for making a project public (‘private’, ‘internal’, ‘public’).

  • :user_id (Integer)

    The user/owner id of a project.



73
74
75
76
# File 'lib/gitlab/client/projects.rb', line 73

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)


391
392
393
# File 'lib/gitlab/client/projects.rb', line 391

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)


85
86
87
# File 'lib/gitlab/client/projects.rb', line 85

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)


237
238
239
# File 'lib/gitlab/client/projects.rb', line 237

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.



291
292
293
# File 'lib/gitlab/client/projects.rb', line 291

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)


341
342
343
# File 'lib/gitlab/client/projects.rb', line 341

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)

Options Hash (options):

  • :page (Integer)

    The page number.

  • :per_page (Integer)

    The number of results per page.



329
330
331
# File 'lib/gitlab/client/projects.rb', line 329

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)


379
380
381
# File 'lib/gitlab/client/projects.rb', line 379

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' })

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



442
443
444
# File 'lib/gitlab/client/projects.rb', line 442

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')


224
225
226
227
# File 'lib/gitlab/client/projects.rb', line 224

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' })

See Also:



279
280
281
# File 'lib/gitlab/client/projects.rb', line 279

def edit_push_rule(id, options = {})
  put("/projects/#{url_encode id}/push_rule", body: options)
end

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

Updates a team member’s project access level.

Examples:

Gitlab.edit_team_member('gitlab', 3, 20)
Gitlab.edit_team_member('gitlab', 3, 20, { expires_at: "2018-12-31"})

Options Hash (options):

  • :expires_at (String)

    A date string in the format YEAR-MONTH-DAY.



146
147
148
149
# File 'lib/gitlab/client/projects.rb', line 146

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

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

Enables a deploy key at the project.

Examples:

Gitlab.enable_deploy_key(42, 66)


367
368
369
# File 'lib/gitlab/client/projects.rb', line 367

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)


303
304
305
# File 'lib/gitlab/client/projects.rb', line 303

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')


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

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)

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



423
424
425
# File 'lib/gitlab/client/projects.rb', line 423

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)


188
189
190
# File 'lib/gitlab/client/projects.rb', line 188

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')

Options Hash (options):

  • :page (Integer)

    The page number.

  • :per_page (Integer)

    The number of results per page.



175
176
177
# File 'lib/gitlab/client/projects.rb', line 175

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' })

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



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

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

#project_template(project, type, key, options = {}) ⇒ Gitlab::ObjectifiedHash

Get one project template of a particular type

Examples:

Gitlab.project_template(1, 'dockerfiles', 'dockey')
Gitlab.project_template(1, 'licenses', 'gpl', { project: 'some project', fullname: 'Holder Holding' })

Options Hash (options):

  • project(optional) (String)

    The project name to use when expanding placeholders in the template. Only affects licenses

  • fullname(optional) (String)

    The full name of the copyright holder to use when expanding placeholders in the template. Only affects licenses

See Also:



569
570
571
# File 'lib/gitlab/client/projects.rb', line 569

def project_template(project, type, key, options = {})
  get("/projects/#{url_encode project}/templates/#{type}/#{key}", query: options)
end

#project_templates(project, type) ⇒ Array<Gitlab::ObjectifiedHash>

Get all project templates of a particular type

Examples:

Gitlab.project_templates(1, 'dockerfiles')
Gitlab.project_templates(1, 'licenses')

See Also:



551
552
553
# File 'lib/gitlab/client/projects.rb', line 551

def project_templates(project, type)
  get("/projects/#{url_encode project}/templates/#{type}")
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

Options Hash (options):

  • :page (Integer)

    The page number.

  • :per_page (Integer)

    The number of results per page.



18
19
20
# File 'lib/gitlab/client/projects.rb', line 18

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

#push_rule(id) ⇒ Gitlab::ObjectifiedHash

Gets a project push rule.



249
250
251
# File 'lib/gitlab/client/projects.rb', line 249

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)


315
316
317
# File 'lib/gitlab/client/projects.rb', line 315

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)


160
161
162
# File 'lib/gitlab/client/projects.rb', line 160

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)


454
455
456
# File 'lib/gitlab/client/projects.rb', line 454

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')

See Also:



491
492
493
# File 'lib/gitlab/client/projects.rb', line 491

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)


113
114
115
# File 'lib/gitlab/client/projects.rb', line 113

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')

Options Hash (options):

  • :query (String)

    The search query.

  • :page (Integer)

    The page number.

  • :per_page (Integer)

    The number of results per page.



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

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

#transfer_project(project, namespace) ⇒ Gitlab::ObjectifiedHash

Transfer a project to a new namespace.

Examples:

Gitlab.transfer_project(42, 'yolo')


478
479
480
# File 'lib/gitlab/client/projects.rb', line 478

def transfer_project(project, namespace)
  put("/projects/#{url_encode project}/transfer", body: { namespace: namespace })
end

#unarchive_project(id) ⇒ Gitlab::ObjectifiedHash

Unarchives a project.

Examples:

Gitlab.unarchive_project(4)


591
592
593
# File 'lib/gitlab/client/projects.rb', line 591

def unarchive_project(id)
  post("/projects/#{url_encode id}/unarchive")
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)


466
467
468
# File 'lib/gitlab/client/projects.rb', line 466

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')

See Also:



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

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

#upload_file(id, file_fullpath) ⇒ Gitlab::ObjectifiedHash

Uploads a file to the specified project to be used in an issue or merge request description, or a comment.

Examples:

Gitlab.upload_file(1, '/full/path/to/avatar.jpg')

See Also:



537
538
539
# File 'lib/gitlab/client/projects.rb', line 537

def upload_file(id, file_fullpath)
  post("/projects/#{url_encode id}/uploads", body: { file: File.open(file_fullpath, 'r') })
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' })

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.

See Also:



523
524
525
# File 'lib/gitlab/client/projects.rb', line 523

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