version.go

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