Class: Fastlane::Actions::GithubJobStatusAction
- Inherits:
-
Action
- Object
- Action
- Fastlane::Actions::GithubJobStatusAction
- Defined in:
- lib/fastlane/plugin/github_job_status/actions/github_job_status_action.rb
Class Method Summary collapse
- .authors ⇒ Object
- .available_options ⇒ Object
- .description ⇒ Object
- .description_for_state(state) ⇒ Object
- .details ⇒ Object
- .is_supported?(platform) ⇒ Boolean
- .post(url, payload, headers) ⇒ Object
- .return_value ⇒ Object
- .run(params) ⇒ Object
Class Method Details
.authors ⇒ Object
58 59 60 |
# File 'lib/fastlane/plugin/github_job_status/actions/github_job_status_action.rb', line 58 def self. ["Justin Singer"] end |
.available_options ⇒ Object
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 |
# File 'lib/fastlane/plugin/github_job_status/actions/github_job_status_action.rb', line 70 def self. [ FastlaneCore::ConfigItem.new( key: :token, env_name: 'GITHUB_JOB_STATUS_TOKEN', description: 'OAuth token for :owner GitHub account', verify_block: proc { |value| UI.user_error! "Token must be specified" if value.empty? } ), FastlaneCore::ConfigItem.new( key: :owner, env_name: 'GITHUB_JOB_STATUS_OWNER', description: 'The github owner or username', verify_block: proc { |value| UI.user_error! "Owner must be specified" if value.empty? } ), FastlaneCore::ConfigItem.new( key: :repo, env_name: 'GITHUB_JOB_STATUS_REPO', description: 'The github repo', verify_block: proc { |value| UI.user_error! "Repo must be specified" if value.empty? } ), FastlaneCore::ConfigItem.new( key: :sha, env_name: 'GITHUB_JOB_STATUS_SHA', description: 'The github sha of the commit', optional: true ), FastlaneCore::ConfigItem.new( key: :job_name, env_name: 'GITHUB_JOB_STATUS_JOB_NAME', description: 'The string displayed next to the status indicator but before the description', optional: true ), FastlaneCore::ConfigItem.new( key: :description, env_name: 'GITHUB_JOB_STATUS_DESCRIPTION', description: 'The string displayed after job name', optional: true ), FastlaneCore::ConfigItem.new( key: :build_url, env_name: 'GITHUB_JOB_STATUS_BUILD_URL', description: 'The url of the build upon which we are reporting the status', optional: true ), FastlaneCore::ConfigItem.new( key: :state, env_name: 'GITHUB_JOB_STATUS_STATE', description: 'The state of a build; must be pending, success, error, or failure', verify_block: proc do |value| unless ['pending', 'success', 'error', 'failure'].include?(value) UI.user_error! "Invalid state '#{value}' given. State must be pending, success, error, or failure." end end ) ] end |
.description ⇒ Object
54 55 56 |
# File 'lib/fastlane/plugin/github_job_status/actions/github_job_status_action.rb', line 54 def self.description "Post the status of your test jobs to your pull requests" end |
.description_for_state(state) ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/fastlane/plugin/github_job_status/actions/github_job_status_action.rb', line 41 def self.description_for_state(state) case state when 'pending' 'Job pending' when 'success' 'Job succeeded' when 'error' 'Job failed' when 'failure' 'Job unstable' end end |
.details ⇒ Object
66 67 68 |
# File 'lib/fastlane/plugin/github_job_status/actions/github_job_status_action.rb', line 66 def self.details "Uses github's status API (https://developer.github.com/v3/repos/statuses/) to display the status of continuous integration jobs directly on pull requests." end |
.is_supported?(platform) ⇒ Boolean
127 128 129 |
# File 'lib/fastlane/plugin/github_job_status/actions/github_job_status_action.rb', line 127 def self.is_supported?(platform) true end |
.post(url, payload, headers) ⇒ Object
37 38 39 |
# File 'lib/fastlane/plugin/github_job_status/actions/github_job_status_action.rb', line 37 def self.post(url, payload, headers) RestClient.post(url, payload, headers) end |
.return_value ⇒ Object
62 63 64 |
# File 'lib/fastlane/plugin/github_job_status/actions/github_job_status_action.rb', line 62 def self.return_value "True if status posted sucessfully, False otherwise" end |
.run(params) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/fastlane/plugin/github_job_status/actions/github_job_status_action.rb', line 6 def self.run(params) api = "https://api.github.com/repos" # if sha not provided then use last_commit sha = !params[:sha] ? Fastlane::Actions.last_git_commit_dict[:commit_hash] : params[:sha] url = "#{api}/#{params[:owner]}/#{params[:repo]}/statuses/#{sha}" headers = { 'Authorization' => "token #{params[:token]}", 'User-Agent' => 'fastlane', 'content_type' => :json, 'accept' => :json } payload = { state: params[:state], description: !params[:description] ? description_for_state(params[:state]) : params[:description] } context = params[:job_name] payload['context'] = context unless context.nil? target_url = params[:build_url] payload['target_url'] = target_url unless target_url.nil? begin post(url, payload.to_json, headers) true rescue RestClient::ExceptionWithResponse => e UI.error "Status failed to post to GitHub. Recieved the following response from the server: #{e.response}" false end end |