Class: Rbcli::Autoupdate::GithubUpdater

Inherits:
Object
  • Object
show all
Includes:
Common
Defined in:
lib/rbcli/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) ⇒ GithubUpdater

Returns a new instance of GithubUpdater.



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/rbcli/autoupdate/github_updater.rb', line 7

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

	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



34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/rbcli/autoupdate/github_updater.rb', line 34

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



26
27
28
# File 'lib/rbcli/autoupdate/github_updater.rb', line 26

def get_latest_version
	@client.repo(@reponame).rels[:tags].get.data.map{ |t| t[:name] }[0].sub(/^[v]*/,"")
end

#update_messageObject



30
31
32
# File 'lib/rbcli/autoupdate/github_updater.rb', line 30

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