...

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

Documentation: github.com/xanzy/go-gitlab

     1  //
     2  // Copyright 2021, Sander van Harmelen
     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  // RepositorySubmodulesService handles communication with the repository
    26  // submodules related methods of the GitLab API.
    27  //
    28  // GitLab API docs: https://docs.gitlab.com/ee/api/repository_submodules.html
    29  type RepositorySubmodulesService struct {
    30  	client *Client
    31  }
    32  
    33  // SubmoduleCommit represents a GitLab submodule commit.
    34  //
    35  // GitLab API docs: https://docs.gitlab.com/ee/api/repository_submodules.html
    36  type SubmoduleCommit struct {
    37  	ID             string           `json:"id"`
    38  	ShortID        string           `json:"short_id"`
    39  	Title          string           `json:"title"`
    40  	AuthorName     string           `json:"author_name"`
    41  	AuthorEmail    string           `json:"author_email"`
    42  	CommitterName  string           `json:"committer_name"`
    43  	CommitterEmail string           `json:"committer_email"`
    44  	CreatedAt      *time.Time       `json:"created_at"`
    45  	Message        string           `json:"message"`
    46  	ParentIDs      []string         `json:"parent_ids"`
    47  	CommittedDate  *time.Time       `json:"committed_date"`
    48  	AuthoredDate   *time.Time       `json:"authored_date"`
    49  	Status         *BuildStateValue `json:"status"`
    50  }
    51  
    52  func (r SubmoduleCommit) String() string {
    53  	return Stringify(r)
    54  }
    55  
    56  // UpdateSubmoduleOptions represents the available UpdateSubmodule() options.
    57  //
    58  // GitLab API docs:
    59  // https://docs.gitlab.com/ee/api/repository_submodules.html#update-existing-submodule-reference-in-repository
    60  type UpdateSubmoduleOptions struct {
    61  	Branch        *string `url:"branch,omitempty" json:"branch,omitempty"`
    62  	CommitSHA     *string `url:"commit_sha,omitempty" json:"commit_sha,omitempty"`
    63  	CommitMessage *string `url:"commit_message,omitempty" json:"commit_message,omitempty"`
    64  }
    65  
    66  // UpdateSubmodule updates an existing submodule reference.
    67  //
    68  // GitLab API docs:
    69  // https://docs.gitlab.com/ee/api/repository_submodules.html#update-existing-submodule-reference-in-repository
    70  func (s *RepositorySubmodulesService) UpdateSubmodule(pid interface{}, submodule string, opt *UpdateSubmoduleOptions, options ...RequestOptionFunc) (*SubmoduleCommit, *Response, error) {
    71  	project, err := parseID(pid)
    72  	if err != nil {
    73  		return nil, nil, err
    74  	}
    75  	u := fmt.Sprintf(
    76  		"projects/%s/repository/submodules/%s",
    77  		PathEscape(project),
    78  		PathEscape(submodule),
    79  	)
    80  
    81  	req, err := s.client.NewRequest(http.MethodPut, u, opt, options)
    82  	if err != nil {
    83  		return nil, nil, err
    84  	}
    85  
    86  	sc := new(SubmoduleCommit)
    87  	resp, err := s.client.Do(req, sc)
    88  	if err != nil {
    89  		return nil, resp, err
    90  	}
    91  
    92  	return sc, resp, nil
    93  }
    94  

View as plain text