Sha256: 8834c1c19853f4b676fbe87bf06318292696b2d57416d68a460ed94f6fbceb02

Contents?: true

Size: 1.86 KB

Versions: 15

Compression:

Stored size: 1.86 KB

Contents

#!/usr/bin/env ruby
# frozen_string_literal: true

require 'gitlab'

# Configure credentials to be used with gitlab gem
Gitlab.configure do |config|
  config.endpoint = 'https://gitlab.com/api/v4'
  config.private_token = ENV['GITLAB_BOT_MULTI_PROJECT_PIPELINE_POLLING_TOKEN']
end

class CommitComment
  def self.post!(status, report_file_name)
    unless ENV['TOP_UPSTREAM_SOURCE_SHA']
      puts "The 'TOP_UPSTREAM_SOURCE_SHA' environment variable is missing, cannot post a comment on a missing upstream commit."
      return
    end

    top_upstream_source_sha = ENV['TOP_UPSTREAM_SOURCE_SHA']

    unless ENV['TOP_UPSTREAM_SOURCE_PROJECT']
      puts "The 'TOP_UPSTREAM_SOURCE_PROJECT' environment variable is missing, cannot post a comment on the upstream #{top_upstream_source_sha} commit."
      return
    end

    top_upstream_source_project = ENV['TOP_UPSTREAM_SOURCE_PROJECT']

    status_with_icon =
      case status
      when :success
        "passed. :white_check_mark:"
      when :failure
        "failed! :boom:"
      end

    # The HTML report can't be opened as a web page so we're forced to
    # download it. See https://gitlab.com/gitlab-org/gitlab/issues/25192
    Gitlab.create_commit_comment(
      top_upstream_source_project,
      top_upstream_source_sha,
      <<~COMMENT
        The [`gitlab-qa` downstream pipeline](#{ENV['CI_PIPELINE_URL']}) #{status_with_icon}.

        You can download a report of the test results: [`#{report_file_name}`](#{ENV['CI_JOB_URL']}/artifacts/raw/#{report_file_name})
      COMMENT
    )
  rescue Gitlab::Error::Error => error
    puts "Ignoring the following error: #{error}"
  end
end

status = ARGV.shift.to_s.strip
report_file_name = ARGV.shift.to_s.strip

abort "Please provide a status!" if status == ''
abort "Please provide a file name for the report!" if report_file_name == ''

CommitComment.post!(status.to_sym, report_file_name)

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
gitlab-qa-4.16.0 bin/notify_upstream_commit
gitlab-qa-4.15.0 bin/notify_upstream_commit
gitlab-qa-4.14.0 bin/notify_upstream_commit
gitlab-qa-4.13.0 bin/notify_upstream_commit
gitlab-qa-4.12.0 bin/notify_upstream_commit
gitlab-qa-4.11.0 bin/notify_upstream_commit
gitlab-qa-4.10.0 bin/notify_upstream_commit
gitlab-qa-4.9.0 bin/notify_upstream_commit
gitlab-qa-4.8.1 bin/notify_upstream_commit
gitlab-qa-4.8.0 bin/notify_upstream_commit
gitlab-qa-4.7.1 bin/notify_upstream_commit
gitlab-qa-4.7.0 bin/notify_upstream_commit
gitlab-qa-4.6.0 bin/notify_upstream_commit
gitlab-qa-4.5.0 bin/notify_upstream_commit
gitlab-qa-4.4.0 bin/notify_upstream_commit