Class: Tinybucket::Api::PullRequestsApi

Inherits:
BaseApi
  • Object
show all
Includes:
Helper::PullRequestsHelper
Defined in:
lib/tinybucket/api/pull_requests_api.rb

Overview

PullRequests Api client

Constant Summary

Constants included from Connection

Connection::DEFAULT_USER_AGENT

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Connection

#caching?, #clear_cache, #connection

Instance Attribute Details

#repo_ownerString



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
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
# File 'lib/tinybucket/api/pull_requests_api.rb', line 14

class PullRequestsApi < BaseApi
  include Tinybucket::Api::Helper::PullRequestsHelper

  attr_accessor :repo_owner, :repo_slug

  # Send 'GET a list of open pull requests' request
  #
  # @param options [Hash]
  # @return [Tinybucket::Model::Page]
  def list(options = {})
    get_path(
      path_to_list,
      options,
      get_parser(:collection, Tinybucket::Model::PullRequest)
    )
  end

  # Send 'GET a specific pull request' request
  #
  # @param pr_id [String] The pull request identifier
  # @param options [Hash]
  # @return [Tinybucket::Model::PullRequest]
  def find(pr_id, options = {})
    get_path(
      path_to_find(pr_id),
      options,
      get_parser(:object, Tinybucket::Model::PullRequest)
    )
  end

  # Send 'GET the commits for a pull request' request
  #
  # @param pr_id [String] The pull request identifier
  # @param options [Hash]
  # @return [Tinybucket::Model::PullRequest]
  def commits(pr_id, options = {})
    get_path(
      path_to_commits(pr_id),
      options,
      get_parser(:collection, Tinybucket::Model::Commit)
    )
  end

  # Send 'POST a pull request approval' request
  #
  # @note This method return true if this pull request already approved.
  #
  # @param pr_id [String] The pull request identifier
  # @param options [Hash]
  # @return [true, false]
  def approve(pr_id, options = {})
    result = post_path(path_to_approve(pr_id), options)
    (result['approved'] == true)
  rescue Tinybucket::Error::Conflict => e
    logger.debug 'Already approved: ' + e.inspect
    true
  end

  # Send 'DELETE a pull request approval' request
  #
  # @note This method return true if this pull request is not approved yet.
  #
  # @param pr_id [String] The pull request identifier
  # @param options [Hash]
  # @return [true]
  def unapprove(pr_id, options = {})
    delete_path(path_to_approve(pr_id), options)
    true
  rescue Tinybucket::Error::NotFound => e
    logger.debug 'Already unapproved: ' + e.inspect
    true
  end

  # Send 'Decline or reject a pull request' request
  #
  # @param pr_id [String] The pull request identifier
  # @param options [Hash]
  # @return [true, false]
  def decline(pr_id, options = {})
    result = post_path(path_to_decline(pr_id), options)
    (result['state'] == 'DECLINED')
  end

  # Send 'Accept and merge a pull request' request
  #
  # @param pr_id [String] The pull request identifier
  # @param options [Hash]
  # @return [true, false]
  def merge(pr_id, options = {})
    result = post_path(path_to_merge(pr_id), options)
    (result['state'] == 'MERGED')
  end

  # Send 'GET the diff for a pull request' request
  #
  # @param pr_id [String] The pull request identifier
  # @param options [Hash]
  # @return [String] diff as raw text.
  def diff(pr_id, options = {})
    get_path(path_to_diff(pr_id), options)
  end
end

#repo_slugString



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
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
# File 'lib/tinybucket/api/pull_requests_api.rb', line 14

class PullRequestsApi < BaseApi
  include Tinybucket::Api::Helper::PullRequestsHelper

  attr_accessor :repo_owner, :repo_slug

  # Send 'GET a list of open pull requests' request
  #
  # @param options [Hash]
  # @return [Tinybucket::Model::Page]
  def list(options = {})
    get_path(
      path_to_list,
      options,
      get_parser(:collection, Tinybucket::Model::PullRequest)
    )
  end

  # Send 'GET a specific pull request' request
  #
  # @param pr_id [String] The pull request identifier
  # @param options [Hash]
  # @return [Tinybucket::Model::PullRequest]
  def find(pr_id, options = {})
    get_path(
      path_to_find(pr_id),
      options,
      get_parser(:object, Tinybucket::Model::PullRequest)
    )
  end

  # Send 'GET the commits for a pull request' request
  #
  # @param pr_id [String] The pull request identifier
  # @param options [Hash]
  # @return [Tinybucket::Model::PullRequest]
  def commits(pr_id, options = {})
    get_path(
      path_to_commits(pr_id),
      options,
      get_parser(:collection, Tinybucket::Model::Commit)
    )
  end

  # Send 'POST a pull request approval' request
  #
  # @note This method return true if this pull request already approved.
  #
  # @param pr_id [String] The pull request identifier
  # @param options [Hash]
  # @return [true, false]
  def approve(pr_id, options = {})
    result = post_path(path_to_approve(pr_id), options)
    (result['approved'] == true)
  rescue Tinybucket::Error::Conflict => e
    logger.debug 'Already approved: ' + e.inspect
    true
  end

  # Send 'DELETE a pull request approval' request
  #
  # @note This method return true if this pull request is not approved yet.
  #
  # @param pr_id [String] The pull request identifier
  # @param options [Hash]
  # @return [true]
  def unapprove(pr_id, options = {})
    delete_path(path_to_approve(pr_id), options)
    true
  rescue Tinybucket::Error::NotFound => e
    logger.debug 'Already unapproved: ' + e.inspect
    true
  end

  # Send 'Decline or reject a pull request' request
  #
  # @param pr_id [String] The pull request identifier
  # @param options [Hash]
  # @return [true, false]
  def decline(pr_id, options = {})
    result = post_path(path_to_decline(pr_id), options)
    (result['state'] == 'DECLINED')
  end

  # Send 'Accept and merge a pull request' request
  #
  # @param pr_id [String] The pull request identifier
  # @param options [Hash]
  # @return [true, false]
  def merge(pr_id, options = {})
    result = post_path(path_to_merge(pr_id), options)
    (result['state'] == 'MERGED')
  end

  # Send 'GET the diff for a pull request' request
  #
  # @param pr_id [String] The pull request identifier
  # @param options [Hash]
  # @return [String] diff as raw text.
  def diff(pr_id, options = {})
    get_path(path_to_diff(pr_id), options)
  end
end

Instance Method Details

#approve(pr_id, options = {}) ⇒ true, false

Note:

This method return true if this pull request already approved.

Send 'POST a pull request approval' request



64
65
66
67
68
69
70
# File 'lib/tinybucket/api/pull_requests_api.rb', line 64

def approve(pr_id, options = {})
  result = post_path(path_to_approve(pr_id), options)
  (result['approved'] == true)
rescue Tinybucket::Error::Conflict => e
  logger.debug 'Already approved: ' + e.inspect
  true
end

#commits(pr_id, options = {}) ⇒ Tinybucket::Model::PullRequest

Send 'GET the commits for a pull request' request



49
50
51
52
53
54
55
# File 'lib/tinybucket/api/pull_requests_api.rb', line 49

def commits(pr_id, options = {})
  get_path(
    path_to_commits(pr_id),
    options,
    get_parser(:collection, Tinybucket::Model::Commit)
  )
end

#decline(pr_id, options = {}) ⇒ true, false

Send 'Decline or reject a pull request' request



92
93
94
95
# File 'lib/tinybucket/api/pull_requests_api.rb', line 92

def decline(pr_id, options = {})
  result = post_path(path_to_decline(pr_id), options)
  (result['state'] == 'DECLINED')
end

#diff(pr_id, options = {}) ⇒ String

Send 'GET the diff for a pull request' request



112
113
114
# File 'lib/tinybucket/api/pull_requests_api.rb', line 112

def diff(pr_id, options = {})
  get_path(path_to_diff(pr_id), options)
end

#find(pr_id, options = {}) ⇒ Tinybucket::Model::PullRequest

Send 'GET a specific pull request' request



36
37
38
39
40
41
42
# File 'lib/tinybucket/api/pull_requests_api.rb', line 36

def find(pr_id, options = {})
  get_path(
    path_to_find(pr_id),
    options,
    get_parser(:object, Tinybucket::Model::PullRequest)
  )
end

#list(options = {}) ⇒ Tinybucket::Model::Page

Send 'GET a list of open pull requests' request



23
24
25
26
27
28
29
# File 'lib/tinybucket/api/pull_requests_api.rb', line 23

def list(options = {})
  get_path(
    path_to_list,
    options,
    get_parser(:collection, Tinybucket::Model::PullRequest)
  )
end

#merge(pr_id, options = {}) ⇒ true, false

Send 'Accept and merge a pull request' request



102
103
104
105
# File 'lib/tinybucket/api/pull_requests_api.rb', line 102

def merge(pr_id, options = {})
  result = post_path(path_to_merge(pr_id), options)
  (result['state'] == 'MERGED')
end

#unapprove(pr_id, options = {}) ⇒ true

Note:

This method return true if this pull request is not approved yet.

Send 'DELETE a pull request approval' request



79
80
81
82
83
84
85
# File 'lib/tinybucket/api/pull_requests_api.rb', line 79

def unapprove(pr_id, options = {})
  delete_path(path_to_approve(pr_id), options)
  true
rescue Tinybucket::Error::NotFound => e
  logger.debug 'Already unapproved: ' + e.inspect
  true
end