#!/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 desc "#{method}", "commit status #{method}" define_method "#{method}" do begin 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