...

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

View as plain text