Module: Gitlab::CI::Client::Projects

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

Overview

Defines methods related to projects.

Instance Method Summary collapse

Instance Method Details

#create_project(name, id, ref = 'master') ⇒ Gitlab::ObjectifiedHash

Creates a GitLab CI project using GitLab project details.

Examples:

Gitlab::CI.create_project('gitlab')
Gitlab::CI.create_project('viking', :description => 'Awesome project')
Gitlab::CI.create_project('Red', :wall_enabled => false)

Parameters:

  • name (String)

    (required) - The name of the project

  • gitlab_id (String)

    (required) - The ID of the project on the GitLab instance

  • default_ref (String)

    (optional) - The branch to run on (default to master)

Returns:

  • (Gitlab::ObjectifiedHash)

    Information about created project.



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

def create_project(name, id, ref='master')
  url = "/projects"
  post(url, body: { name: name, gitlab_id: id, default_ref: ref })
end

#delete_project(id) ⇒ Gitlab::ObjectifiedHash

Removes a GitLab CI project that the authenticated user has access to.

Examples:

Gitlab::CI.delete_project(4)

Parameters:

  • id (Integer, String)

    (required) - The ID of the GitLab CI project

Returns:

  • (Gitlab::ObjectifiedHash)

    Information about deleted project.



70
71
72
# File 'lib/gitlab/ci/client/projects.rb', line 70

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

#edit_project(id, name, ref = 'master') ⇒ Gitlab::ObjectifiedHash

Updates a GitLab CI project using GitLab project details that the authenticated user has access to.

Examples:

Gitlab::CI.edit_project(4, "name", "branch")

Parameters:

  • name (String)
    • The name of the project

  • default_ref (String)
    • The branch to run on (default to master)

Returns:

  • (Gitlab::ObjectifiedHash)

    Information about deleted project.



59
60
61
# File 'lib/gitlab/ci/client/projects.rb', line 59

def edit_project(id, name, ref='master')
  put("/projects/#{id}", body: { name: name, gitlab_id: id, default_ref: ref })
end

Links a runner to a project so that it can make builds (only via authorized user).

Examples:

Gitlab::CI.link_project_to_runner(4,5)

Parameters:

  • id (Integer, String)

    (required) - The ID of the GitLab CI project

  • runner_id (Integer, String)

    (required) - The ID of the GitLab CI runner

Returns:

  • (Gitlab::ObjectifiedHash)

    Information about deleted project.



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

def link_project_to_runner(id,runner)
  post("/projects/#{id}/runners/#{runner}", body: { id: id, runner_id: runner })
end

#project(id) ⇒ Gitlab::ObjectifiedHash

Returns information about a single project for which the user is authorized.

Examples:

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

Parameters:

  • id (Integer, String)

    The ID of the GitLab CI project

Returns:

  • (Gitlab::ObjectifiedHash)


31
32
33
# File 'lib/gitlab/ci/client/projects.rb', line 31

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

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

Lists all projects that the authenticated user has access to.

Examples:

Gitlab::CI.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:

  • (Array<Gitlab::ObjectifiedHash>)


15
16
17
18
19
20
21
# File 'lib/gitlab/ci/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_project_from_runner(id, runner) ⇒ Gitlab::ObjectifiedHash

Removes a runner from a project so that it can not make builds (only via authorized user).

Examples:

Gitlab::CI.remove_project_from_runner(4,5)

Parameters:

  • id (Integer, String)

    (required) - The ID of the GitLab CI project

  • runner_id (Integer, String)

    (required) - The ID of the GitLab CI runner

Returns:

  • (Gitlab::ObjectifiedHash)

    Information about deleted project.



94
95
96
# File 'lib/gitlab/ci/client/projects.rb', line 94

def remove_project_from_runner(id,runner)
  delete("/projects/#{id}/runners/#{runner}")
end