Class: SupportOps::GitLab::RepositoryFiles

Inherits:
Base
  • Object
show all
Defined in:
lib/support_ops_gitlab/gitlab/repository_files.rb

Overview

TODO:

Document attribute meaning

Defines the class RepositoryFiles within the module SupportOps::GitLab.

Author:

  • Jason Colyer

Since:

  • 1.0.0

Instance Attribute Summary collapse

Class Method Summary collapse

Methods inherited from Base

#activate!, #approve!, attributes, #badges, #ban!, #block!, client, #client=, #commits, configure, #contributors, #create_support_pin!, #deactivate!, define_attributes, #delete!, #diffs, #disable_2fa!, #discussions, #emails, #encoded_path, #events, #find, #find!, #gpg_keys, #hard_delete!, #impersonations, #initialize, #issues, #jobs, #latest_pipeline, #members, #memberships, #merge_requests, #move!, #notes, #paid?, #pats, #pipeline_variables, #pipelines, #preferences, #projects, readonly_attributes, #reject!, #revoke!, #rotate!, #save!, #ssh_keys, #status, #store_original_attributes, #subscribe!, #support_pin, to_hash, #tokens, #unban!, #unblock!, #unsubscribe!, #webhooks

Constructor Details

This class inherits a constructor from SupportOps::GitLab::Base

Instance Attribute Details

#blob_idString

Returns the current value of blob_id.

Returns:

  • (String)

    the current value of blob_id



25
26
27
# File 'lib/support_ops_gitlab/gitlab/repository_files.rb', line 25

def blob_id
  @blob_id
end

#commit_idString

Returns the current value of commit_id.

Returns:

  • (String)

    the current value of commit_id



25
26
27
# File 'lib/support_ops_gitlab/gitlab/repository_files.rb', line 25

def commit_id
  @commit_id
end

#contentString

Returns the current value of content.

Returns:

  • (String)

    the current value of content



25
26
27
# File 'lib/support_ops_gitlab/gitlab/repository_files.rb', line 25

def content
  @content
end

#content_sha256String

Returns the current value of content_sha256.

Returns:

  • (String)

    the current value of content_sha256



25
26
27
# File 'lib/support_ops_gitlab/gitlab/repository_files.rb', line 25

def content_sha256
  @content_sha256
end

#encodingString

Returns the current value of encoding.

Returns:

  • (String)

    the current value of encoding



25
26
27
# File 'lib/support_ops_gitlab/gitlab/repository_files.rb', line 25

def encoding
  @encoding
end

#execute_filemodeBoolean

Returns the current value of execute_filemode.

Returns:

  • (Boolean)

    the current value of execute_filemode



25
26
27
# File 'lib/support_ops_gitlab/gitlab/repository_files.rb', line 25

def execute_filemode
  @execute_filemode
end

#file_nameString

Returns the current value of file_name.

Returns:

  • (String)

    the current value of file_name



25
26
27
# File 'lib/support_ops_gitlab/gitlab/repository_files.rb', line 25

def file_name
  @file_name
end

#file_pathString

Returns the current value of file_path.

Returns:

  • (String)

    the current value of file_path



25
26
27
# File 'lib/support_ops_gitlab/gitlab/repository_files.rb', line 25

def file_path
  @file_path
end

#last_commit_idString

Returns the current value of last_commit_id.

Returns:

  • (String)

    the current value of last_commit_id



25
26
27
# File 'lib/support_ops_gitlab/gitlab/repository_files.rb', line 25

def last_commit_id
  @last_commit_id
end

#refString

Returns the current value of ref.

Returns:

  • (String)

    the current value of ref



25
26
27
# File 'lib/support_ops_gitlab/gitlab/repository_files.rb', line 25

def ref
  @ref
end

#sizeInteger

Returns the current value of size.

Returns:

  • (Integer)

    the current value of size



25
26
27
# File 'lib/support_ops_gitlab/gitlab/repository_files.rb', line 25

def size
  @size
end

Class Method Details

.get(project_id, path, ref = 'HEAD') ⇒ Object

Get file from repository

Examples:

require 'support_ops_gitlab'

SupportOps::GitLab::Configuration.configure do |config|
  config.url = 'https://gitlab.com/api/v4'
  config.token = 'abc123'
end

file = SupportOps::GitLab::RepositoryFiles.get(123456, 'public/hw.txt')
pp file.file_path
# => "public/hw.txt"
pp file.content
# => "Hello World!"

Parameters:

  • project_id (Integer)

    The project ID to look in (can also use a URL encoded String)

  • path (String)

    The path to the file in the repository

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

    The ref to look in (defaults to HEAD, meaning the default branch)

Returns:

  • String

See Also:

Author:

  • Jason Colyer

Since:

  • 1.0.0



59
60
61
62
63
64
65
# File 'lib/support_ops_gitlab/gitlab/repository_files.rb', line 59

def self.get(project_id, path, ref = 'HEAD')
  response = client.connection.get("projects/#{project_id}/repository/files/#{ERB::Util.url_encode(path)}?ref=#{ref}")
  body = Oj.load(response.body)
  return nil unless response.status == 200

  RepositoryFiles.new(body)
end

.get_raw(project_id, path, ref = 'HEAD', lfs = false) ⇒ Object

Get raw file from repository

Examples:

require 'support_ops_gitlab'

SupportOps::GitLab::Configuration.configure do |config|
  config.url = 'https://gitlab.com/api/v4'
  config.token = 'abc123'
end

content = SupportOps::GitLab::RepositoryFiles.get_raw(123456, 'public/hw.txt')
pp content
# => "Hello World!"

Parameters:

  • project_id (Integer)

    The project ID to look in (can also use a URL encoded String)

  • path (String)

    The path to the file in the repository

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

    The ref to look in (defaults to HEAD, meaning the default branch)

  • lft (Boolean)

    Determines if the response should be Git LFS file contents, rather than the pointer (defaults to false)

Returns:

  • String

See Also:

Author:

  • Jason Colyer

Since:

  • 1.0.0



92
93
94
95
96
97
# File 'lib/support_ops_gitlab/gitlab/repository_files.rb', line 92

def self.get_raw(project_id, path, ref = 'HEAD', lfs = false)
  response = client.connection.get("projects/#{project_id}/repository/files/#{ERB::Util.url_encode(path)}/raw?ref=#{ref}")
  return nil unless response.status == 200

  response.body
end