forked from andygrunwald/go-gerrit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
plugins.go
131 lines (113 loc) · 4.71 KB
/
plugins.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
package gerrit
import (
"fmt"
)
// PluginsService contains Plugin related REST endpoints
//
// Gerrit API docs: https://gerrit-review.googlesource.com/Documentation/rest-api-plugins.html
type PluginsService struct {
client *Client
}
// PluginInfo entity describes a plugin.
type PluginInfo struct {
ID string `json:"id"`
Version string `json:"version"`
IndexURL string `json:"index_url,omitempty"`
Disabled bool `json:"disabled,omitempty"`
}
// PluginInput entity describes a plugin that should be installed.
type PluginInput struct {
URL string `json:"url"`
}
// PluginOptions specifies the different options for the ListPlugins call.
//
// Gerrit API docs: https://gerrit-review.googlesource.com/Documentation/rest-api-plugins.html#list-plugins
type PluginOptions struct {
// All enabled that all plugins are returned (enabled and disabled).
All bool `url:"all,omitempty"`
}
// ListPlugins lists the plugins installed on the Gerrit server.
// Only the enabled plugins are returned unless the all option is specified.
//
// To be allowed to see the installed plugins, a user must be a member of a group that is granted the 'View Plugins' capability or the 'Administrate Server' capability.
// The entries in the map are sorted by plugin ID.
//
// Gerrit API docs: https://gerrit-review.googlesource.com/Documentation/rest-api-plugins.html#list-plugins
func (s *PluginsService) ListPlugins(opt *PluginOptions) (*map[string]PluginInfo, *Response, error) {
u := "plugins/"
u, err := addOptions(u, opt)
if err != nil {
return nil, nil, err
}
req, err := s.client.NewRequest("GET", u, nil)
if err != nil {
return nil, nil, err
}
v := new(map[string]PluginInfo)
resp, err := s.client.Do(req, v)
if err != nil {
return nil, resp, err
}
return v, resp, err
}
// GetPluginStatus retrieves the status of a plugin on the Gerrit server.
//
// Gerrit API docs: https://gerrit-review.googlesource.com/Documentation/rest-api-plugins.html#get-plugin-status
func (s *PluginsService) GetPluginStatus(pluginID string) (*PluginInfo, *Response, error) {
u := fmt.Sprintf("plugins/%s/gerrit~status", pluginID)
return s.requestWithPluginInfoResponse("GET", u, nil)
}
// InstallPlugin installs a new plugin on the Gerrit server.
// If a plugin with the specified name already exists it is overwritten.
//
// Note: if the plugin provides its own name in the MANIFEST file, then the plugin name from the MANIFEST file has precedence over the {plugin-id} above.
//
// The plugin jar can either be sent as binary data in the request body or a URL to the plugin jar must be provided in the request body inside a PluginInput entity.
//
// As response a PluginInfo entity is returned that describes the plugin.
// If an existing plugin was overwritten the response is “200 OK”.
//
// Gerrit API docs: https://gerrit-review.googlesource.com/Documentation/rest-api-projects.html#set-dashboard
func (s *PluginsService) InstallPlugin(pluginID string, input *PluginInput) (*PluginInfo, *Response, error) {
u := fmt.Sprintf("plugins/%s", pluginID)
return s.requestWithPluginInfoResponse("PUT", u, input)
}
// EnablePlugin enables a plugin on the Gerrit server.
//
// As response a PluginInfo entity is returned that describes the plugin.
//
// Gerrit API docs: https://gerrit-review.googlesource.com/Documentation/rest-api-plugins.html#enable-plugin
func (s *PluginsService) EnablePlugin(pluginID string) (*PluginInfo, *Response, error) {
u := fmt.Sprintf("plugins/%s/gerrit~enable", pluginID)
return s.requestWithPluginInfoResponse("POST", u, nil)
}
// DisablePlugin disables a plugin on the Gerrit server.
//
// As response a PluginInfo entity is returned that describes the plugin.
//
// Gerrit API docs: https://gerrit-review.googlesource.com/Documentation/rest-api-plugins.html#disable-plugin
func (s *PluginsService) DisablePlugin(pluginID string) (*PluginInfo, *Response, error) {
u := fmt.Sprintf("plugins/%s/gerrit~disable", pluginID)
return s.requestWithPluginInfoResponse("POST", u, nil)
}
// ReloadPlugin reloads a plugin on the Gerrit server.
//
// As response a PluginInfo entity is returned that describes the plugin.
//
// Gerrit API docs: https://gerrit-review.googlesource.com/Documentation/rest-api-plugins.html#disable-plugin
func (s *PluginsService) ReloadPlugin(pluginID string) (*PluginInfo, *Response, error) {
u := fmt.Sprintf("plugins/%s/gerrit~reload", pluginID)
return s.requestWithPluginInfoResponse("POST", u, nil)
}
func (s *PluginsService) requestWithPluginInfoResponse(method, u string, input interface{}) (*PluginInfo, *Response, error) {
req, err := s.client.NewRequest(method, u, input)
if err != nil {
return nil, nil, err
}
v := new(PluginInfo)
resp, err := s.client.Do(req, v)
if err != nil {
return nil, resp, err
}
return v, resp, err
}