Sha256: f114d548d4472d968c10e0b78901f82f59303ab92de59bb89456e15970653d8e
Contents?: true
Size: 1.66 KB
Versions: 6
Compression:
Stored size: 1.66 KB
Contents
# frozen_string_literal: true module CiToolkit # allows to have a combined build status for all builds that are triggered for a pull request # it uses the description of the status check on Github to parse the number of builds remaining and total class BuildStatus def initialize( context = "Builds", github = CiToolkit::DvcsPrFactory.create(CiToolkit::BitriseEnv.new), env = CiToolkit::BitriseEnv.new ) @context = context @github = github @env = env end def start(num_builds, state = "pending") target_url = @env.app_url desc = "Finished building 0/#{num_builds}" if num_builds.zero? state = "success" desc = "No builds assigned" target_url = @env.build_url end @github.create_status(state, @context, target_url, desc) end def increment(status = CiToolkit::DvcsPrUtil.status_state_pending) counter = load_counter return if counter.nil? num_finished = counter[:num_finished] + 1 num_total = counter[:num_total] state = status state = "success" if num_finished == num_total @github.create_status(state, @context, @env.app_url, "Finished building #{num_finished}/#{num_total}") end def error(state = CiToolkit::DvcsPrUtil.status_state_error) @github.create_status(state, @context, @env.app_url, "Building failed") end def load_counter description = @github.get_status_description(@context) return if description.nil? build_counter = description[%r{(\d/\d)}] || "0/0" { num_finished: build_counter.split("/")[0].to_i, num_total: build_counter.split("/")[1].to_i } end end end
Version data entries
6 entries across 6 versions & 1 rubygems