Sha256: 00a69717e4e6a66656cce88d6d98afc2a8af9ec8957890edd86c93c39f65e937

Contents?: true

Size: 1.6 KB

Versions: 1

Compression:

Stored size: 1.6 KB

Contents

#!/usr/bin/env ruby

require "bundler/setup"
require "octokit"
require "thor"

class GithubCommitStatusUpdater < Thor
  STATUSES = %w(pending success failure error)

  STATUSES.each do |method|
    method_option :repo, :type => :string, :required => true, :aliases => "-r"
    method_option :sha1, :type => :string, :required => true, :aliases => "-s"
    method_option :username, :type => :string, :aliases => "-u"
    method_option :password, :type => :string, :aliases => "-p"
    method_option :oauth_token, :type => :string
    method_option :target_url, :type => :string
    method_option :description, :type => :string
    method_option :web_endpoint, :type => :string

    desc "#{method}", "commit status #{method}"
    define_method "#{method}" do
      begin
        if options.web_endpoint
          Octokit.configure do |c|
            c.api_endpoint = options.web_endpoint + 'api/v3'
            c.web_endpoint = options.web_endpoint
          end
        end
        client.create_status(options.repo, options.sha1, method, {target_url: options.target_url, description: options.description})
        puts "Changed status as #{method}"
      rescue Octokit::Error => e
        $stderr.puts "Update error: #{e.message}"
      end
    end
  end

  private
  def client
    if options.username && options.password
      Octokit::Client.new(:login => options.username, :password => options.password)
    elsif options.username && options.oauth_token
      Octokit::Client.new(:login => options.username, :oauth_token => options.oauth_token)
    else
      Octokit::Client.new
    end
  end
end

GithubCommitStatusUpdater.start

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
github-commit-status-updater-1.0.2 bin/github-commit-status-updater