Module: EmergeCLI::Github
- Defined in:
- lib/utils/github.rb
Constant Summary collapse
- GITHUB_EVENT_PR =
'pull_request'.freeze
- GITHUB_EVENT_PUSH =
'push'.freeze
Class Method Summary collapse
- .base_sha ⇒ Object
- .branch ⇒ Object
- .event_name ⇒ Object
- .github_event_data ⇒ Object
- .pr_number ⇒ Object
- .previous_sha ⇒ Object
- .pull_request? ⇒ Boolean
- .push? ⇒ Boolean
- .repo_name ⇒ Object
- .repo_owner ⇒ Object
- .sha ⇒ Object
- .supported_github_event? ⇒ Boolean
Class Method Details
.base_sha ⇒ Object
31 32 33 34 |
# File 'lib/utils/github.rb', line 31 def self.base_sha return unless pull_request? github_event_data.dig(:pull_request, :base, :sha) end |
.branch ⇒ Object
40 41 42 |
# File 'lib/utils/github.rb', line 40 def self.branch pull_request? ? github_event_data.dig(:pull_request, :head, :ref) : Git.branch end |
.event_name ⇒ Object
6 7 8 |
# File 'lib/utils/github.rb', line 6 def self.event_name ENV.fetch('GITHUB_EVENT_NAME', nil) end |
.github_event_data ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/utils/github.rb', line 56 def self.github_event_data @github_event_data ||= begin github_event_path = ENV.fetch('GITHUB_EVENT_PATH', nil) Logger.error 'GITHUB_EVENT_PATH is not set' if github_event_path.nil? Logger.error "File #{github_event_path} doesn't exist" unless File.exist?(github_event_path) file_content = File.read(github_event_path) file_json = JSON.parse(file_content, symbolize_names: true) Logger.debug "Parsed GitHub event data: #{file_json.inspect}" file_json end end |
.pr_number ⇒ Object
36 37 38 |
# File 'lib/utils/github.rb', line 36 def self.pr_number pull_request? ? github_event_data[:number] : nil end |
.previous_sha ⇒ Object
52 53 54 |
# File 'lib/utils/github.rb', line 52 def self.previous_sha Git.previous_sha end |
.pull_request? ⇒ Boolean
15 16 17 |
# File 'lib/utils/github.rb', line 15 def self.pull_request? event_name == GITHUB_EVENT_PR end |
.push? ⇒ Boolean
19 20 21 |
# File 'lib/utils/github.rb', line 19 def self.push? event_name == GITHUB_EVENT_PUSH end |
.repo_name ⇒ Object
48 49 50 |
# File 'lib/utils/github.rb', line 48 def self.repo_name github_event_data.dig(:repository, :full_name) end |
.repo_owner ⇒ Object
44 45 46 |
# File 'lib/utils/github.rb', line 44 def self.repo_owner github_event_data.dig(:repository, :owner, :login) end |
.sha ⇒ Object
23 24 25 26 27 28 29 |
# File 'lib/utils/github.rb', line 23 def self.sha if push? ENV.fetch('GITHUB_SHA', nil) elsif pull_request? github_event_data.dig(:pull_request, :head, :sha) end end |