class WatchDoge::Notification::GitlabRepo

Public Class Methods

new(opt) click to toggle source
Calls superclass method WatchDoge::Notification::Base::new
# File lib/watchdoge/notification/gitlab_repo.rb, line 13
def initialize opt
  super

  @host = opt[:host] || ENV['CI_API_V4_URL']
  @project_id = opt[:project_id] || ENV['CI_PROJECT_ID']
  @source_branch = opt[:source_branch] || ENV['CI_COMMIT_REF_NAME']
  @commit_short_sha = opt[:commit_short_sha] || ENV['CI_COMMIT_SHORT_SHA']

  @private_token = opt[:private_token]
end

Public Instance Methods

flush() click to toggle source
# File lib/watchdoge/notification/gitlab_repo.rb, line 24
def flush
  return if @message_queue.empty?

  meesages_to_flush = @message_queue
  @message_queue = []

  target_id = get_latest_request_iid || get_commit_id

  raise RuntimeError, "Can't find any target to pushing message" if target_id.nil?

  thread = disscussion_thread do |thread_context|
    meesages_to_flush.each do |message|
      case message
      when String
        post_discussion target_id, message: message
      when ChunkyPNG::Image
        upload_link = upload_image message
        link = md_img_link upload_link

        post_discussion target_id, message: link
      when WatchDoge::PixelTest
        filename = message.option[:filename]

        before = md_img_link upload_image(message.before)
        after = md_img_link upload_image(message.after)
        diff = md_img_link upload_image(message.diff)

        thread_context << markdown_table(before, after, diff, filename)
      end
    end

    thread_context
  end

  post_discussion target_id, message: thread
end
post_discussion(target_iid, message: uri = case @discussion_target) click to toggle source
# File lib/watchdoge/notification/gitlab_repo.rb, line 61
def post_discussion target_iid, message:
  uri =
    case @discussion_target
    when :merge_request
      project_uri("/merge_requests/#{target_iid}/discussions")
    when :commit
      project_uri("/repository/commits/#{target_iid}/discussions")
    end