-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #144 from VitorHP/tags-api
Implemented Tags API based on the current Branches API
- Loading branch information
Showing
17 changed files
with
901 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,7 @@ module Api | |
[ | ||
:BaseApi, | ||
:BranchesApi, | ||
:TagsApi, | ||
:BranchRestrictionsApi, | ||
:BuildStatusApi, | ||
:CommitsApi, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
module Tinybucket | ||
module Api | ||
module Helper | ||
module TagsHelper | ||
include ::Tinybucket::Api::Helper::ApiHelper | ||
|
||
private | ||
|
||
def path_to_list | ||
build_path(base_path) | ||
end | ||
|
||
def path_to_find(tag) | ||
build_path(base_path, | ||
[tag, 'tag']) | ||
end | ||
|
||
def base_path | ||
build_path('/repositories', | ||
[repo_owner, 'repo_owner'], | ||
[repo_slug, 'repo_slug'], | ||
'refs', 'tags') | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
# frozen_string_literal: true | ||
|
||
module Tinybucket | ||
module Api | ||
# Tags Api client | ||
# | ||
# @!attribute [rw] repo_owner | ||
# @return [String] repository owner name. | ||
# @!attribute [rw] repo_slug | ||
# @return [String] {https://developer.atlassian.com/bitbucket/api/2/reference/resource/repositories/%7Busername%7D/%7Brepo_slug%7D repo_slug}. | ||
class TagsApi < BaseApi | ||
include Tinybucket::Api::Helper::TagsHelper | ||
|
||
attr_accessor :repo_owner, :repo_slug | ||
|
||
# Send 'GET a tags list for a repository' request | ||
# | ||
# @see https://developer.atlassian.com/bitbucket/api/2/reference/resource/repositories/%7Busername%7D/%7Brepo_slug%7D/refs/tags#get | ||
# GET a tags list for a repository | ||
# | ||
# @param options [Hash] | ||
# @return [Tinybucket::Model::Page] | ||
def list(options = {}) | ||
get_path( | ||
path_to_list, | ||
options, | ||
get_parser(:collection, Tinybucket::Model::Tag) | ||
) | ||
end | ||
|
||
# Send 'GET an individual tag' request | ||
# | ||
# @see https://developer.atlassian.com/bitbucket/api/2/reference/resource/repositories/%7Busername%7D/%7Brepo_slug%7D/refs/tags/%7Bname%7D#get | ||
# GET an individual tag | ||
# | ||
# @param name [String] The tag name | ||
# @param options [Hash] | ||
# @return [Tinybucket::Model::Tag] | ||
def find(name, options = {}) | ||
get_path( | ||
path_to_find(name), | ||
options, | ||
get_parser(:object, Tinybucket::Model::Tag) | ||
) | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
# frozen_string_literal: true | ||
|
||
module Tinybucket | ||
module Model | ||
# Tag | ||
# | ||
# @see https://developer.atlassian.com/bitbucket/api/2/reference/resource/repositories/%7Busername%7D/%7Brepo_slug%7D/refs/tags | ||
# Tag Resource | ||
# | ||
# @!attribute [rw] links | ||
# @return [Hash] | ||
# @!attribute [rw] type | ||
# @return [String] | ||
# @!attribute [rw] name | ||
# @return [String] | ||
# @!attribute [rw] repository | ||
# @return [Hash] | ||
# @!attribute [rw] target | ||
# @return [Hash] | ||
class Tag < Base | ||
include Tinybucket::Model::Concerns::RepositoryKeys | ||
|
||
acceptable_attributes :links, :type, :name, :repository, :target, :tagger, :date, :message | ||
|
||
# Returns the commits available for the specific tag | ||
# | ||
# @param options [Hash] | ||
# @return [Tinybucket::Resource::Commits] | ||
def commits(options = {}) | ||
commits_resource.tag(name, options) | ||
end | ||
|
||
private | ||
|
||
def commits_resource(options = {}) | ||
Tinybucket::Resource::Commits.new(self, options) | ||
end | ||
|
||
def tags_api | ||
create_api('Tags', repo_keys) | ||
end | ||
|
||
def load_model | ||
tags_api.find(name, {}) | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
# frozen_string_literal: true | ||
|
||
module Tinybucket | ||
module Resource | ||
class Tags < Tinybucket::Resource::Base | ||
def initialize(repo, options) | ||
@repo = repo | ||
@args = [options] | ||
end | ||
|
||
# Find the tag | ||
# | ||
# @param tag [String] | ||
# @param options [Hash] | ||
# @return [Tinybucket::Model::Tag] | ||
def find(tag, options = {}) | ||
tags_api.find(tag, options).tap do |m| | ||
inject_repo_keys(m, @repo.repo_keys) | ||
end | ||
end | ||
|
||
private | ||
|
||
def tags_api | ||
create_api('Tags', @repo.repo_keys) | ||
end | ||
|
||
def enumerator | ||
create_enumerator(tags_api, :list, *@args) do |m| | ||
inject_repo_keys(m, @repo.repo_keys) | ||
end | ||
end | ||
end | ||
end | ||
end |
Oops, something went wrong.