github_api
Community Action Reference: Inspected directly from Fastlane core ruby gem definitions.
Supported Platforms: ios, android, mac
Call a GitHub API endpoint and get the resulting JSON response
Details
Calls any GitHub API endpoint. You must provide your GitHub Personal token (get one from https://github.com/settings/tokens/new). Out parameters provide the status code and the full response JSON if valid, otherwise the raw response body. Documentation: https://developer.github.com/v3.
Parameters & Options
Total options available: 11
| Key | Type | Env Variable | Default | Required | Description |
|---|---|---|---|---|---|
server_url |
String |
FL_GITHUB_API_SERVER_URL |
https://api.github.com |
No | The server url. e.g. βhttps://your.internal.github.host/api/v3β (Default: βhttps://api.github.comβ) |
api_token |
String |
FL_GITHUB_API_TOKEN |
- |
No | Personal API Token for GitHub - generate one at https://github.com/settings/tokens |
api_bearer |
String |
FL_GITHUB_API_BEARER |
- |
No | Use a Bearer authorization token. Usually generated by GitHub Apps, e.g. GitHub Actions GITHUB_TOKEN environment variable |
http_method |
String |
FL_GITHUB_API_HTTP_METHOD |
GET |
No | The HTTP method. e.g. GET / POST |
body |
String |
FL_GITHUB_API_REQUEST_BODY |
{} |
No | The request body in JSON or hash format |
raw_body |
String |
FL_GITHUB_API_REQUEST_RAW_BODY |
- |
No | The request body taken verbatim instead of as JSON, useful for file uploads |
path |
String |
FL_GITHUB_API_PATH |
- |
No | The endpoint path. e.g. β/repos/:owner/:repo/readmeβ |
url |
String |
FL_GITHUB_API_URL |
- |
No | The complete full url - used instead of path. e.g. βhttps://uploads.github.com/repos/fastlaneβ¦β |
error_handlers |
Hash |
- |
{} |
No | Optional error handling hash based on status code, or pass β*β to handle all errors |
headers |
Hash |
FL_GITHUB_API_HEADERS |
{} |
No | Optional headers to apply |
secure |
Fastlane::Boolean |
FL_GITHUB_API_SECURE |
true |
No | Optionally disable secure requests (ssl_verify_peer) |
Lane Context Shared Values
This action writes the following values to Actions.lane_context[SharedValues::...]:
| Key | Description |
|---|---|
SharedValues::GITHUB_API_STATUS_CODE |
The status code returned from the request |
SharedValues::GITHUB_API_RESPONSE |
The full response body |
SharedValues::GITHUB_API_JSON |
The parsed json returned from GitHub |
Examples
result = github_api( server_url: "https://api.github.com", api_token: ENV["GITHUB_TOKEN"], http_method: "GET", path: "/repos/:owner/:repo/readme", body: { ref: "master" })# Alternatively call directly with optional error handling or block usageGithubApiAction.run( server_url: "https://api.github.com", api_token: ENV["GITHUB_TOKEN"], http_method: "GET", path: "/repos/:owner/:repo/readme", error_handlers: { 404 => proc do |result| UI.message("Something went wrong - I couldn't find it...") end, '*' => proc do |result| UI.message("Handle all error codes other than 404") end }) do |result|UI.message("JSON returned: #{result[:json]}")endSource & Upstream
- Gem Action:
github_api.rb - Upstream Source: Inspect Ruby Implementation on GitHub
- Authors:
tommeier