Commit 1e58dd09 authored by Lin Jen-Shin's avatar Lin Jen-Shin

Prefer CI_API_V4_URL for scripts/api/cancel_pipeline.rb

Also avoid using global GitLab client
parent 34836d37
......@@ -18,19 +18,19 @@ class CancelPipeline
@project = options.delete(:project)
@pipeline_id = options.delete(:pipeline_id)
Gitlab.configure do |config|
config.endpoint = 'https://gitlab.com/api/v4'
config.private_token = options.delete(:api_token)
end
@client = Gitlab.client(
endpoint: ENV.fetch('CI_API_V4_URL', 'https://gitlab.com/api/v4'),
private_token: options.delete(:api_token)
)
end
def execute
Gitlab.cancel_pipeline(project, pipeline_id)
client.cancel_pipeline(project, pipeline_id)
end
private
attr_reader :project, :pipeline_id
attr_reader :project, :pipeline_id, :client
end
if $0 == __FILE__
......
......@@ -28,10 +28,10 @@ class JobFinder
warn "No API token given." if api_token.empty?
Gitlab.configure do |config|
config.endpoint = 'https://gitlab.com/api/v4'
config.private_token = api_token
end
@client = Gitlab.client(
endpoint: 'https://gitlab.com/api/v4',
private_token: api_token
)
end
def execute
......@@ -40,13 +40,13 @@ class JobFinder
private
attr_reader :project, :pipeline_query, :job_query, :pipeline_id, :job_name, :artifact_path
attr_reader :project, :pipeline_query, :job_query, :pipeline_id, :job_name, :artifact_path, :client
def find_job_with_artifact
return if artifact_path.nil?
Gitlab.pipelines(project, pipeline_query_params).auto_paginate do |pipeline|
Gitlab.pipeline_jobs(project, pipeline.id, job_query_params).auto_paginate do |job|
client.pipelines(project, pipeline_query_params).auto_paginate do |pipeline|
client.pipeline_jobs(project, pipeline.id, job_query_params).auto_paginate do |job|
return job if found_job_with_artifact?(job) # rubocop:disable Cop/AvoidReturnFromBlocks
end
end
......@@ -57,8 +57,8 @@ class JobFinder
def find_job_with_filtered_pipelines
return if pipeline_query.empty?
Gitlab.pipelines(project, pipeline_query_params).auto_paginate do |pipeline|
Gitlab.pipeline_jobs(project, pipeline.id, job_query_params).auto_paginate do |job|
client.pipelines(project, pipeline_query_params).auto_paginate do |pipeline|
client.pipeline_jobs(project, pipeline.id, job_query_params).auto_paginate do |job|
return job if found_job_by_name?(job) # rubocop:disable Cop/AvoidReturnFromBlocks
end
end
......@@ -69,7 +69,7 @@ class JobFinder
def find_job_in_pipeline
return unless pipeline_id
Gitlab.pipeline_jobs(project, pipeline_id, job_query_params).auto_paginate do |job|
client.pipeline_jobs(project, pipeline_id, job_query_params).auto_paginate do |job|
return job if found_job_by_name?(job) # rubocop:disable Cop/AvoidReturnFromBlocks
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