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, options = {}) ⇒ Gitlab::ObjectifiedHash

Creates a new repository file.

Examples:

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

Parameters:

  • project (Integer, String)

    The ID or name of a project.

  • path (String)

    full path to new file.

  • branch (String)

    the name of the branch.

  • content (String)

    file content.

  • commit_message (String)

    …commit message.

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

    Optional additional details for commit

Options Hash (options):

  • :author_name (String)

    Commit author’s name

  • :author_email (String)

    Commit author’s email address

Returns:



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

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

#edit_file(project, path, branch, content, commit_message, options = {}) ⇒ Gitlab::ObjectifiedHash

Edits an existing repository file.

Examples:

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

Parameters:

  • project (Integer, String)

    The ID or name of a project.

  • path (String)

    full path of file to update.

  • branch (String)

    the name of the branch to commit changes to.

  • content (String)

    new file content.

  • commit_message (String)

    …commit message.

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

    Optional additional details for commit

Options Hash (options):

  • :author_name (String)

    Commit author’s name

  • :author_email (String)

    Commit author’s email address

Returns:



76
77
78
79
80
81
# File 'lib/gitlab/client/repository_files.rb', line 76

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

#file_contents(project, filepath, ref = 'master') ⇒ String Also known as: repo_file_contents

Get the contents of a file

Examples:

Gitlab.file_contents(42, 'Gemfile')
Gitlab.repo_file_contents(3, 'Gemfile', 'ed899a2f4b50b4370feeea94676502b42383c746')

Parameters:

  • project (Integer, String)

    The ID or name of a project.

  • filepath (String)

    The relative path of the file in the repository

  • ref (String) (defaults to: 'master')

    The name of a repository branch or tag or if not given the default branch.

Returns:

  • (String)


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

def file_contents(project, filepath, ref='master')
  get "/projects/#{url_encode project}/repository/files/#{url_encode filepath}/raw",
      query: { ref: ref},
      format: nil,
      headers: { Accept: 'text/plain' },
      parser: ::Gitlab::Request::Parser
end

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

Gets a repository file.

Examples:

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

Parameters:

  • project (Integer, String)

    The ID or name of a project.

  • file_path (String)

    The full path of the file.

  • ref (String)

    The name of branch, tag or commit.

Returns:



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

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

#remove_file(project, path, branch, commit_message, options = {}) ⇒ Gitlab::ObjectifiedHash

Removes an existing repository file.

Examples:

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

Parameters:

  • project (Integer, String)

    The ID or name of a project.

  • path (String)

    full path of file to delete.

  • branch (String)

    the name of the branch to commit the deletion to.

  • commit_message (String)

    …a commit message ;)

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

    Optional additional details for commit

Options Hash (options):

  • :author_name (String)

    Commit author’s name

  • :author_email (String)

    Commit author’s email address

Returns:



96
97
98
99
100
101
102
# File 'lib/gitlab/client/repository_files.rb', line 96

def remove_file(project, path, branch, commit_message, options = {})
  delete("/projects/#{url_encode project}/repository/files/#{url_encode path}",
         body: {
           branch: branch,
           commit_message: commit_message
         }.merge(options))
end