Class: AppVersion::Release

Inherits:
Object
  • Object
show all
Defined in:
lib/appversion.rb

Class Method Summary collapse

Class Method Details

.is_pre_release?(tag) ⇒ Boolean

Returns:

  • (Boolean)


4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/appversion.rb', line 4

def self.is_pre_release?(tag)
  default = TRUE #default to true if running locally
  begin
    if tag.empty?
      p 'No tag, so unable to check Github release status'
      default
    else
      require 'octokit'
      repo = CI.repo || Git.repo
      $stdout.puts  "Repo slug is #{repo}"
      if repo.empty? || ENV['GITHUB_TOKEN'].nil? #for local builds
        $stdout.puts  'GITHUB_TOKEN missing, running locally'
        default
      else
        client = Octokit::Client.new(:access_token => ENV['GITHUB_TOKEN'])
        $stdout.puts  'Connecting to Github'
        client.user.
        client.default_media_type = "application/vnd.github.moondragon+json"
        release = client.release_for_tag(repo, tag)
        if !release
          default
        else
          release[:prerelease]
        end
      end
    end

  rescue LoadError
    $stdout.puts  'Octokit gem missing, running locally'
    default
  end
end