Commit a9e566d0 authored by Rémy Coutable's avatar Rémy Coutable Committed by Lin Jen-Shin

tooling: Work around a gitlab gem bug to make unauthenticated requests

Signed-off-by: default avatarRémy Coutable <remy@rymai.me>
parent 72fdd799
...@@ -4,7 +4,6 @@ ...@@ -4,7 +4,6 @@
require 'rubygems' require 'rubygems'
require 'gitlab' require 'gitlab'
require 'optparse' require 'optparse'
require 'cgi'
class JobFinder class JobFinder
DEFAULT_OPTIONS = { DEFAULT_OPTIONS = {
...@@ -21,14 +20,16 @@ class JobFinder ...@@ -21,14 +20,16 @@ class JobFinder
@job_query = options.delete(:job_query) @job_query = options.delete(:job_query)
@pipeline_id = options.delete(:pipeline_id) @pipeline_id = options.delete(:pipeline_id)
@job_name = options.delete(:job_name) @job_name = options.delete(:job_name)
@api_token = options.delete(:api_token)
# Force the token to be a string so that if api_token is nil, it's set to '', allowing unauthenticated requests (for forks).
api_token = options.delete(:api_token).to_s
warn "No API token given." if api_token.empty?
Gitlab.configure do |config| Gitlab.configure do |config|
config.endpoint = 'https://gitlab.com/api/v4' config.endpoint = 'https://gitlab.com/api/v4'
config.private_token = api_token if api_token config.private_token = api_token
end end
warn "No API token given." unless api_token
end end
def execute def execute
...@@ -37,21 +38,13 @@ class JobFinder ...@@ -37,21 +38,13 @@ class JobFinder
private private
attr_reader :project, :pipeline_query, :job_query, :pipeline_id, :job_name, :api_token attr_reader :project, :pipeline_query, :job_query, :pipeline_id, :job_name
def find_job_with_filtered_pipelines def find_job_with_filtered_pipelines
return if pipeline_query.empty? return if pipeline_query.empty?
Gitlab.get( Gitlab.pipelines(project, pipeline_query_params).auto_paginate do |pipeline|
"/projects/#{CGI.escape(project)}/pipelines", Gitlab.pipeline_jobs(project, pipeline.id, job_query_params).auto_paginate do |job|
query: pipeline_query_params,
unauthenticated: api_token.nil?
).auto_paginate do |pipeline|
Gitlab.get(
"/projects/#{CGI.escape(project)}/pipelines/#{pipeline.id}/jobs",
query: job_query_params,
unauthenticated: api_token.nil?
).auto_paginate do |job|
return job if job.name == job_name # rubocop:disable Cop/AvoidReturnFromBlocks return job if job.name == job_name # rubocop:disable Cop/AvoidReturnFromBlocks
end end
end end
...@@ -62,11 +55,7 @@ class JobFinder ...@@ -62,11 +55,7 @@ class JobFinder
def find_job_in_pipeline def find_job_in_pipeline
return unless pipeline_id return unless pipeline_id
Gitlab.get( Gitlab.pipeline_jobs(project, pipeline_id, job_query_params).auto_paginate do |job|
"/projects/#{CGI.escape(project)}/pipelines/#{pipeline_id}/jobs",
query: job_query_params,
unauthenticated: api_token.nil?
).auto_paginate do |job|
return job if job.name == job_name # rubocop:disable Cop/AvoidReturnFromBlocks return job if job.name == job_name # rubocop:disable Cop/AvoidReturnFromBlocks
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment