Commit 5cbbc607 authored by Johan Brandhorst's avatar Johan Brandhorst Committed by Sander van Harmelen

Update BranchesService Methods to Conform to v4 API (#157)

* CI: always test on the latest bugfix Go releases (#154)

* Remove unnecessary fmt.Sprintf call (#153)

* Fix typo in user 404 error (#155)

* Update BranchesService Methods.

This change breaks backwards compatibility.

The BranchesService methods were almost all inconsistent with other Services and not supplying all available options. Also updated all documentation links.

The Branch struct now includes all properties exported by the v3 API.
ListBranches takes a new ListBranchesOptions struct for pagination.
Added the ability to configure the branch protection in line with API documentation.
Added a new DeleteMergedBranches which is part of the branches page.

* Restore API doc links
parent 1c2ae800
...@@ -24,16 +24,14 @@ import ( ...@@ -24,16 +24,14 @@ import (
// BranchesService handles communication with the branch related methods // BranchesService handles communication with the branch related methods
// of the GitLab API. // of the GitLab API.
// //
// GitLab API docs: // GitLab API docs: https://docs.gitlab.com/ce/api/branches.html
// https://gitlab.com/gitlab-org/gitlab-ce/blob/8-16-stable/doc/api/branches.md
type BranchesService struct { type BranchesService struct {
client *Client client *Client
} }
// Branch represents a GitLab branch. // Branch represents a GitLab branch.
// //
// GitLab API docs: // GitLab API docs: https://docs.gitlab.com/ce/api/branches.html
// https://gitlab.com/gitlab-org/gitlab-ce/blob/8-16-stable/doc/api/branches.md
type Branch struct { type Branch struct {
Commit *Commit `json:"commit"` Commit *Commit `json:"commit"`
Name string `json:"name"` Name string `json:"name"`
...@@ -50,7 +48,7 @@ func (b Branch) String() string { ...@@ -50,7 +48,7 @@ func (b Branch) String() string {
// ListBranchesOptions represents the available ListBranches() options. // ListBranchesOptions represents the available ListBranches() options.
// //
// GitLab API docs: // GitLab API docs:
// https://gitlab.com/gitlab-org/gitlab-ce/blob/8-16-stable/doc/api/branches.md#list-repository-branches // https://docs.gitlab.com/ce/api/branches.html#list-repository-branches
type ListBranchesOptions struct { type ListBranchesOptions struct {
ListOptions ListOptions
} }
...@@ -59,7 +57,7 @@ type ListBranchesOptions struct { ...@@ -59,7 +57,7 @@ type ListBranchesOptions struct {
// name alphabetically. // name alphabetically.
// //
// GitLab API docs: // GitLab API docs:
// https://gitlab.com/gitlab-org/gitlab-ce/blob/8-16-stable/doc/api/branches.md#list-repository-branches // https://docs.gitlab.com/ce/api/branches.html#list-repository-branches
func (s *BranchesService) ListBranches(pid interface{}, opts *ListBranchesOptions, options ...OptionFunc) ([]*Branch, *Response, error) { func (s *BranchesService) ListBranches(pid interface{}, opts *ListBranchesOptions, options ...OptionFunc) ([]*Branch, *Response, error) {
project, err := parseID(pid) project, err := parseID(pid)
if err != nil { if err != nil {
...@@ -84,7 +82,7 @@ func (s *BranchesService) ListBranches(pid interface{}, opts *ListBranchesOption ...@@ -84,7 +82,7 @@ func (s *BranchesService) ListBranches(pid interface{}, opts *ListBranchesOption
// GetBranch gets a single project repository branch. // GetBranch gets a single project repository branch.
// //
// GitLab API docs: // GitLab API docs:
// https://gitlab.com/gitlab-org/gitlab-ce/blob/8-16-stable/doc/api/branches.md#get-single-repository-branch // https://docs.gitlab.com/ce/api/branches.html#get-single-repository-branch
func (s *BranchesService) GetBranch(pid interface{}, branch string, options ...OptionFunc) (*Branch, *Response, error) { func (s *BranchesService) GetBranch(pid interface{}, branch string, options ...OptionFunc) (*Branch, *Response, error) {
project, err := parseID(pid) project, err := parseID(pid)
if err != nil { if err != nil {
...@@ -109,7 +107,7 @@ func (s *BranchesService) GetBranch(pid interface{}, branch string, options ...O ...@@ -109,7 +107,7 @@ func (s *BranchesService) GetBranch(pid interface{}, branch string, options ...O
// ProtectBranchOptions represents the available ProtectBranch() options. // ProtectBranchOptions represents the available ProtectBranch() options.
// //
// GitLab API docs: // GitLab API docs:
// https://gitlab.com/gitlab-org/gitlab-ce/blob/8-16-stable/doc/api/branches.md#protect-repository-branch // https://docs.gitlab.com/ce/api/branches.html#protect-repository-branch
type ProtectBranchOptions struct { type ProtectBranchOptions struct {
DevelopersCanPush *bool `url:"developers_can_push,omitempty" json:"developers_can_push,omitempty"` DevelopersCanPush *bool `url:"developers_can_push,omitempty" json:"developers_can_push,omitempty"`
DevelopersCanMerge *bool `url:"developers_can_merge,omitempty" json:"developers_can_merge,omitempty"` DevelopersCanMerge *bool `url:"developers_can_merge,omitempty" json:"developers_can_merge,omitempty"`
...@@ -120,7 +118,7 @@ type ProtectBranchOptions struct { ...@@ -120,7 +118,7 @@ type ProtectBranchOptions struct {
// still returns a 200 OK status code. // still returns a 200 OK status code.
// //
// GitLab API docs: // GitLab API docs:
// https://gitlab.com/gitlab-org/gitlab-ce/blob/8-16-stable/doc/api/branches.md#protect-repository-branch // https://docs.gitlab.com/ce/api/branches.html#protect-repository-branch
func (s *BranchesService) ProtectBranch(pid interface{}, branch string, opts *ProtectBranchOptions, options ...OptionFunc) (*Branch, *Response, error) { func (s *BranchesService) ProtectBranch(pid interface{}, branch string, opts *ProtectBranchOptions, options ...OptionFunc) (*Branch, *Response, error) {
project, err := parseID(pid) project, err := parseID(pid)
if err != nil { if err != nil {
...@@ -147,7 +145,7 @@ func (s *BranchesService) ProtectBranch(pid interface{}, branch string, opts *Pr ...@@ -147,7 +145,7 @@ func (s *BranchesService) ProtectBranch(pid interface{}, branch string, opts *Pr
// still returns a 200 OK status code. // still returns a 200 OK status code.
// //
// GitLab API docs: // GitLab API docs:
// https://gitlab.com/gitlab-org/gitlab-ce/blob/8-16-stable/doc/api/branches.md#unprotect-repository-branch // https://docs.gitlab.com/ce/api/branches.html#unprotect-repository-branch
func (s *BranchesService) UnprotectBranch(pid interface{}, branch string, options ...OptionFunc) (*Branch, *Response, error) { func (s *BranchesService) UnprotectBranch(pid interface{}, branch string, options ...OptionFunc) (*Branch, *Response, error) {
project, err := parseID(pid) project, err := parseID(pid)
if err != nil { if err != nil {
...@@ -172,7 +170,7 @@ func (s *BranchesService) UnprotectBranch(pid interface{}, branch string, option ...@@ -172,7 +170,7 @@ func (s *BranchesService) UnprotectBranch(pid interface{}, branch string, option
// CreateBranchOptions represents the available CreateBranch() options. // CreateBranchOptions represents the available CreateBranch() options.
// //
// GitLab API docs: // GitLab API docs:
// https://gitlab.com/gitlab-org/gitlab-ce/blob/8-16-stable/doc/api/branches.md#create-repository-branch // https://docs.gitlab.com/ce/api/branches.html#create-repository-branch
type CreateBranchOptions struct { type CreateBranchOptions struct {
BranchName *string `url:"branch_name,omitempty" json:"branch_name,omitempty"` BranchName *string `url:"branch_name,omitempty" json:"branch_name,omitempty"`
Ref *string `url:"ref,omitempty" json:"ref,omitempty"` Ref *string `url:"ref,omitempty" json:"ref,omitempty"`
...@@ -181,7 +179,7 @@ type CreateBranchOptions struct { ...@@ -181,7 +179,7 @@ type CreateBranchOptions struct {
// CreateBranch creates branch from commit SHA or existing branch. // CreateBranch creates branch from commit SHA or existing branch.
// //
// GitLab API docs: // GitLab API docs:
// https://gitlab.com/gitlab-org/gitlab-ce/blob/8-16-stable/doc/api/branches.md#create-repository-branch // https://docs.gitlab.com/ce/api/branches.html#create-repository-branch
func (s *BranchesService) CreateBranch(pid interface{}, opt *CreateBranchOptions, options ...OptionFunc) (*Branch, *Response, error) { func (s *BranchesService) CreateBranch(pid interface{}, opt *CreateBranchOptions, options ...OptionFunc) (*Branch, *Response, error) {
project, err := parseID(pid) project, err := parseID(pid)
if err != nil { if err != nil {
...@@ -206,7 +204,7 @@ func (s *BranchesService) CreateBranch(pid interface{}, opt *CreateBranchOptions ...@@ -206,7 +204,7 @@ func (s *BranchesService) CreateBranch(pid interface{}, opt *CreateBranchOptions
// DeleteBranch deletes an existing branch. // DeleteBranch deletes an existing branch.
// //
// GitLab API docs: // GitLab API docs:
// https://gitlab.com/gitlab-org/gitlab-ce/blob/8-16-stable/doc/api/branches.md#delete-repository-branch // https://docs.gitlab.com/ce/api/branches.html#delete-repository-branch
func (s *BranchesService) DeleteBranch(pid interface{}, branch string, options ...OptionFunc) (*Response, error) { func (s *BranchesService) DeleteBranch(pid interface{}, branch string, options ...OptionFunc) (*Response, error) {
project, err := parseID(pid) project, err := parseID(pid)
if err != nil { if err != nil {
...@@ -225,7 +223,7 @@ func (s *BranchesService) DeleteBranch(pid interface{}, branch string, options . ...@@ -225,7 +223,7 @@ func (s *BranchesService) DeleteBranch(pid interface{}, branch string, options .
// DeleteMergedBranches deletes all branches that are merged into the project's default branch. // DeleteMergedBranches deletes all branches that are merged into the project's default branch.
// //
// GitLab API docs: // GitLab API docs:
// https://gitlab.com/gitlab-org/gitlab-ce/blob/8-16-stable/doc/api/branches.md#delete-merged-branches // https://docs.gitlab.com/ce/api/branches.html#delete-merged-branches
func (s *BranchesService) DeleteMergedBranches(pid interface{}, options ...OptionFunc) (*Response, error) { func (s *BranchesService) DeleteMergedBranches(pid interface{}, options ...OptionFunc) (*Response, error) {
project, err := parseID(pid) project, err := parseID(pid)
if err != nil { if err != nil {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment