-
Notifications
You must be signed in to change notification settings - Fork 237
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into adamdmharvey/enable-setup-in-examples
- Loading branch information
Showing
34 changed files
with
1,889 additions
and
1,198 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ version: 2.1 | |
|
||
orbs: | ||
shellcheck: circleci/[email protected] | ||
windows: circleci/windows@2.2.0 | ||
windows: circleci/windows@5.0.0 | ||
|
||
executors: | ||
go: | ||
|
@@ -82,19 +82,22 @@ commands: | |
|
||
jobs: | ||
test_windows: | ||
executor: windows/default | ||
executor: | ||
name: windows/default | ||
shell: bash --login -eo pipefail | ||
steps: | ||
- run: git config --global core.autocrlf false | ||
- checkout | ||
- run: setx GOPATH %USERPROFILE%\go | ||
- run: go get gotest.tools/gotestsum | ||
- run: mkdir test_results | ||
- run: setx TESTING "true" | ||
|
||
- run: | ||
name: Run tests | ||
command: | | ||
C:\Users\circleci\go\bin\gotestsum.exe --junitfile test_results/windows.xml | ||
export GOBIN=/c/go/bin | ||
export PATH=$GOBIN:$PATH | ||
export TESTING="true" | ||
go install gotest.tools/gotestsum@latest | ||
gotestsum --junitfile test_results/windows.xml | ||
- store_test_results: | ||
path: test_results | ||
- store_artifacts: | ||
|
@@ -267,9 +270,9 @@ jobs: | |
brew-deploy: | ||
executor: mac | ||
environment: | ||
- USER: circleci | ||
- TRAVIS: circleci | ||
- DESTDIR: /Users/distiller/dest | ||
USER: circleci | ||
TRAVIS: circleci | ||
DESTDIR: /Users/distiller/dest | ||
steps: | ||
- checkout | ||
- force-http-1 | ||
|
@@ -332,6 +335,8 @@ workflows: | |
- brew-deploy: | ||
requires: | ||
- run-brew-deploy-gate | ||
context: | ||
- devex-release | ||
- deploy: | ||
requires: | ||
- test | ||
|
@@ -342,4 +347,6 @@ workflows: | |
- shellcheck/check | ||
filters: | ||
branches: | ||
only: master | ||
only: main | ||
context: | ||
- devex-release |
Validating CODEOWNERS rules …
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
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
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,15 @@ | ||
package project | ||
|
||
// ProjectEnvironmentVariable is a Environment Variable of a Project | ||
type ProjectEnvironmentVariable struct { | ||
Name string | ||
Value string | ||
} | ||
|
||
// ProjectClient is the interface to interact with project and it's | ||
// components. | ||
type ProjectClient interface { | ||
ListAllEnvironmentVariables(vcs, org, project string) ([]*ProjectEnvironmentVariable, error) | ||
GetEnvironmentVariable(vcs, org, project, envName string) (*ProjectEnvironmentVariable, error) | ||
CreateEnvironmentVariable(vcs, org, project string, v ProjectEnvironmentVariable) (*ProjectEnvironmentVariable, error) | ||
} |
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,157 @@ | ||
package project | ||
|
||
import ( | ||
"fmt" | ||
"net/url" | ||
|
||
"github.com/CircleCI-Public/circleci-cli/api/rest" | ||
"github.com/CircleCI-Public/circleci-cli/settings" | ||
) | ||
|
||
type projectRestClient struct { | ||
token string | ||
server string | ||
client *rest.Client | ||
} | ||
|
||
var _ ProjectClient = &projectRestClient{} | ||
|
||
type listProjectEnvVarsParams struct { | ||
vcs string | ||
org string | ||
project string | ||
pageToken string | ||
} | ||
|
||
type projectEnvVarResponse struct { | ||
Name string | ||
Value string | ||
} | ||
|
||
type listAllProjectEnvVarsResponse struct { | ||
Items []projectEnvVarResponse | ||
NextPageToken string `json:"next_page_token"` | ||
} | ||
|
||
type createProjectEnvVarRequest struct { | ||
Name string `json:"name"` | ||
Value string `json:"value"` | ||
} | ||
|
||
// NewProjectRestClient returns a new projectRestClient satisfying the api.ProjectInterface | ||
// interface via the REST API. | ||
func NewProjectRestClient(config settings.Config) (*projectRestClient, error) { | ||
serverURL, err := config.ServerURL() | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
client := &projectRestClient{ | ||
token: config.Token, | ||
server: serverURL.String(), | ||
client: rest.New(config.Host, &config), | ||
} | ||
|
||
return client, nil | ||
} | ||
|
||
// ListAllEnvironmentVariables returns all of the environment variables owned by the | ||
// given project. Note that pagination is not supported - we get all | ||
// pages of env vars and return them all. | ||
func (p *projectRestClient) ListAllEnvironmentVariables(vcs, org, project string) ([]*ProjectEnvironmentVariable, error) { | ||
res := make([]*ProjectEnvironmentVariable, 0) | ||
var nextPageToken string | ||
for { | ||
resp, err := p.listEnvironmentVariables(&listProjectEnvVarsParams{ | ||
vcs: vcs, | ||
org: org, | ||
project: project, | ||
pageToken: nextPageToken, | ||
}) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
for _, ev := range resp.Items { | ||
res = append(res, &ProjectEnvironmentVariable{ | ||
Name: ev.Name, | ||
Value: ev.Value, | ||
}) | ||
} | ||
|
||
if resp.NextPageToken == "" { | ||
break | ||
} | ||
|
||
nextPageToken = resp.NextPageToken | ||
} | ||
return res, nil | ||
} | ||
|
||
func (c *projectRestClient) listEnvironmentVariables(params *listProjectEnvVarsParams) (*listAllProjectEnvVarsResponse, error) { | ||
path := fmt.Sprintf("project/%s/%s/%s/envvar", params.vcs, params.org, params.project) | ||
urlParams := url.Values{} | ||
if params.pageToken != "" { | ||
urlParams.Add("page-token", params.pageToken) | ||
} | ||
|
||
req, err := c.client.NewRequest("GET", &url.URL{Path: path, RawQuery: urlParams.Encode()}, nil) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
var resp listAllProjectEnvVarsResponse | ||
_, err = c.client.DoRequest(req, &resp) | ||
if err != nil { | ||
return nil, err | ||
} | ||
return &resp, nil | ||
} | ||
|
||
// GetEnvironmentVariable retrieves and returns a variable with the given name. | ||
// If the response status code is 404, nil is returned. | ||
func (c *projectRestClient) GetEnvironmentVariable(vcs string, org string, project string, envName string) (*ProjectEnvironmentVariable, error) { | ||
path := fmt.Sprintf("project/%s/%s/%s/envvar/%s", vcs, org, project, envName) | ||
req, err := c.client.NewRequest("GET", &url.URL{Path: path}, nil) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
var resp projectEnvVarResponse | ||
code, err := c.client.DoRequest(req, &resp) | ||
if err != nil { | ||
if code == 404 { | ||
// Note: 404 may mean that the project isn't found. | ||
// The cause can't be distinguished except by the response text. | ||
return nil, nil | ||
} | ||
return nil, err | ||
} | ||
return &ProjectEnvironmentVariable{ | ||
Name: resp.Name, | ||
Value: resp.Value, | ||
}, nil | ||
} | ||
|
||
// CreateEnvironmentVariable creates a variable on the given project. | ||
// This returns the variable if successfully created. | ||
func (c *projectRestClient) CreateEnvironmentVariable(vcs string, org string, project string, v ProjectEnvironmentVariable) (*ProjectEnvironmentVariable, error) { | ||
path := fmt.Sprintf("project/%s/%s/%s/envvar", vcs, org, project) | ||
req, err := c.client.NewRequest("POST", &url.URL{Path: path}, &createProjectEnvVarRequest{ | ||
Name: v.Name, | ||
Value: v.Value, | ||
}) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
var resp projectEnvVarResponse | ||
_, err = c.client.DoRequest(req, &resp) | ||
if err != nil { | ||
return nil, err | ||
} | ||
return &ProjectEnvironmentVariable{ | ||
Name: resp.Name, | ||
Value: resp.Value, | ||
}, nil | ||
} |
Oops, something went wrong.