...

Source file src/github.com/xanzy/go-gitlab/project_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  // ProjectRepositoryStorageMoveService handles communication with the
    26  // repositories related methods of the GitLab API.
    27  //
    28  // GitLab API docs:
    29  // https://docs.gitlab.com/ee/api/project_repository_storage_moves.html
    30  type ProjectRepositoryStorageMoveService struct {
    31  	client *Client
    32  }
    33  
    34  // ProjectRepositoryStorageMove represents the status of a repository move.
    35  //
    36  // GitLab API docs:
    37  // https://docs.gitlab.com/ee/api/project_repository_storage_moves.html
    38  type ProjectRepositoryStorageMove 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  	Project                *RepositoryProject `json:"project"`
    45  }
    46  
    47  type RepositoryProject struct {
    48  	ID                int        `json:"id"`
    49  	Description       string     `json:"description"`
    50  	Name              string     `json:"name"`
    51  	NameWithNamespace string     `json:"name_with_namespace"`
    52  	Path              string     `json:"path"`
    53  	PathWithNamespace string     `json:"path_with_namespace"`
    54  	CreatedAt         *time.Time `json:"created_at"`
    55  }
    56  
    57  // RetrieveAllProjectStorageMovesOptions represents the available
    58  // RetrieveAllStorageMoves() options.
    59  //
    60  // GitLab API docs:
    61  // https://docs.gitlab.com/ee/api/project_repository_storage_moves.html#retrieve-all-project-repository-storage-moves
    62  type RetrieveAllProjectStorageMovesOptions ListOptions
    63  
    64  // RetrieveAllStorageMoves retrieves all project repository storage moves
    65  // accessible by the authenticated user.
    66  //
    67  // GitLab API docs:
    68  // https://docs.gitlab.com/ee/api/project_repository_storage_moves.html#retrieve-all-project-repository-storage-moves
    69  func (p ProjectRepositoryStorageMoveService) RetrieveAllStorageMoves(opts RetrieveAllProjectStorageMovesOptions, options ...RequestOptionFunc) ([]*ProjectRepositoryStorageMove, *Response, error) {
    70  	req, err := p.client.NewRequest(http.MethodGet, "project_repository_storage_moves", opts, options)
    71  	if err != nil {
    72  		return nil, nil, err
    73  	}
    74  
    75  	var psms []*ProjectRepositoryStorageMove
    76  	resp, err := p.client.Do(req, &psms)
    77  	if err != nil {
    78  		return nil, resp, err
    79  	}
    80  
    81  	return psms, resp, err
    82  }
    83  
    84  // RetrieveAllStorageMovesForProject retrieves all repository storage moves for
    85  // a single project accessible by the authenticated user.
    86  //
    87  // GitLab API docs:
    88  // https://docs.gitlab.com/ee/api/project_repository_storage_moves.html#retrieve-all-repository-storage-moves-for-a-project
    89  func (p ProjectRepositoryStorageMoveService) RetrieveAllStorageMovesForProject(project int, opts RetrieveAllProjectStorageMovesOptions, options ...RequestOptionFunc) ([]*ProjectRepositoryStorageMove, *Response, error) {
    90  	u := fmt.Sprintf("projects/%d/repository_storage_moves", project)
    91  
    92  	req, err := p.client.NewRequest(http.MethodGet, u, opts, options)
    93  	if err != nil {
    94  		return nil, nil, err
    95  	}
    96  
    97  	var psms []*ProjectRepositoryStorageMove
    98  	resp, err := p.client.Do(req, &psms)
    99  	if err != nil {
   100  		return nil, resp, err
   101  	}
   102  
   103  	return psms, resp, err
   104  }
   105  
   106  // GetStorageMove gets a single project repository storage move.
   107  //
   108  // GitLab API docs:
   109  // https://docs.gitlab.com/ee/api/project_repository_storage_moves.html#get-a-single-project-repository-storage-move
   110  func (p ProjectRepositoryStorageMoveService) GetStorageMove(repositoryStorage int, options ...RequestOptionFunc) (*ProjectRepositoryStorageMove, *Response, error) {
   111  	u := fmt.Sprintf("project_repository_storage_moves/%d", repositoryStorage)
   112  
   113  	req, err := p.client.NewRequest(http.MethodGet, u, nil, options)
   114  	if err != nil {
   115  		return nil, nil, err
   116  	}
   117  
   118  	psm := new(ProjectRepositoryStorageMove)
   119  	resp, err := p.client.Do(req, psm)
   120  	if err != nil {
   121  		return nil, resp, err
   122  	}
   123  
   124  	return psm, resp, err
   125  }
   126  
   127  // GetStorageMoveForProject gets a single repository storage move for a project.
   128  //
   129  // GitLab API docs:
   130  // https://docs.gitlab.com/ee/api/project_repository_storage_moves.html#get-a-single-repository-storage-move-for-a-project
   131  func (p ProjectRepositoryStorageMoveService) GetStorageMoveForProject(project int, repositoryStorage int, options ...RequestOptionFunc) (*ProjectRepositoryStorageMove, *Response, error) {
   132  	u := fmt.Sprintf("projects/%d/repository_storage_moves/%d", project, repositoryStorage)
   133  
   134  	req, err := p.client.NewRequest(http.MethodGet, u, nil, options)
   135  	if err != nil {
   136  		return nil, nil, err
   137  	}
   138  
   139  	psm := new(ProjectRepositoryStorageMove)
   140  	resp, err := p.client.Do(req, psm)
   141  	if err != nil {
   142  		return nil, resp, err
   143  	}
   144  
   145  	return psm, resp, err
   146  }
   147  
   148  // ScheduleStorageMoveForProjectOptions represents the available
   149  // ScheduleStorageMoveForProject() options.
   150  //
   151  // GitLab API docs:
   152  // https://docs.gitlab.com/ee/api/project_repository_storage_moves.html#schedule-a-repository-storage-move-for-a-project
   153  type ScheduleStorageMoveForProjectOptions struct {
   154  	DestinationStorageName *string `url:"destination_storage_name,omitempty" json:"destination_storage_name,omitempty"`
   155  }
   156  
   157  // ScheduleStorageMoveForProject schedule a repository to be moved for a project.
   158  //
   159  // GitLab API docs:
   160  // https://docs.gitlab.com/ee/api/project_repository_storage_moves.html#schedule-a-repository-storage-move-for-a-project
   161  func (p ProjectRepositoryStorageMoveService) ScheduleStorageMoveForProject(project int, opts ScheduleStorageMoveForProjectOptions, options ...RequestOptionFunc) (*ProjectRepositoryStorageMove, *Response, error) {
   162  	u := fmt.Sprintf("projects/%d/repository_storage_moves", project)
   163  
   164  	req, err := p.client.NewRequest(http.MethodPost, u, opts, options)
   165  	if err != nil {
   166  		return nil, nil, err
   167  	}
   168  
   169  	psm := new(ProjectRepositoryStorageMove)
   170  	resp, err := p.client.Do(req, psm)
   171  	if err != nil {
   172  		return nil, resp, err
   173  	}
   174  
   175  	return psm, resp, err
   176  }
   177  
   178  // ScheduleAllProjectStorageMovesOptions represents the available
   179  // ScheduleAllStorageMoves() options.
   180  //
   181  // GitLab API docs:
   182  // https://docs.gitlab.com/ee/api/project_repository_storage_moves.html#schedule-repository-storage-moves-for-all-projects-on-a-storage-shard
   183  type ScheduleAllProjectStorageMovesOptions struct {
   184  	SourceStorageName      *string `url:"source_storage_name,omitempty" json:"source_storage_name,omitempty"`
   185  	DestinationStorageName *string `url:"destination_storage_name,omitempty" json:"destination_storage_name,omitempty"`
   186  }
   187  
   188  // ScheduleAllStorageMoves schedules all repositories to be moved.
   189  //
   190  // GitLab API docs:
   191  // https://docs.gitlab.com/ee/api/project_repository_storage_moves.html#schedule-repository-storage-moves-for-all-projects-on-a-storage-shard
   192  func (p ProjectRepositoryStorageMoveService) ScheduleAllStorageMoves(opts ScheduleAllProjectStorageMovesOptions, options ...RequestOptionFunc) (*Response, error) {
   193  	req, err := p.client.NewRequest(http.MethodPost, "project_repository_storage_moves", opts, options)
   194  	if err != nil {
   195  		return nil, err
   196  	}
   197  
   198  	return p.client.Do(req, nil)
   199  }
   200  

View as plain text