This repository has been archived by the owner on Dec 10, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 960
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- v0.115.0
- v0.114.0
- v0.113.0
- v0.112.0
- v0.111.0
- v0.110.0
- v0.109.0
- v0.108.0
- v0.107.0
- v0.106.0
- v0.105.0
- v0.104.1
- v0.104.0
- v0.103.0
- v0.102.0
- v0.101.0
- v0.100.0
- v0.99.0
- v0.98.0
- v0.97.0
- v0.96.0
- v0.95.2
- v0.95.1
- v0.95.0
- v0.94.0
- v0.93.2
- v0.93.1
- v0.93.0
- v0.92.3
- v0.92.2
- v0.92.1
- v0.92.0
- v0.91.1
- v0.91.0
- v0.90.0
- v0.89.0
- v0.88.0
- v0.87.0
- v0.86.0
- v0.85.0
- v0.84.0
- v0.83.0
- v0.82.0
- v0.81.0
- v0.80.3
- v0.80.2
- v0.80.1
- v0.80.0
- v0.79.1
- v0.79.0
- v0.78.0
- v0.77.0
- v0.76.0
1 parent
4ec1dc6
commit 4c641df
Showing
3 changed files
with
119 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
// | ||
// Copyright 2022, Timo Furrer <tuxtimo@gmail.com> | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// | ||
|
||
package gitlab | ||
|
||
import "net/http" | ||
|
||
// MetadataService handles communication with the GitLab server instance to | ||
// retrieve its metadata information via the GitLab API. | ||
// | ||
// GitLab API docs: https://docs.gitlab.com/ce/api/version.md | ||
type MetadataService struct { | ||
client *Client | ||
} | ||
|
||
// Metadata represents a GitLab instance version. | ||
// | ||
// GitLab API docs: https://docs.gitlab.com/ce/api/metadata.md | ||
type Metadata struct { | ||
Version string `json:"version"` | ||
Revision string `json:"revision"` | ||
KAS struct { | ||
Enabled bool `json:"enabled"` | ||
ExternalURL string `json:"externalUrl"` | ||
Version string `json:"version"` | ||
} `json:"kas"` | ||
} | ||
|
||
func (s Metadata) String() string { | ||
return Stringify(s) | ||
} | ||
|
||
// GetMetadata gets a GitLab server instance meteadata. | ||
// | ||
// GitLab API docs: https://docs.gitlab.com/ce/api/metadata.md | ||
func (s *MetadataService) GetMetadata(options ...RequestOptionFunc) (*Metadata, *Response, error) { | ||
req, err := s.client.NewRequest(http.MethodGet, "metadata", nil, options) | ||
if err != nil { | ||
return nil, nil, err | ||
} | ||
|
||
v := new(Metadata) | ||
resp, err := s.client.Do(req, v) | ||
if err != nil { | ||
return nil, resp, err | ||
} | ||
|
||
return v, resp, err | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
// | ||
// Copyright 2022, Timo Furrer <tuxtimo@gmail.com> | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// | ||
|
||
package gitlab | ||
|
||
import ( | ||
"fmt" | ||
"net/http" | ||
"reflect" | ||
"testing" | ||
) | ||
|
||
func TestGetMetadata(t *testing.T) { | ||
mux, server, client := setup(t) | ||
defer teardown(server) | ||
|
||
mux.HandleFunc("/api/v4/metadata", | ||
func(w http.ResponseWriter, r *http.Request) { | ||
testMethod(t, r, http.MethodGet) | ||
fmt.Fprint(w, `{"version":"15.6.0-pre","revision":"016e8d8bdc3","kas":{"enabled":true,"externalUrl":"wss://kas.gitlab.com","version":"15.6.0-rc2"}}`) | ||
}) | ||
|
||
version, _, err := client.Metadata.GetMetadata() | ||
if err != nil { | ||
t.Errorf("Metadata.GetMetadata returned error: %v", err) | ||
} | ||
|
||
want := &Metadata{Version: "15.6.0-pre", Revision: "016e8d8bdc3", KAS: struct { | ||
Enabled bool `json:"enabled"` | ||
ExternalURL string `json:"externalUrl"` | ||
Version string `json:"version"` | ||
}{ | ||
Enabled: true, | ||
ExternalURL: "wss://kas.gitlab.com", | ||
Version: "15.6.0-rc2", | ||
}} | ||
if !reflect.DeepEqual(want, version) { | ||
t.Errorf("Metadata.GetMetadata returned %+v, want %+v", version, want) | ||
} | ||
} | ||
|