Module: Fastlane::Helper::Github

Defined in:
lib/fastlane/plugin/emerge/helper/github.rb

Constant Summary collapse

GITHUB_EVENT_PR =
"pull_request".freeze
GITHUB_EVENT_PUSH =
"push".freeze

Class Method Summary collapse

Class Method Details

.base_shaObject



37
38
39
40
41
# File 'lib/fastlane/plugin/emerge/helper/github.rb', line 37

def self.base_sha
  if is_pull_request?
    github_event_data.dig(:pull_request, :base, :sha)
  end
end

.branchObject



55
56
57
# File 'lib/fastlane/plugin/emerge/helper/github.rb', line 55

def self.branch
  is_pull_request? ? github_event_data.dig(:pull_request, :head, :ref) : Git.branch
end

.event_nameObject



12
13
14
# File 'lib/fastlane/plugin/emerge/helper/github.rb', line 12

def self.event_name
  ENV['GITHUB_EVENT_NAME']
end

.github_event_dataObject



69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/fastlane/plugin/emerge/helper/github.rb', line 69

def self.github_event_data
  github_event_path = ENV['GITHUB_EVENT_PATH']
  UI.error!("GITHUB_EVENT_PATH is not set") if github_event_path.nil?

  unless File.exist?(github_event_path)
    UI.error!("File #{github_event_path} doesn't exist")
  end

  file_content = File.read(github_event_path)
  file_json = JSON.parse(file_content, symbolize_names: true)
  if ENV['DEBUG']
    UI.message("Parsed GitHub event data: #{file_json.inspect}")
  end
  file_json
end

.is_pull_request?Boolean

Returns:

  • (Boolean)


21
22
23
# File 'lib/fastlane/plugin/emerge/helper/github.rb', line 21

def self.is_pull_request?
  event_name == GITHUB_EVENT_PR
end

.is_push?Boolean

Returns:

  • (Boolean)


25
26
27
# File 'lib/fastlane/plugin/emerge/helper/github.rb', line 25

def self.is_push?
  event_name == GITHUB_EVENT_PUSH
end

.is_supported_github_event?Boolean

Returns:

  • (Boolean)


16
17
18
19
# File 'lib/fastlane/plugin/emerge/helper/github.rb', line 16

def self.is_supported_github_event?
  UI.message("GitHub event name: #{event_name}")
  is_pull_request? || is_push?
end

.pr_numberObject



51
52
53
# File 'lib/fastlane/plugin/emerge/helper/github.rb', line 51

def self.pr_number
  is_pull_request? ? github_event_data.dig(:number) : nil
end

.previous_shaObject



43
44
45
46
47
48
49
# File 'lib/fastlane/plugin/emerge/helper/github.rb', line 43

def self.previous_sha
  if is_push?
    github_event_data.dig(:before)
  else
    github_event_data.dig(:before) || self.base_sha
  end
end

.repo_nameObject



63
64
65
# File 'lib/fastlane/plugin/emerge/helper/github.rb', line 63

def self.repo_name
  github_event_data.dig(:repository, :full_name)
end

.repo_ownerObject



59
60
61
# File 'lib/fastlane/plugin/emerge/helper/github.rb', line 59

def self.repo_owner
  github_event_data.dig(:repository, :owner, :login)
end

.shaObject



29
30
31
32
33
34
35
# File 'lib/fastlane/plugin/emerge/helper/github.rb', line 29

def self.sha
  if is_push?
    ENV['GITHUB_SHA']
  elsif is_pull_request?
    github_event_data.dig(:pull_request, :head, :sha)
  end
end