Class: GitlabQuality::TestTooling::GitlabClient::RepositoryFilesClient

Inherits:
GitlabClient
  • Object
show all
Defined in:
lib/gitlab_quality/test_tooling/gitlab_client/repository_files_client.rb

Constant Summary

Constants inherited from GitlabClient

GitlabClient::MAX_RETRY_ATTEMPTS, GitlabClient::RETRY_BACK_OFF_DELAY

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from GitlabClient

#handle_gitlab_client_exceptions, #ignore_gitlab_client_exceptions, #post_exception_to_slack

Constructor Details

#initialize(file_path:, ref:, **kwargs) ⇒ RepositoryFilesClient

Returns a new instance of RepositoryFilesClient.



9
10
11
12
13
# File 'lib/gitlab_quality/test_tooling/gitlab_client/repository_files_client.rb', line 9

def initialize(file_path:, ref:, **kwargs)
  @file_path = file_path
  @ref = ref
  super(**kwargs)
end

Instance Attribute Details

#file_pathObject (readonly)

Returns the value of attribute file_path.



7
8
9
# File 'lib/gitlab_quality/test_tooling/gitlab_client/repository_files_client.rb', line 7

def file_path
  @file_path
end

#refObject (readonly)

Returns the value of attribute ref.



7
8
9
# File 'lib/gitlab_quality/test_tooling/gitlab_client/repository_files_client.rb', line 7

def ref
  @ref
end

Instance Method Details

#file_contentsObject



15
16
17
18
19
# File 'lib/gitlab_quality/test_tooling/gitlab_client/repository_files_client.rb', line 15

def file_contents
  handle_gitlab_client_exceptions do
    client.file_contents(project, file_path.gsub(%r{^/}, ""), ref)
  end
end

#file_contents_at_line(line_number) ⇒ Object



21
22
23
24
25
# File 'lib/gitlab_quality/test_tooling/gitlab_client/repository_files_client.rb', line 21

def file_contents_at_line(line_number)
  ignore_gitlab_client_exceptions do
    file_contents.lines(chomp: true)[line_number - 1]
  end
end