diff --git a/lib/gitlab/api_client.rb b/lib/gitlab/api_client.rb new file mode 100644 index 0000000000000000000000000000000000000000..095406f353980a0d492e2e401ec6018f3c995511_bGliL2dpdGxhYi9hcGlfY2xpZW50LnJi --- /dev/null +++ b/lib/gitlab/api_client.rb @@ -0,0 +1,12 @@ +require_relative 'build/info/ci' +require_relative 'build/info/secrets' + +require 'gitlab' + +module Gitlab + class APIClient + def initialize(endpoint = Build::Info::CI.api_v4_url, token = Build::Info::Secrets.api_token) + @client = ::Gitlab::Client.new(endpoint: endpoint, private_token: token) + end + end +end diff --git a/lib/gitlab/build/info/ci.rb b/lib/gitlab/build/info/ci.rb new file mode 100644 index 0000000000000000000000000000000000000000..095406f353980a0d492e2e401ec6018f3c995511_bGliL2dpdGxhYi9idWlsZC9pbmZvL2NpLnJi --- /dev/null +++ b/lib/gitlab/build/info/ci.rb @@ -0,0 +1,39 @@ +require_relative '../../util' +require_relative '../../api_client' +require_relative '../check' + +module Build + class Info + class CI + class << self + def branch_name + Gitlab::Util.get_env('CI_COMMIT_BRANCH') + end + + def tag_name + Gitlab::Util.get_env('CI_COMMIT_TAG') + end + + def project_id + Gitlab::Util.get_env('CI_PROJECT_ID') + end + + def pipeline_id + Gitlab::Util.get_env('CI_PIPELINE_ID') + end + + def job_id + Gitlab::Util.get_env('CI_JOB_ID') + end + + def job_token + Gitlab::Util.get_env('CI_JOB_TOKEN') + end + + def api_v4_url + Gitlab::Util.get_env('CI_API_V4_URL') + end + end + end + end +end diff --git a/lib/gitlab/build/info/secrets.rb b/lib/gitlab/build/info/secrets.rb new file mode 100644 index 0000000000000000000000000000000000000000..095406f353980a0d492e2e401ec6018f3c995511_bGliL2dpdGxhYi9idWlsZC9pbmZvL3NlY3JldHMucmI= --- /dev/null +++ b/lib/gitlab/build/info/secrets.rb @@ -0,0 +1,17 @@ +require_relative '../../util' + +module Build + class Info + class Secrets + class << self + def api_token(scope: 'reporter') + Gitlab::Util.get_env("GITLAB_API_#{scope.upcase}_TOKEN") + end + + def ci_job_token + Build::Info::CI.job_token + end + end + end + end +end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 937b2fa1422a83d5a0a06b3e4e75e0bb063b8378_c3BlYy9zcGVjX2hlbHBlci5yYg==..095406f353980a0d492e2e401ec6018f3c995511_c3BlYy9zcGVjX2hlbHBlci5yYg== 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -19,6 +19,14 @@ require 'gitlab/util' require 'rspec-parameterized' +# Because our library directory is also named `gitlab`, it collides with +# upstream 'gitlab' gem's code. So, we set a dummy value to the `VERSION` +# constant so that the `gitlab` library can be required without issues. The +# proper fix is renaming our directory to `omnibus_gitlab` to match convention. +module Gitlab + VERSION = 'dummy-version'.freeze +end + # Load support libraries to provide common convenience methods for our tests Dir["./spec/support/**/*.rb"].each { |f| require f }