module Gitlab::Client::RepositoryFiles

Defines methods related to repository files. @see docs.gitlab.com/ce/api/repository_files.html

Public Instance Methods

create_file(project, path, branch, content, commit_message) click to toggle source

Creates a new repository file.

@example

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

@param [Integer] project The ID of a project. @param [String] full path to new file. @param [String] the name of the branch. @param [String] file content. @param [String] commit message. @return [Gitlab::ObjectifiedHash]

# 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) click to toggle source

Edits an existing repository file.

@example

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

@param [Integer] project The ID of a project. @param [String] full path to new file. @param [String] the name of the branch. @param [String] file content. @param [String] commit message. @return [Gitlab::ObjectifiedHash]

# 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) click to toggle source

Gets a repository file.

@example

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

@param [Integer] project The ID of a project. @param [String] file_path The full path of the file. @param [String] ref The name of branch, tag or commit. @return [Gitlab::ObjectifiedHash]

# 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) click to toggle source

Removes an existing repository file.

@example

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

@param [Integer] project The ID of a project. @param [String] full path to new file. @param [String] the name of the branch. @param [String] commit message. @return [Gitlab::ObjectifiedHash]

# 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

Private Instance Methods

encoded_content_attributes(content) click to toggle source
# File lib/gitlab/client/repository_files.rb, line 81
def encoded_content_attributes(content)
  {
    encoding: 'base64',
    content: Base64.encode64(content)
  }
end