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 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157
|
package api
import (
"github.com/hashicorp/go-retryablehttp"
gitlab "gitlab.com/gitlab-org/api/client-go"
)
var CreateProjectVariable = func(client *gitlab.Client, projectID interface{}, opts *gitlab.CreateProjectVariableOptions) (*gitlab.ProjectVariable, error) {
if client == nil {
client = apiClient.Lab()
}
vars, _, err := client.ProjectVariables.CreateVariable(projectID, opts)
if err != nil {
return nil, err
}
return vars, nil
}
var ListProjectVariables = func(client *gitlab.Client, projectID interface{}, opts *gitlab.ListProjectVariablesOptions) ([]*gitlab.ProjectVariable, error) {
if client == nil {
client = apiClient.Lab()
}
vars, _, err := client.ProjectVariables.ListVariables(projectID, opts)
if err != nil {
return nil, err
}
return vars, nil
}
var GetProjectVariable = func(client *gitlab.Client, projectID interface{}, key string, scope string) (*gitlab.ProjectVariable, error) {
if client == nil {
client = apiClient.Lab()
}
reqOpts := &gitlab.GetProjectVariableOptions{
Filter: &gitlab.VariableFilter{
EnvironmentScope: scope,
},
}
vars, _, err := client.ProjectVariables.GetVariable(projectID, key, reqOpts)
if err != nil {
return nil, err
}
return vars, nil
}
var DeleteProjectVariable = func(client *gitlab.Client, projectID interface{}, key string, scope string) error {
if client == nil {
client = apiClient.Lab()
}
reqOpts := &gitlab.RemoveProjectVariableOptions{
Filter: &gitlab.VariableFilter{
EnvironmentScope: scope,
},
}
_, err := client.ProjectVariables.RemoveVariable(projectID, key, reqOpts)
if err != nil {
return err
}
return nil
}
var UpdateProjectVariable = func(client *gitlab.Client, projectID interface{}, key string, opts *gitlab.UpdateProjectVariableOptions) (*gitlab.ProjectVariable, error) {
if client == nil {
client = apiClient.Lab()
}
filter := func(request *retryablehttp.Request) error {
q := request.URL.Query()
q.Add("filter[environment_scope]", *opts.EnvironmentScope)
request.URL.RawQuery = q.Encode()
return nil
}
vars, _, err := client.ProjectVariables.UpdateVariable(projectID, key, opts, filter)
if err != nil {
return nil, err
}
return vars, nil
}
var ListGroupVariables = func(client *gitlab.Client, groupID interface{}, opts *gitlab.ListGroupVariablesOptions) ([]*gitlab.GroupVariable, error) {
if client == nil {
client = apiClient.Lab()
}
vars, _, err := client.GroupVariables.ListVariables(groupID, opts)
if err != nil {
return nil, err
}
return vars, nil
}
var CreateGroupVariable = func(client *gitlab.Client, groupID interface{}, opts *gitlab.CreateGroupVariableOptions) (*gitlab.GroupVariable, error) {
if client == nil {
client = apiClient.Lab()
}
vars, _, err := client.GroupVariables.CreateVariable(groupID, opts)
if err != nil {
return nil, err
}
return vars, nil
}
var GetGroupVariable = func(client *gitlab.Client, groupID interface{}, key string, scope string) (*gitlab.GroupVariable, error) {
if client == nil {
client = apiClient.Lab()
}
reqOpts := &gitlab.GetGroupVariableOptions{
Filter: &gitlab.VariableFilter{
EnvironmentScope: scope,
},
}
vars, _, err := client.GroupVariables.GetVariable(groupID, key, reqOpts)
if err != nil {
return nil, err
}
return vars, nil
}
var DeleteGroupVariable = func(client *gitlab.Client, groupID interface{}, key string) error {
if client == nil {
client = apiClient.Lab()
}
_, err := client.GroupVariables.RemoveVariable(groupID, key)
if err != nil {
return err
}
return nil
}
var UpdateGroupVariable = func(client *gitlab.Client, groupID interface{}, key string, opts *gitlab.UpdateGroupVariableOptions) (*gitlab.GroupVariable, error) {
if client == nil {
client = apiClient.Lab()
}
vars, _, err := client.GroupVariables.UpdateVariable(groupID, key, opts)
if err != nil {
return nil, err
}
return vars, nil
}
|