Class: Jets::Git::Github

Inherits:
Base
  • Object
show all
Defined in:
lib/jets/git/github.rb

Instance Method Summary collapse

Methods inherited from Base

#base, #params, #user

Instance Method Details

#build_typeObject



44
45
46
# File 'lib/jets/git/github.rb', line 44

def build_type
  ENV["GITHUB_EVENT_NAME"]
end

#git_branchObject



16
17
18
19
20
21
22
# File 'lib/jets/git/github.rb', line 16

def git_branch
  if build_type == "pull_request"
    pr.dig("pull_request", "head", "ref")
  else # push
    ENV["GITHUB_REF_NAME"]
  end
end

#git_shaObject



24
25
26
27
28
29
30
# File 'lib/jets/git/github.rb', line 24

def git_sha
  if build_type == "pull_request"
    pr.dig("pull_request", "head", "sha")
  else # push
    ENV["GITHUB_SHA"]
  end
end

#git_urlObject



32
33
34
35
36
# File 'lib/jets/git/github.rb', line 32

def git_url
  host = ENV["GITHUB_SERVER_URL"] || "https://github.com"
  full_repo = ENV["GITHUB_REPOSITORY"]
  "#{host}/#{full_repo}"
end

#infoObject



3
4
5
6
7
8
9
10
11
12
13
14
# File 'lib/jets/git/github.rb', line 3

def info
  info = {
    git_system: "github",
    git_branch: git_branch,
    git_sha: git_sha,
    git_dirty: false
    # git_message: nil,
    # git_version: nil,
  }
  info[:git_url] = git_url if git_url
  info
end

#prObject

GitHub webhook JSON payload in file and path is set in GITHUB_EVENT_PATH



39
40
41
42
# File 'lib/jets/git/github.rb', line 39

def pr
  return {} unless ENV["GITHUB_EVENT_PATH"]
  JSON.load(IO.read(ENV["GITHUB_EVENT_PATH"]))
end