Sha256: 568b5309d0c51781303c009612b01dcca5c551165d5ed98bc8b701bc6aaa48b1

Contents?: true

Size: 1.81 KB

Versions: 5

Compression:

Stored size: 1.81 KB

Contents

module Wassup
  module Helpers
    module Netlify
      require 'json'
      require 'rest-client'

      def self.deploys(site_id:)
        resp = RestClient::Request.execute(
          method: :get, 
          url: "https://api.netlify.com/api/v1/sites/#{site_id}/deploys", 
          headers: { "Authorization": "Bearer #{ENV['WASSUP_NETLIFY_TOKEN']}", "User-Agent": "Wassup" }
        )
        return JSON.parse(resp)
      end

    end
  end
end

module Wassup
  module Helpers
    module Netlify
      module Formatter
        def self.deploy(deploy)
          review_id = deploy["review_id"]
          context = deploy["context"]
          state = deploy["state"]
          error_message = deploy["error_message"]
          branch = deploy["branch"]
          commit_ref = deploy["commit_ref"] || "HEAD"
          url = deploy["deploy_url"]

          if error_message.to_s.downcase.include?("canceled")
            state = "cancelled"
          end

          color = "green"
          if state == "building"
            color = "yellow"
          elsif state == "enqueued"
            color = "magenta"
          elsif state == "cancelled"
            color = "gray"
          elsif state == "error"
            color = "red"
          end

          display_context = context.split('-').map(&:capitalize).join(' ')
          display_context = "[fg=#{color}]#{display_context}"

          if !review_id.nil?
            display_context += " - ##{review_id}"
          end

          display_context += "[fg=gray]"
          display_context += " (#{state})"
          display_context += "[fg=white]"

          if !branch.nil? && !commit_ref.nil?
            display_context += "[fg=cyan]: #{branch}@#{commit_ref[0...7]}"
          end

          display = "#{display_context}"

          return display
        end
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
wassup-0.4.1 lib/wassup/helpers/netlify.rb
wassup-0.4.0 lib/wassup/helpers/netlify.rb
wassup-0.3.2 lib/wassup/helpers/netlify.rb
wassup-0.3.1 lib/wassup/helpers/netlify.rb
wassup-0.3.0 lib/wassup/helpers/netlify.rb