Class: StateSync::GitlabFetcher
- Inherits:
-
Object
- Object
- StateSync::GitlabFetcher
- Defined in:
- lib/state_sync/fetchers/gitlab_fetcher.rb
Constant Summary collapse
- API_BASE =
"https://gitlab.com/api/v4"
Instance Method Summary collapse
-
#fetch(path) ⇒ Object
Fetches raw file content from GitLab using the repository files raw endpoint.
-
#initialize(config) ⇒ GitlabFetcher
constructor
A new instance of GitlabFetcher.
Constructor Details
#initialize(config) ⇒ GitlabFetcher
Returns a new instance of GitlabFetcher.
7 8 9 |
# File 'lib/state_sync/fetchers/gitlab_fetcher.rb', line 7 def initialize(config) @config = config end |
Instance Method Details
#fetch(path) ⇒ Object
Fetches raw file content from GitLab using the repository files raw endpoint. ref=HEAD always resolves to the project’s default branch.
13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/state_sync/fetchers/gitlab_fetcher.rb', line 13 def fetch(path) encoded_repo = URI.encode_www_form_component(@config.repo) encoded_path = URI.encode_www_form_component(path) uri = URI("#{API_BASE}/projects/#{encoded_repo}/repository/files/#{encoded_path}/raw?ref=HEAD") request = Net::HTTP::Get.new(uri) request["PRIVATE-TOKEN"] = @config.token if @config.token response = Net::HTTP.start(uri.hostname, uri.port, use_ssl: true) do |http| http.request(request) end handle_response(response, path) end |