Module: Gitlab::Client::RepositoryFiles

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

Overview

Defines methods related to repository files.

Instance Method Summary collapse

Instance Method Details

#create_file(project, path, branch, content, commit_message) ⇒ Gitlab::ObjectifiedHash

Creates a new repository file.

Examples:

Gitlab.create_file(42, "path", "branch", "content", "commit message")

Parameters:

  • project (Integer)

    The ID of a project.

  • full (String)

    path to new file.

  • the (String)

    name of the branch.

  • file (String)

    content.

  • commit (String)

    message.

Returns:



34
35
36
37
38
39
40
# File 'lib/gitlab/client/repository_files.rb', line 34

def create_file(project, path, branch, content, commit_message)
  post("/projects/#{project}/repository/files", body: {
    file_path: path,
    branch_name: branch,
    commit_message: commit_message
  }.merge(encoded_content_attributes(content)))
end

#edit_file(project, path, branch, content, commit_message) ⇒ Gitlab::ObjectifiedHash

Edits an existing repository file.

Examples:

Gitlab.edit_file(42, "path", "branch", "content", "commit message")

Parameters:

  • project (Integer)

    The ID of a project.

  • full (String)

    path to new file.

  • the (String)

    name of the branch.

  • file (String)

    content.

  • commit (String)

    message.

Returns:



53
54
55
56
57
58
59
# File 'lib/gitlab/client/repository_files.rb', line 53

def edit_file(project, path, branch, content, commit_message)
  put("/projects/#{project}/repository/files", body: {
    file_path: path,
    branch_name: branch,
    commit_message: commit_message
  }.merge(encoded_content_attributes(content)))
end

#get_file(project, file_path, ref) ⇒ Gitlab::ObjectifiedHash

Gets a repository file.

Examples:

Gitlab.get_file(42, "README.md", "master")

Parameters:

  • project (Integer)

    The ID of a project.

  • file_path (String)

    The full path of the file.

  • ref (String)

    The name of branch, tag or commit.

Returns:



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

def get_file(project, file_path, ref)
  get("/projects/#{project}/repository/files", query: {
        file_path: file_path,
        ref: ref
      })
end

#remove_file(project, path, branch, commit_message) ⇒ Gitlab::ObjectifiedHash

Removes an existing repository file.

Examples:

Gitlab.remove_file(42, "path", "branch", "commit message")

Parameters:

  • project (Integer)

    The ID of a project.

  • full (String)

    path to new file.

  • the (String)

    name of the branch.

  • commit (String)

    message.

Returns:



71
72
73
74
75
76
77
# File 'lib/gitlab/client/repository_files.rb', line 71

def remove_file(project, path, branch, commit_message)
  delete("/projects/#{project}/repository/files", body: {
           file_path: path,
           branch_name: branch,
           commit_message: commit_message
         })
end