...

Source file src/github.com/xanzy/go-gitlab/group_repository_storage_move.go

Documentation: github.com/xanzy/go-gitlab

     1  //
     2  // Copyright 2023, Nick Westbury
     3  //
     4  // Licensed under the Apache License, Version 2.0 (the "License");
     5  // you may not use this file except in compliance with the License.
     6  // You may obtain a copy of the License at
     7  //
     8  //     http://www.apache.org/licenses/LICENSE-2.0
     9  //
    10  // Unless required by applicable law or agreed to in writing, software
    11  // distributed under the License is distributed on an "AS IS" BASIS,
    12  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13  // See the License for the specific language governing permissions and
    14  // limitations under the License.
    15  //
    16  
    17  package gitlab
    18  
    19  import (
    20  	"fmt"
    21  	"net/http"
    22  	"time"
    23  )
    24  
    25  // GroupRepositoryStorageMoveService handles communication with the
    26  // group repositories related methods of the GitLab API.
    27  //
    28  // GitLab API docs:
    29  // https://docs.gitlab.com/ee/api/group_repository_storage_moves.html
    30  type GroupRepositoryStorageMoveService struct {
    31  	client *Client
    32  }
    33  
    34  // GroupRepositoryStorageMove represents the status of a repository move.
    35  //
    36  // GitLab API docs:
    37  // https://docs.gitlab.com/ee/api/group_repository_storage_moves.html
    38  type GroupRepositoryStorageMove struct {
    39  	ID                     int              `json:"id"`
    40  	CreatedAt              *time.Time       `json:"created_at"`
    41  	State                  string           `json:"state"`
    42  	SourceStorageName      string           `json:"source_storage_name"`
    43  	DestinationStorageName string           `json:"destination_storage_name"`
    44  	Group                  *RepositoryGroup `json:"group"`
    45  }
    46  
    47  type RepositoryGroup struct {
    48  	ID     int    `json:"id"`
    49  	Name   string `json:"name"`
    50  	WebURL string `json:"web_url"`
    51  }
    52  
    53  // RetrieveAllGroupStorageMovesOptions represents the available
    54  // RetrieveAllStorageMoves() options.
    55  //
    56  // GitLab API docs:
    57  // https://docs.gitlab.com/ee/api/group_repository_storage_moves.html#retrieve-all-group-repository-storage-moves
    58  type RetrieveAllGroupStorageMovesOptions ListOptions
    59  
    60  // RetrieveAllStorageMoves retrieves all group repository storage moves
    61  // accessible by the authenticated user.
    62  //
    63  // GitLab API docs:
    64  // https://docs.gitlab.com/ee/api/group_repository_storage_moves.html#retrieve-all-group-repository-storage-moves
    65  func (g GroupRepositoryStorageMoveService) RetrieveAllStorageMoves(opts RetrieveAllGroupStorageMovesOptions, options ...RequestOptionFunc) ([]*GroupRepositoryStorageMove, *Response, error) {
    66  	req, err := g.client.NewRequest(http.MethodGet, "group_repository_storage_moves", opts, options)
    67  	if err != nil {
    68  		return nil, nil, err
    69  	}
    70  
    71  	var gsms []*GroupRepositoryStorageMove
    72  	resp, err := g.client.Do(req, &gsms)
    73  	if err != nil {
    74  		return nil, resp, err
    75  	}
    76  
    77  	return gsms, resp, err
    78  }
    79  
    80  // RetrieveAllStorageMovesForGroup retrieves all repository storage moves for
    81  // a single group accessible by the authenticated user.
    82  //
    83  // GitLab API docs:
    84  // https://docs.gitlab.com/ee/api/group_repository_storage_moves.html#retrieve-all-repository-storage-moves-for-a-single-group
    85  func (g GroupRepositoryStorageMoveService) RetrieveAllStorageMovesForGroup(group int, opts RetrieveAllGroupStorageMovesOptions, options ...RequestOptionFunc) ([]*GroupRepositoryStorageMove, *Response, error) {
    86  	u := fmt.Sprintf("groups/%d/repository_storage_moves", group)
    87  
    88  	req, err := g.client.NewRequest(http.MethodGet, u, opts, options)
    89  	if err != nil {
    90  		return nil, nil, err
    91  	}
    92  
    93  	var gsms []*GroupRepositoryStorageMove
    94  	resp, err := g.client.Do(req, &gsms)
    95  	if err != nil {
    96  		return nil, resp, err
    97  	}
    98  
    99  	return gsms, resp, err
   100  }
   101  
   102  // GetStorageMove gets a single group repository storage move.
   103  //
   104  // GitLab API docs:
   105  // https://docs.gitlab.com/ee/api/group_repository_storage_moves.html#get-a-single-group-repository-storage-move
   106  func (g GroupRepositoryStorageMoveService) GetStorageMove(repositoryStorage int, options ...RequestOptionFunc) (*GroupRepositoryStorageMove, *Response, error) {
   107  	u := fmt.Sprintf("group_repository_storage_moves/%d", repositoryStorage)
   108  
   109  	req, err := g.client.NewRequest(http.MethodGet, u, nil, options)
   110  	if err != nil {
   111  		return nil, nil, err
   112  	}
   113  
   114  	gsm := new(GroupRepositoryStorageMove)
   115  	resp, err := g.client.Do(req, gsm)
   116  	if err != nil {
   117  		return nil, resp, err
   118  	}
   119  
   120  	return gsm, resp, err
   121  }
   122  
   123  // GetStorageMoveForGroup gets a single repository storage move for a group.
   124  //
   125  // GitLab API docs:
   126  // https://docs.gitlab.com/ee/api/group_repository_storage_moves.html#get-a-single-repository-storage-move-for-a-group
   127  func (g GroupRepositoryStorageMoveService) GetStorageMoveForGroup(group int, repositoryStorage int, options ...RequestOptionFunc) (*GroupRepositoryStorageMove, *Response, error) {
   128  	u := fmt.Sprintf("groups/%d/repository_storage_moves/%d", group, repositoryStorage)
   129  
   130  	req, err := g.client.NewRequest(http.MethodGet, u, nil, options)
   131  	if err != nil {
   132  		return nil, nil, err
   133  	}
   134  
   135  	gsm := new(GroupRepositoryStorageMove)
   136  	resp, err := g.client.Do(req, gsm)
   137  	if err != nil {
   138  		return nil, resp, err
   139  	}
   140  
   141  	return gsm, resp, err
   142  }
   143  
   144  // ScheduleStorageMoveForGroupOptions represents the available
   145  // ScheduleStorageMoveForGroup() options.
   146  //
   147  // GitLab API docs:
   148  // https://docs.gitlab.com/ee/api/group_repository_storage_moves.html#schedule-a-repository-storage-move-for-a-group
   149  type ScheduleStorageMoveForGroupOptions struct {
   150  	DestinationStorageName *string `url:"destination_storage_name,omitempty" json:"destination_storage_name,omitempty"`
   151  }
   152  
   153  // ScheduleStorageMoveForGroup schedule a repository to be moved for a group.
   154  //
   155  // GitLab API docs:
   156  // https://docs.gitlab.com/ee/api/group_repository_storage_moves.html#schedule-a-repository-storage-move-for-a-group
   157  func (g GroupRepositoryStorageMoveService) ScheduleStorageMoveForGroup(group int, opts ScheduleStorageMoveForGroupOptions, options ...RequestOptionFunc) (*GroupRepositoryStorageMove, *Response, error) {
   158  	u := fmt.Sprintf("groups/%d/repository_storage_moves", group)
   159  
   160  	req, err := g.client.NewRequest(http.MethodPost, u, opts, options)
   161  	if err != nil {
   162  		return nil, nil, err
   163  	}
   164  
   165  	gsm := new(GroupRepositoryStorageMove)
   166  	resp, err := g.client.Do(req, gsm)
   167  	if err != nil {
   168  		return nil, resp, err
   169  	}
   170  
   171  	return gsm, resp, err
   172  }
   173  
   174  // ScheduleAllGroupStorageMovesOptions represents the available
   175  // ScheduleAllStorageMoves() options.
   176  //
   177  // GitLab API docs:
   178  // https://docs.gitlab.com/ee/api/group_repository_storage_moves.html#schedule-repository-storage-moves-for-all-groups-on-a-storage-shard
   179  type ScheduleAllGroupStorageMovesOptions struct {
   180  	SourceStorageName      *string `url:"source_storage_name,omitempty" json:"source_storage_name,omitempty"`
   181  	DestinationStorageName *string `url:"destination_storage_name,omitempty" json:"destination_storage_name,omitempty"`
   182  }
   183  
   184  // ScheduleAllStorageMoves schedules all group repositories to be moved.
   185  //
   186  // GitLab API docs:
   187  // https://docs.gitlab.com/ee/api/group_repository_storage_moves.html#schedule-repository-storage-moves-for-all-groups-on-a-storage-shard
   188  func (g GroupRepositoryStorageMoveService) ScheduleAllStorageMoves(opts ScheduleAllGroupStorageMovesOptions, options ...RequestOptionFunc) (*Response, error) {
   189  	req, err := g.client.NewRequest(http.MethodPost, "group_repository_storage_moves", opts, options)
   190  	if err != nil {
   191  		return nil, err
   192  	}
   193  
   194  	return g.client.Do(req, nil)
   195  }
   196  

View as plain text