Class: Tinybucket::Api::CommitsApi

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

Overview

Commits 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

Returns repository owner name.

Returns:

  • (String)

    repository owner name.



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
83
84
85
86
87
88
89
90
91
92
93
94
95
# File 'lib/tinybucket/api/commits_api.rb', line 11

class CommitsApi < BaseApi
  include Tinybucket::Api::Helper::CommitsHelper

  attr_accessor :repo_owner, :repo_slug

  # Send 'GET a commits list for a repository' request
  #
  # @see https://developer.atlassian.com/bitbucket/api/2/reference/resource/repositories/%7Busername%7D/%7Brepo_slug%7D/commits#get
  #   GET a commits list for a repository
  #
  # @note This method does not support 'compare commits across branches'
  #   API call, yet.
  #
  # @param options [Hash]
  # @return [Tinybucket::Model::Page]
  def list(options = {})
    get_path(
      path_to_list,
      options,
      get_parser(:collection, Tinybucket::Model::Commit)
    )
  end

  # Send 'GET an individual commit' request
  #
  # @see https://developer.atlassian.com/bitbucket/api/2/reference/resource/repositories/%7Busername%7D/%7Brepo_slug%7D/commits/%7Brevision%7D#get
  #   GET an individual commit
  #
  # @param revision [String] A SHA1 value for the commit.
  # @param options [Hash]
  # @return [Tinybucket::Model::Commit]
  def find(revision, options = {})
    get_path(
      path_to_find(revision),
      options,
      get_parser(:object, Tinybucket::Model::Commit)
    )
  end

  # Send 'POST a commit approval' request
  # @see https://developer.atlassian.com/bitbucket/api/2/reference/resource/repositories/%7Busername%7D/%7Brepo_slug%7D/commit/%7Bnode%7D/approve#post
  #   POST a commit approval request
  #
  # @param revision [String]
  # @param options [Hash]
  # @return [true, false]
  def approve(revision, options = {})
    result = post_path(path_to_approve(revision), options)
    (result['approved'] == true)
  rescue Tinybucket::Error::Conflict => e
    logger.debug 'Already approved: ' + e.inspect
    true
  end

  # Send 'DELETE a commit approval' request
  # @see https://developer.atlassian.com/bitbucket/api/2/reference/resource/repositories/%7Busername%7D/%7Brepo_slug%7D/commit/%7Bnode%7D/approve#delete
  #   DELETE a commit approval (unapprove the commit)
  #
  # @param revision [String]
  # @param options [Hash]
  # @return [true, false]
  def unapprove(revision, options = {})
    delete_path(path_to_approve(revision), options)
    true
  rescue Tinybucket::Error::NotFound => e
    logger.debug 'Already unapproved: ' + e.inspect
    true
  end

  # Send 'GET commits for a branch' request
  #
  # @see https://developer.atlassian.com/bitbucket/api/2/reference/resource/repositories/%7Busername%7D/%7Brepo_slug%7D/commits
  #   GET an individual commit
  #
  # @param name [String] The branch name or a SHA1 value for the commit.
  # @param options [Hash]
  # @return [Tinybucket::Model::Commit]
  def branch(name, options = {})
    get_path(
      path_to_branch(name),
      options,
      get_parser(:collection, Tinybucket::Model::Commit)
    )
  end
end

#repo_slugString

Returns repository slug.

Returns:



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
83
84
85
86
87
88
89
90
91
92
93
94
95
# File 'lib/tinybucket/api/commits_api.rb', line 11

class CommitsApi < BaseApi
  include Tinybucket::Api::Helper::CommitsHelper

  attr_accessor :repo_owner, :repo_slug

  # Send 'GET a commits list for a repository' request
  #
  # @see https://developer.atlassian.com/bitbucket/api/2/reference/resource/repositories/%7Busername%7D/%7Brepo_slug%7D/commits#get
  #   GET a commits list for a repository
  #
  # @note This method does not support 'compare commits across branches'
  #   API call, yet.
  #
  # @param options [Hash]
  # @return [Tinybucket::Model::Page]
  def list(options = {})
    get_path(
      path_to_list,
      options,
      get_parser(:collection, Tinybucket::Model::Commit)
    )
  end

  # Send 'GET an individual commit' request
  #
  # @see https://developer.atlassian.com/bitbucket/api/2/reference/resource/repositories/%7Busername%7D/%7Brepo_slug%7D/commits/%7Brevision%7D#get
  #   GET an individual commit
  #
  # @param revision [String] A SHA1 value for the commit.
  # @param options [Hash]
  # @return [Tinybucket::Model::Commit]
  def find(revision, options = {})
    get_path(
      path_to_find(revision),
      options,
      get_parser(:object, Tinybucket::Model::Commit)
    )
  end

  # Send 'POST a commit approval' request
  # @see https://developer.atlassian.com/bitbucket/api/2/reference/resource/repositories/%7Busername%7D/%7Brepo_slug%7D/commit/%7Bnode%7D/approve#post
  #   POST a commit approval request
  #
  # @param revision [String]
  # @param options [Hash]
  # @return [true, false]
  def approve(revision, options = {})
    result = post_path(path_to_approve(revision), options)
    (result['approved'] == true)
  rescue Tinybucket::Error::Conflict => e
    logger.debug 'Already approved: ' + e.inspect
    true
  end

  # Send 'DELETE a commit approval' request
  # @see https://developer.atlassian.com/bitbucket/api/2/reference/resource/repositories/%7Busername%7D/%7Brepo_slug%7D/commit/%7Bnode%7D/approve#delete
  #   DELETE a commit approval (unapprove the commit)
  #
  # @param revision [String]
  # @param options [Hash]
  # @return [true, false]
  def unapprove(revision, options = {})
    delete_path(path_to_approve(revision), options)
    true
  rescue Tinybucket::Error::NotFound => e
    logger.debug 'Already unapproved: ' + e.inspect
    true
  end

  # Send 'GET commits for a branch' request
  #
  # @see https://developer.atlassian.com/bitbucket/api/2/reference/resource/repositories/%7Busername%7D/%7Brepo_slug%7D/commits
  #   GET an individual commit
  #
  # @param name [String] The branch name or a SHA1 value for the commit.
  # @param options [Hash]
  # @return [Tinybucket::Model::Commit]
  def branch(name, options = {})
    get_path(
      path_to_branch(name),
      options,
      get_parser(:collection, Tinybucket::Model::Commit)
    )
  end
end

Instance Method Details

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

Send ‘POST a commit approval’ request

Parameters:

  • revision (String)
  • options (Hash) (defaults to: {})

Returns:

  • (true, false)

See Also:



57
58
59
60
61
62
63
# File 'lib/tinybucket/api/commits_api.rb', line 57

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

#branch(name, options = {}) ⇒ Tinybucket::Model::Commit

Send ‘GET commits for a branch’ request

Parameters:

  • name (String)

    The branch name or a SHA1 value for the commit.

  • options (Hash) (defaults to: {})

Returns:

See Also:



88
89
90
91
92
93
94
# File 'lib/tinybucket/api/commits_api.rb', line 88

def branch(name, options = {})
  get_path(
    path_to_branch(name),
    options,
    get_parser(:collection, Tinybucket::Model::Commit)
  )
end

#find(revision, options = {}) ⇒ Tinybucket::Model::Commit

Send ‘GET an individual commit’ request

Parameters:

  • revision (String)

    A SHA1 value for the commit.

  • options (Hash) (defaults to: {})

Returns:

See Also:



42
43
44
45
46
47
48
# File 'lib/tinybucket/api/commits_api.rb', line 42

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

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

Note:

This method does not support ‘compare commits across branches’ API call, yet.

Send ‘GET a commits list for a repository’ request

Parameters:

  • options (Hash) (defaults to: {})

Returns:

See Also:



26
27
28
29
30
31
32
# File 'lib/tinybucket/api/commits_api.rb', line 26

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

#unapprove(revision, options = {}) ⇒ true, false

Send ‘DELETE a commit approval’ request

Parameters:

  • revision (String)
  • options (Hash) (defaults to: {})

Returns:

  • (true, false)

See Also:



72
73
74
75
76
77
78
# File 'lib/tinybucket/api/commits_api.rb', line 72

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