1 // 2 // Copyright 2021, Andrea Funto' 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 "net/http" 20 21 // VersionService handles communication with the GitLab server instance to 22 // retrieve its version information via the GitLab API. 23 // 24 // GitLab API docs: https://docs.gitlab.com/ee/api/version.html 25 type VersionService struct { 26 client *Client 27 } 28 29 // Version represents a GitLab instance version. 30 // 31 // GitLab API docs: https://docs.gitlab.com/ee/api/version.html 32 type Version struct { 33 Version string `json:"version"` 34 Revision string `json:"revision"` 35 } 36 37 func (s Version) String() string { 38 return Stringify(s) 39 } 40 41 // GetVersion gets a GitLab server instance version; it is only available to 42 // authenticated users. 43 // 44 // GitLab API docs: https://docs.gitlab.com/ee/api/version.html 45 func (s *VersionService) GetVersion(options ...RequestOptionFunc) (*Version, *Response, error) { 46 req, err := s.client.NewRequest(http.MethodGet, "version", nil, options) 47 if err != nil { 48 return nil, nil, err 49 } 50 51 v := new(Version) 52 resp, err := s.client.Do(req, v) 53 if err != nil { 54 return nil, resp, err 55 } 56 57 return v, resp, nil 58 } 59