summaryrefslogtreecommitdiff
path: root/scripts/api
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2020-11-24 09:09:32 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2020-11-24 09:09:32 +0000
commit4372b0ca297cb4659bfcf81d511b70004bf365af (patch)
tree54d45c5e1ee088fef1434eae19029dc83e6d6fe9 /scripts/api
parent0d312b8d370738d1dfa089b59ed21f40af1d4add (diff)
downloadgitlab-ce-4372b0ca297cb4659bfcf81d511b70004bf365af.tar.gz
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'scripts/api')
-rwxr-xr-xscripts/api/cancel_pipeline58
-rwxr-xr-xscripts/api/download_job_artifact92
-rwxr-xr-xscripts/api/get_job_id108
-rwxr-xr-xscripts/api/play_job60
4 files changed, 0 insertions, 318 deletions
diff --git a/scripts/api/cancel_pipeline b/scripts/api/cancel_pipeline
deleted file mode 100755
index 0965877a69a..00000000000
--- a/scripts/api/cancel_pipeline
+++ /dev/null
@@ -1,58 +0,0 @@
-#!/usr/bin/env ruby
-# frozen_string_literal: true
-
-require 'rubygems'
-require 'gitlab'
-require 'optparse'
-require_relative 'get_job_id'
-
-class CancelPipeline
- DEFAULT_OPTIONS = {
- project: ENV['CI_PROJECT_ID'],
- pipeline_id: ENV['CI_PIPELINE_ID'],
- api_token: ENV['GITLAB_BOT_MULTI_PROJECT_PIPELINE_POLLING_TOKEN']
- }.freeze
-
- def initialize(options)
- @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
- end
-
- def execute
- Gitlab.cancel_pipeline(project, pipeline_id)
- end
-
- private
-
- attr_reader :project, :pipeline_id
-end
-
-if $0 == __FILE__
- options = CancelPipeline::DEFAULT_OPTIONS.dup
-
- OptionParser.new do |opts|
- opts.on("-p", "--project PROJECT", String, "Project where to find the job (defaults to $CI_PROJECT_ID)") do |value|
- options[:project] = value
- end
-
- opts.on("-i", "--pipeline-id PIPELINE_ID", String, "A pipeline ID (defaults to $CI_PIPELINE_ID)") do |value|
- options[:pipeline_id] = value
- end
-
- opts.on("-t", "--api-token API_TOKEN", String, "A value API token with the `read_api` scope") do |value|
- options[:api_token] = value
- end
-
- opts.on("-h", "--help", "Prints this help") do
- puts opts
- exit
- end
- end.parse!
-
- CancelPipeline.new(options).execute
-end
diff --git a/scripts/api/download_job_artifact b/scripts/api/download_job_artifact
deleted file mode 100755
index 9ac24ff624d..00000000000
--- a/scripts/api/download_job_artifact
+++ /dev/null
@@ -1,92 +0,0 @@
-#!/usr/bin/env ruby
-# frozen_string_literal: true
-
-require 'rubygems'
-require 'optparse'
-require 'fileutils'
-require 'uri'
-require 'cgi'
-require 'net/http'
-
-class ArtifactFinder
- DEFAULT_OPTIONS = {
- project: ENV['CI_PROJECT_ID'],
- api_token: ENV['GITLAB_BOT_MULTI_PROJECT_PIPELINE_POLLING_TOKEN']
- }.freeze
-
- def initialize(options)
- @project = options.delete(:project)
- @job_id = options.delete(:job_id)
- @api_token = options.delete(:api_token)
- @artifact_path = options.delete(:artifact_path)
- end
-
- def execute
- url = "https://gitlab.com/api/v4/projects/#{CGI.escape(project)}/jobs/#{job_id}/artifacts"
-
- if artifact_path
- FileUtils.mkdir_p(File.dirname(artifact_path))
- url += "/#{artifact_path}"
- end
-
- fetch(url)
- end
-
- private
-
- attr_reader :project, :job_id, :api_token, :artifact_path
-
- def fetch(uri_str, limit = 10)
- raise 'Too many HTTP redirects' if limit == 0
-
- uri = URI(uri_str)
- request = Net::HTTP::Get.new(uri)
- request['Private-Token'] = api_token
-
- Net::HTTP.start(uri.host, uri.port, use_ssl: true) do |http|
- http.request(request) do |response|
- case response
- when Net::HTTPSuccess then
- File.open(artifact_path || 'artifacts.zip', 'w') do |file|
- response.read_body(&file.method(:write))
- end
- when Net::HTTPRedirection then
- location = response['location']
- warn "Redirected (#{limit - 1} redirections remaining)."
- fetch(location, limit - 1)
- else
- raise "Unexpected response: #{response.value}"
- end
- end
- end
- end
-end
-
-if $0 == __FILE__
- options = ArtifactFinder::DEFAULT_OPTIONS.dup
-
- OptionParser.new do |opts|
- opts.on("-p", "--project PROJECT", String, "Project where to find the job (defaults to $CI_PROJECT_ID)") do |value|
- options[:project] = value
- end
-
- opts.on("-j", "--job-id JOB_ID", String, "A job ID") do |value|
- options[:job_id] = value
- end
-
- opts.on("-a", "--artifact-path ARTIFACT_PATH", String, "A valid artifact path") do |value|
- options[:artifact_path] = value
- end
-
- opts.on("-t", "--api-token API_TOKEN", String, "A value API token with the `read_api` scope") do |value|
- options[:api_token] = value
- end
-
- opts.on("-h", "--help", "Prints this help") do
- puts opts
- exit
- end
- end.parse!
-
- ArtifactFinder.new(options).execute
-end
diff --git a/scripts/api/get_job_id b/scripts/api/get_job_id
deleted file mode 100755
index 2324f6ca9d3..00000000000
--- a/scripts/api/get_job_id
+++ /dev/null
@@ -1,108 +0,0 @@
-#!/usr/bin/env ruby
-# frozen_string_literal: true
-
-require 'rubygems'
-require 'gitlab'
-require 'optparse'
-
-class JobFinder
- DEFAULT_OPTIONS = {
- project: ENV['CI_PROJECT_ID'],
- pipeline_id: ENV['CI_PIPELINE_ID'],
- pipeline_query: {},
- job_query: {},
- api_token: ENV['GITLAB_BOT_MULTI_PROJECT_PIPELINE_POLLING_TOKEN']
- }.freeze
-
- def initialize(options)
- @project = options.delete(:project)
- @pipeline_query = options.delete(:pipeline_query)
- @job_query = options.delete(:job_query)
- @pipeline_id = options.delete(:pipeline_id)
- @job_name = options.delete(:job_name)
-
- Gitlab.configure do |config|
- config.endpoint = 'https://gitlab.com/api/v4'
- config.private_token = options.delete(:api_token)
- end
- end
-
- def execute
- find_job_with_filtered_pipelines || find_job_in_pipeline
- end
-
- private
-
- attr_reader :project, :pipeline_query, :job_query, :pipeline_id, :job_name
-
- 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|
- return job if job.name == job_name # rubocop:disable Cop/AvoidReturnFromBlocks
- end
- end
-
- raise 'Job not found!'
- end
-
- def find_job_in_pipeline
- return unless pipeline_id
-
- Gitlab.pipeline_jobs(project, pipeline_id, job_query_params).auto_paginate do |job|
- return job if job.name == job_name # rubocop:disable Cop/AvoidReturnFromBlocks
- end
-
- raise 'Job not found!'
- end
-
- def pipeline_query_params
- @pipeline_query_params ||= { per_page: 100, **pipeline_query }
- end
-
- def job_query_params
- @job_query_params ||= { per_page: 100, **job_query }
- end
-end
-
-if $0 == __FILE__
- options = JobFinder::DEFAULT_OPTIONS.dup
-
- OptionParser.new do |opts|
- opts.on("-p", "--project PROJECT", String, "Project where to find the job (defaults to $CI_PROJECT_ID)") do |value|
- options[:project] = value
- end
-
- opts.on("-i", "--pipeline-id pipeline_id", String, "A pipeline ID (defaults to $CI_PIPELINE_ID)") do |value|
- options[:pipeline_id] = value
- end
-
- opts.on("-q", "--pipeline-query pipeline_query", String, "Query to pass to the Pipeline API request") do |value|
- options[:pipeline_query].merge!(Hash[*value.split('=')])
- end
-
- opts.on("-Q", "--job-query job_query", String, "Query to pass to the Job API request") do |value|
- options[:job_query].merge!(Hash[*value.split('=')])
- end
-
- opts.on("-j", "--job-name job_name", String, "A job name that needs to exist in the found pipeline") do |value|
- options[:job_name] = value
- end
-
- opts.on("-t", "--api-token API_TOKEN", String, "A value API token with the `read_api` scope") do |value|
- options[:api_token] = value
- end
-
- opts.on("-h", "--help", "Prints this help") do
- puts opts
- exit
- end
- end.parse!
-
- job = JobFinder.new(options).execute
-
- return if job.nil?
-
- puts job.id
-end
diff --git a/scripts/api/play_job b/scripts/api/play_job
deleted file mode 100755
index 199f7e65633..00000000000
--- a/scripts/api/play_job
+++ /dev/null
@@ -1,60 +0,0 @@
-#!/usr/bin/env ruby
-# frozen_string_literal: true
-
-require 'rubygems'
-require 'gitlab'
-require 'optparse'
-require_relative 'get_job_id'
-
-class PlayJob
- DEFAULT_OPTIONS = {
- project: ENV['CI_PROJECT_ID'],
- pipeline_id: ENV['CI_PIPELINE_ID'],
- api_token: ENV['GITLAB_BOT_MULTI_PROJECT_PIPELINE_POLLING_TOKEN']
- }.freeze
-
- def initialize(options)
- @project = options.delete(:project)
- @options = options
-
- Gitlab.configure do |config|
- config.endpoint = 'https://gitlab.com/api/v4'
- config.private_token = options.fetch(:api_token)
- end
- end
-
- def execute
- job = JobFinder.new(project, options.slice(:api_token, :pipeline_id, :job_name).merge(scope: 'manual')).execute
-
- Gitlab.job_play(project, job.id)
- end
-
- private
-
- attr_reader :project, :options
-end
-
-if $0 == __FILE__
- options = PlayJob::DEFAULT_OPTIONS.dup
-
- OptionParser.new do |opts|
- opts.on("-p", "--project PROJECT", String, "Project where to find the job (defaults to $CI_PROJECT_ID)") do |value|
- options[:project] = value
- end
-
- opts.on("-j", "--job-name JOB_NAME", String, "A job name that needs to exist in the found pipeline") do |value|
- options[:job_name] = value
- end
-
- opts.on("-t", "--api-token API_TOKEN", String, "A value API token with the `read_api` scope") do |value|
- options[:api_token] = value
- end
-
- opts.on("-h", "--help", "Prints this help") do
- puts opts
- exit
- end
- end.parse!
-
- PlayJob.new(options).execute
-end