Class: Rbcli::Autoupdate::GithubUpdater

Inherits:
Object
  • Object
show all
Includes:
Common
Defined in:
lib/rbcli/features/autoupdate/github_updater.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Common

#show_message, #update_available?

Constructor Details

#initialize(reponame, access_token, enterprise_hostname, force_update, message) ⇒ GithubUpdater

Returns a new instance of GithubUpdater.



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/rbcli/features/autoupdate/github_updater.rb', line 28

def initialize reponame, access_token, enterprise_hostname, force_update, message
	@reponame = reponame
	@force_update = force_update
	@message = message

	access_token = Rbcli.config.key?(:github_updatecheck) ? (Rbcli.config[:github_updatecheck][:access_token] || access_token) : access_token
	enterprise_hostname = Rbcli.config.key?(:github_updatecheck) ? (Rbcli.config[:github_updatecheck][:enterprise_hostname] || enterprise_hostname) : enterprise_hostname

	# Enterprise Connection
	if enterprise_hostname
		Octokit.configure do |c|
			c.api_endpoint = "https://#{enterprise_hostname}/api/v3/"
		end
		# Public Github Connection
	end
	#OAuth connection - not used
	#@client = Octokit::Client.new :client_id => client_id, :client_secret => client_secret
	@client = Octokit::Client.new(:access_token => access_token)
end

Class Method Details

.save_defaultsObject



63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/rbcli/features/autoupdate/github_updater.rb', line 63

def self.save_defaults
	Rbcli::Config::add_categorized_defaults :github_update, 'Automatically Check for Updates from GitHub', {
			access_token: {
					description: 'Access token for GitHub API. This is only required for private repos. For help, see: https://help.github.com/articles/creating-a-personal-access-token-for-the-command-line/',
					value: nil
			},
			enterprise_hostname: {
					description: 'Hostname for GitHub Enterprise. Leave as null (~) for public GitHub.',
					value: nil
			}
	}
end

Instance Method Details

#get_latest_versionObject



48
49
50
51
52
53
54
55
56
57
# File 'lib/rbcli/features/autoupdate/github_updater.rb', line 48

def get_latest_version
	begin
		@client.repo(@reponame).rels[:tags].get.data.map{ |t| t[:name] }[0].sub(/^[v]*/,"")
	rescue Faraday::ConnectionFailed => e
		# This is to capture connection errors without bothering the user.
	rescue NoMethodError => e
		# This ignores repos with no tags
	end

end

#update_messageObject



59
60
61
# File 'lib/rbcli/features/autoupdate/github_updater.rb', line 59

def update_message
	"Please check the github repo #{@reponame} for instructions."
end