Sha256: b75e33edc6e3b9cc54f57fadb8a9812773ba147988f4eba4c7a3b40c7c8eac9f

Contents?: true

Size: 1.2 KB

Versions: 1

Compression:

Stored size: 1.2 KB

Contents

require 'contracts'

module GitHubStatus
  module Support
    module Params
      include ::Contracts::Core
      include ::Contracts::Builtin

      Contract None => String
      def path
        @path ||= params.fetch 'path'
      rescue KeyError
        STDERR.puts 'Params is missing path'
        abort
      end

      Contract None => Enum['success', 'pending', 'failure']
      def state
        @state ||= params.fetch 'state'
      rescue KeyError
        STDERR.puts 'Params is missing state'
        abort
      end

      Contract None => String
      def context
        @context ||= params.fetch 'context', ENV["BUILD_JOB_NAME"]
      end

      Contract None => String
      def description
        @description ||= params.fetch 'description', "#{ENV["BUILD_JOB_NAME"]} number #{ENV["BUILD_NAME"]}"
      end

      Contract None => Array
      def statuses
        @statuses ||= params.fetch 'statuses', []
      end

      Contract None => String
      def target_url
        url = params.fetch 'target_url', "#{atc_external_url}/builds/#{build_id}"
        if File.file?("#{workdir}/#{url}")
          url = File.read("#{workdir}/#{url}").chomp
        end
        @target_url ||= url
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
concourse-github-status-0.7.1 lib/github-status/support/params.rb