Class: Capistrano::Committed::GithubApi
- Inherits:
-
Object
- Object
- Capistrano::Committed::GithubApi
- Defined in:
- lib/capistrano/committed/github_api.rb
Instance Method Summary collapse
- #client ⇒ Object
- #get_commit(user, repo, sha) ⇒ Object
- #get_commits_since(user, repo, date, branch = 'master') ⇒ Object
- #get_pull_request(user, repo, number) ⇒ Object
-
#initialize(config_options = {}) ⇒ GithubApi
constructor
A new instance of GithubApi.
- #register_deployment(user, repo, stage, branch = 'master') ⇒ Object
- #register_deployment_status(user, repo, id, state) ⇒ Object
Constructor Details
#initialize(config_options = {}) ⇒ GithubApi
Returns a new instance of GithubApi.
6 7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/capistrano/committed/github_api.rb', line 6 def initialize( = {}) validate('config_options', , Hash, __callee__) = { adapter: :net_http, ssl: { verify: false }, per_page: 100, user_agent: 'Committed Ruby Gem (via Github API Ruby Gem)' } .merge! @client = ::Github.new end |
Instance Method Details
#client ⇒ Object
19 20 21 |
# File 'lib/capistrano/committed/github_api.rb', line 19 def client @client end |
#get_commit(user, repo, sha) ⇒ Object
23 24 25 26 27 28 29 30 31 32 |
# File 'lib/capistrano/committed/github_api.rb', line 23 def get_commit(user, repo, sha) validate_user_and_repo(user, repo, __callee__) validate('sha', sha, String, __callee__) api_call do @client.repos.commits.get(user: user, repo: repo, sha: sha) end end |
#get_commits_since(user, repo, date, branch = 'master') ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/capistrano/committed/github_api.rb', line 34 def get_commits_since(user, repo, date, branch = 'master') validate_user_and_repo(user, repo, __callee__) date = Time.parse(date) if date.is_a?(String) validate('date', date, Time, __callee__) validate('branch', branch, String, __callee__) api_call do @client.repos.commits.list(user: user, repo: repo, sha: branch, since: date.iso8601) end end |
#get_pull_request(user, repo, number) ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/capistrano/committed/github_api.rb', line 48 def get_pull_request(user, repo, number) validate_user_and_repo(user, repo, __callee__) validate('number', number, Integer, __callee__) api_call do info = @client.pull_requests.get(user: user, repo: repo, number: number) commits = @client.pull_requests.commits(user: user, repo: repo, number: number) return { info: info, commits: commits } end end |
#register_deployment(user, repo, stage, branch = 'master') ⇒ Object
65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/capistrano/committed/github_api.rb', line 65 def register_deployment(user, repo, stage, branch = 'master') validate_user_and_repo(user, repo, __callee__) validate('stage', stage, String, __callee__) validate('branch', branch, String, __callee__) api_call do @client.repos.deployments.create(user: user, repo: repo, environment: stage, ref: branch, auto_merge: false, required_contexts: []) end end |
#register_deployment_status(user, repo, id, state) ⇒ Object
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/capistrano/committed/github_api.rb', line 80 def register_deployment_status(user, repo, id, state) validate_user_and_repo(user, repo, __callee__) validate('id', id, Integer, __callee__) valid_states = %w(pending success error failure) state = state.to_s unless valid_states.include?(state) = t('committed.error.helpers.valid_param', method: __callee__, param: 'state') fail TypeError, end api_call do @client.repos.deployments.create_status(user: user, repo: repo, id: id, state: state) end end |