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



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

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



60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/fastlane/plugin/emerge/helper/github.rb', line 60

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



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

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

.repo_nameObject



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

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

.repo_ownerObject



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

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