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


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

def create_file(project, path, branch, content, commit_message)
  post("/projects/#{url_encode 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")


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

def edit_file(project, path, branch, content, commit_message)
  put("/projects/#{url_encode project}/repository/files", body: {
    file_path: path,
    branch_name: branch,
    commit_message: commit_message
  }.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')


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

def file_contents(project, filepath, ref='master')
  ref = URI.encode(ref, /\W/)
  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")


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

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) ⇒ Gitlab::ObjectifiedHash

Removes an existing repository file.

Examples:

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


90
91
92
93
94
95
96
# File 'lib/gitlab/client/repository_files.rb', line 90

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