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



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

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

.branchObject



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

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

.event_nameObject



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

def self.event_name
  ENV['GITHUB_EVENT_NAME']
end

.github_event_dataObject



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

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)


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

def self.is_pull_request?
  event_name == GITHUB_EVENT_PR
end

.is_push?Boolean

Returns:

  • (Boolean)


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

def self.is_push?
  event_name == GITHUB_EVENT_PUSH
end

.is_supported_github_event?Boolean

Returns:

  • (Boolean)


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

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

.pr_numberObject



48
49
50
# File 'lib/fastlane/plugin/emerge/helper/github.rb', line 48

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

.previous_shaObject



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

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

.repo_nameObject



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

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

.repo_ownerObject



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

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

.shaObject



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

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