1 2 3 4 5 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 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82
|
# frozen_string_literal: true
module Octokit
class Client
# Methods for the Deployments API
#
# @see https://developer.github.com/v3/repos/commits/deployments/
module Deployments
# Fetch a single deployment for a repository
#
# @param repo [Integer, String, Repository, Hash] A GitHub repository
# @param deployment_id [Integer, String, Repository, Hash] A GitHub repository
# @return <Sawyer::Resource> A single deployment
# @see https://developer.github.com/v3/repos/deployments/#get-a-single-deployment
def deployment(repo, deployment_id, options = {})
get("#{Repository.path repo}/deployments/#{deployment_id}", options)
end
# List all deployments for a repository
#
# @param repo [Integer, String, Repository, Hash] A GitHub repository
# @return [Array<Sawyer::Resource>] A list of deployments
# @see https://developer.github.com/v3/repos/deployments/#list-deployments
def deployments(repo, options = {})
paginate("#{Repository.path repo}/deployments", options)
end
alias list_deployments deployments
# Create a deployment for a ref
#
# @param repo [Integer, String, Repository, Hash] A GitHub repository
# @param ref [String] The ref to deploy
# @option options [String] :task Used by the deployment system to allow different execution paths. Defaults to "deploy".
# @option options [String] :payload Meta info about the deployment
# @option options [Boolean] :auto_merge Optional parameter to merge the default branch into the requested deployment branch if necessary. Default: true
# @option options [Array<String>] :required_contexts Optional array of status contexts verified against commit status checks.
# @option options [String] :environment Optional name for the target deployment environment (e.g., production, staging, qa). Default: "production"
# @option options [String] :description Optional short description.
# @return [Sawyer::Resource] A deployment
# @see https://developer.github.com/v3/repos/deployments/#create-a-deployment
def create_deployment(repo, ref, options = {})
options[:ref] = ref
post("#{Repository.path repo}/deployments", options)
end
# Delete a Deployment
#
# @param repo [Integer, String, Repository, Hash] A GitHub repository
# @param deployment_id [Integer, String, Repository, Hash] A GitHub repository
# @return [No Content]
# @see https://developer.github.com/v3/repos/deployments/#delete-a-deployment
def delete_deployment(repo, deployment_id, options = {})
delete("#{Repository.path repo}/deployments/#{deployment_id}", options)
end
# List all statuses for a Deployment
#
# @param deployment_url [String] A URL for a deployment resource
# @return [Array<Sawyer::Resource>] A list of deployment statuses
# @see https://developer.github.com/v3/repos/deployments/#list-deployment-statuses
def deployment_statuses(deployment_url, options = {})
deployment = get(deployment_url, accept: options[:accept])
paginate(deployment.rels[:statuses].href, options)
end
alias list_deployment_statuses deployment_statuses
# Create a deployment status for a Deployment
#
# @param deployment_url [String] A URL for a deployment resource
# @param state [String] The state: pending, success, failure, error
# @option options [String] :target_url The target URL to associate with this status. Default: ""
# @option options [String] :description A short description of the status. Maximum length of 140 characters. Default: ""
# @return [Sawyer::Resource] A deployment status
# @see https://developer.github.com/v3/repos/deployments/#create-a-deployment-status
def create_deployment_status(deployment_url, state, options = {})
deployment = get(deployment_url, accept: options[:accept])
options[:state] = state.to_s.downcase
post(deployment.rels[:statuses].href, options)
end
end
end
end
|