Class: TerraspaceCiGithub::Vars
- Defined in:
- lib/terraspace_ci_github/vars.rb
Instance Method Summary collapse
- #branch_name ⇒ Object
- #build_id ⇒ Object
- #build_type ⇒ Object
- #build_url ⇒ Object
- #commit_message ⇒ Object
-
#data ⇒ Object
Hash of properties to store.
- #full_repo ⇒ Object
- #host ⇒ Object
-
#pr ⇒ Object
GitHub webhook JSON payload in file and path is set in GITHUB_EVENT_PATH.
- #pr_url ⇒ Object
- #sha ⇒ Object
Methods inherited from Base
Instance Method Details
#branch_name ⇒ Object
66 67 68 69 70 71 72 |
# File 'lib/terraspace_ci_github/vars.rb', line 66 def branch_name if build_type == "pull_request" pr.dig('pull_request','head','ref') else # push ENV['GITHUB_REF_NAME'] end end |
#build_id ⇒ Object
36 37 38 |
# File 'lib/terraspace_ci_github/vars.rb', line 36 def build_id ENV['GITHUB_RUN_ID'] end |
#build_type ⇒ Object
62 63 64 |
# File 'lib/terraspace_ci_github/vars.rb', line 62 def build_type ENV['GITHUB_EVENT_NAME'] end |
#build_url ⇒ Object
32 33 34 |
# File 'lib/terraspace_ci_github/vars.rb', line 32 def build_url "#{host}/#{full_repo}/actions/runs/#{build_id}" end |
#commit_message ⇒ Object
42 43 44 45 46 47 48 |
# File 'lib/terraspace_ci_github/vars.rb', line 42 def return unless github_token? resp = client.commit(full_repo, sha) resp['commit']['message'] rescue Octokit:: => e puts "WARN: #{e.message}. Error getting commit message. Please double check your github token" end |
#data ⇒ Object
Hash of properties to store
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/terraspace_ci_github/vars.rb', line 4 def data { build_system: "github", # required host: host, full_repo: full_repo, branch_name: branch_name, # urls pr_url: pr_url, build_url: build_url, # additional properties build_type: build_type, # required IE: pull_request or push pr_number: pr['number'], # set when build_type=pull_request sha: sha, # additional properties commit_message: , build_id: build_id, build_number: ENV['GITHUB_RUN_NUMBER'], } end |
#full_repo ⇒ Object
50 51 52 |
# File 'lib/terraspace_ci_github/vars.rb', line 50 def full_repo ENV['GITHUB_REPOSITORY'] end |
#host ⇒ Object
24 25 26 |
# File 'lib/terraspace_ci_github/vars.rb', line 24 def host ENV['GITHUB_SERVER_URL'] || 'https://github.com' end |
#pr ⇒ Object
GitHub webhook JSON payload in file and path is set in GITHUB_EVENT_PATH
75 76 77 78 |
# File 'lib/terraspace_ci_github/vars.rb', line 75 def pr return {} unless ENV['GITHUB_EVENT_PATH'] JSON.load(IO.read(ENV['GITHUB_EVENT_PATH'])) end |
#pr_url ⇒ Object
28 29 30 |
# File 'lib/terraspace_ci_github/vars.rb', line 28 def pr_url "#{host}/#{full_repo}/pull/#{pr['number']}" if pr['number'] end |
#sha ⇒ Object
54 55 56 57 58 59 60 |
# File 'lib/terraspace_ci_github/vars.rb', line 54 def sha if build_type == "pull_request" pr.dig('pull_request','head','sha') else # push ENV['GITHUB_SHA'] end end |