Skip to content

Commit

Permalink
Merge branch 'master' into doco-tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
adamdmharvey authored May 19, 2022
2 parents 7ddda80 + af626c3 commit bf399b8
Show file tree
Hide file tree
Showing 39 changed files with 1,237 additions and 719 deletions.
2 changes: 0 additions & 2 deletions .circleci/brew-deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
set -e

# Install the latest circleci from homebrew
git -C /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core fetch --unshallow
git -C /usr/local/Homebrew/Library/Taps/homebrew/homebrew-cask fetch --unshallow
brew update

VERSION=$("$DESTDIR"/circleci version)
Expand Down
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ executors:
CGO_ENABLED: 0
mac:
macos:
xcode: 11.3.1
xcode: 12.5.1
environment:
CGO_ENABLED: 0
HOMEBREW_NO_AUTO_UPDATE: 1
Expand Down
46 changes: 0 additions & 46 deletions .circleci/install-packr.sh

This file was deleted.

38 changes: 0 additions & 38 deletions .circleci/pack.sh

This file was deleted.

49 changes: 49 additions & 0 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# Checklist
=========

- [ ] I have performed a self-review of my own code
- [ ] I have commented my code, particularly in hard-to-understand areas
- [ ] I have checked for similar issues and haven't found anything relevant.
- [ ] This is not a security issue (which should be reported here: https://circleci.com/security/)
- [ ] I have read [Contribution Guidelines](https://github.com/CircleCI-Public/circleci-cli/blob/master/CONTRIBUTING.md).

## Changes
=======

- Put itemized changes here, preferably in imperative mood, i.e. "Add
`functionA` to `fileB`"

## Rationale
=========

What was the overarching product goal of this PR as well as any pertinent
history of changes

## Considerations
==============

Why you made some of the technical decisions that you made, especially if the
reasoning is not immediately obvious

## Analytics Events Added
======================

- `event-name`

## Screenshots
============
<h4>Before</h4>
Image or [gif](https://giphy.com/apps/giphycapture)

<h4>After</h4>
Image or gif where change can be clearly seen

## **Here are some helpful tips you can follow when submitting a pull request:**

1. Fork [the repository](https://github.com/CircleCI-Public/circleci-cli) and create your branch from `master`.
2. Run `make build` in the repository root.
3. If you've fixed a bug or added code that should be tested, add tests!
4. Ensure the test suite passes (`make test`).
5. The `--debug` flag is often helpful for debugging HTTP client requests and responses.
6. Format your code with [gofmt](https://golang.org/cmd/gofmt/).
7. Make sure your code lints (`make lint`). Note: This requires Docker to run inside a local job.
13 changes: 0 additions & 13 deletions .github/PULL_REQUEST_TEMPLATE/PULL_REQUEST.md

This file was deleted.

4 changes: 0 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,6 @@ snap/.snapcraft/
stage/
*.snap

# packr related
*/*-packr.go
packrd/

# golangci-lint
# We expect to install the binary each time in CI
bin/golangci-lint
Expand Down
5 changes: 1 addition & 4 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,6 @@ archives:
- api/graphql/LICENSE
- md_docs/LICENSE

before:
hooks:
- make pack

builds:
- binary: circleci
env:
Expand All @@ -25,6 +21,7 @@ builds:
- linux
goarch:
- amd64
- arm64
ldflags:
# -s Omit the symbol table and debug information.
# -w Omit the DWARF symbol table.
Expand Down
10 changes: 0 additions & 10 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ GOOS=$(shell go env GOOS)
GOARCH=$(shell go env GOARCH)

build: always
GO111MODULE=on .circleci/pack.sh
go build -o build/$(GOOS)/$(GOARCH)/circleci

build-all: build/linux/amd64/circleci build/darwin/amd64/circleci
Expand All @@ -16,7 +15,6 @@ build/%/amd64/circleci: always
clean:
GO111MODULE=off go clean -i
rm -rf build out docs dist
.circleci/pack.sh clean

.PHONY: test
test:
Expand All @@ -34,14 +32,6 @@ lint:
doc:
godoc -http=:6060

.PHONY: install-packr
install-packr:
bash .circleci/install-packr.sh

.PHONY: pack
pack:
bash .circleci/pack.sh

.PHONY: install-lint
install-lint:
bash .circleci/install-lint.sh
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ We publish the tool to [Homebrew](https://brew.sh/). The tool is [part of `homeb

The particular considerations that we make are:


1. Since Homebrew [doesn't "like tools that upgrade themselves"](https://docs.brew.sh/Acceptable-Formulae#we-dont-like-tools-that-upgrade-themselves), we disable the `circleci update` command when the tool is released through homebrew. We do this by [defining the PackageManager](https://github.com/Homebrew/homebrew-core/blob/eb1fdb84e2924289bcc8c85ee45081bf83dc024d/Formula/circleci.rb#L28) constant to `homebrew`, which allows us to [disable the `update` command at runtime](https://github.com/CircleCI-Public/circleci-cli/blob/67c7d52bace63846f87a1ed79f67f257c94a55b4/cmd/root.go#L119-L123).
1. We want to avoid every push to `master` from creating a Pull Request to the `circleci` formula on Homebrew. We want to avoid overloading the Homebrew team with pull requests to update our formula for small changes (changes to docs or other files that don't change functionality in the tool).

Expand Down
9 changes: 0 additions & 9 deletions _data/data.yml

This file was deleted.

66 changes: 42 additions & 24 deletions api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -514,7 +514,7 @@ func WhoamiQuery(cl *graphql.Client) (*WhoamiResponse, error) {
}

// ConfigQuery calls the GQL API to validate and process config
func ConfigQuery(cl *graphql.Client, configPath string, orgSlug string, pipelineValues pipeline.Values) (*ConfigResponse, error) {
func ConfigQuery(cl *graphql.Client, configPath string, orgSlug string, params pipeline.Parameters, values pipeline.Values) (*ConfigResponse, error) {
var response BuildConfigResponse
var query string

Expand All @@ -523,30 +523,38 @@ func ConfigQuery(cl *graphql.Client, configPath string, orgSlug string, pipeline
return nil, err
}

// GraphQL isn't forwards-compatible, so we are unusually selective here about
// passing only non-empty fields on to the API, to minimize user impact if the
// backend is out of date.
var fieldAddendums string
if orgSlug != "" {
query = `query ValidateConfig ($config: String!, $pipelineValues: [StringKeyVal!], $orgSlug: String) {
buildConfig(configYaml: $config, pipelineValues: $pipelineValues, orgSlug: $orgSlug) {
valid,
errors { message },
sourceYaml,
outputYaml
}
}`
} else {
query = `query ValidateConfig ($config: String!, $pipelineValues: [StringKeyVal!]) {
buildConfig(configYaml: $config, pipelineValues: $pipelineValues) {
valid,
errors { message },
sourceYaml,
outputYaml
}
}`
fieldAddendums += ", orgSlug: $orgSlug"
}
if len(params) > 0 {
fieldAddendums += ", pipelineParametersJson: $pipelineParametersJson"
}
query = fmt.Sprintf(
`query ValidateConfig ($config: String!, $pipelineParametersJson: String, $pipelineValues: [StringKeyVal!], $orgSlug: String) {
buildConfig(configYaml: $config, pipelineValues: $pipelineValues%s) {
valid,
errors { message },
sourceYaml,
outputYaml
}
}`,
fieldAddendums)

request := graphql.NewRequest(query)
request.Var("config", config)
if pipelineValues != nil {
request.Var("pipelineValues", pipeline.PrepareForGraphQL(pipelineValues))
if values != nil {
request.Var("pipelineValues", pipeline.PrepareForGraphQL(values))
}
if params != nil {
pipelineParameters, err := json.Marshal(params)
if err != nil {
return nil, fmt.Errorf("unable to serialize pipeline values: %s", err.Error())
}
request.Var("pipelineParametersJson", string(pipelineParameters))
}
if orgSlug != "" {
request.Var("orgSlug", orgSlug)
Expand Down Expand Up @@ -794,7 +802,7 @@ func CreateImportedNamespace(cl *graphql.Client, name string) (*ImportNamespaceR
return &response, nil
}

func createNamespaceWithOwnerID(cl *graphql.Client, name string, ownerID string) (*CreateNamespaceResponse, error) {
func CreateNamespaceWithOwnerID(cl *graphql.Client, name string, ownerID string) (*CreateNamespaceResponse, error) {
var response CreateNamespaceResponse

query := `
Expand Down Expand Up @@ -951,7 +959,7 @@ func CreateNamespace(cl *graphql.Client, name string, organizationName string, o
return nil, errors.Wrap(organizationNotFound(organizationName, organizationVcs), getOrgError.Error())
}

createNSResponse, createNSError := createNamespaceWithOwnerID(cl, name, getOrgResponse.Organization.ID)
createNSResponse, createNSError := CreateNamespaceWithOwnerID(cl, name, getOrgResponse.Organization.ID)

if createNSError != nil {
return nil, createNSError
Expand Down Expand Up @@ -1356,6 +1364,7 @@ func OrbSource(cl *graphql.Client, orbRef string) (string, error) {
}`

request := graphql.NewRequest(query)
request.SetToken(cl.Token)
request.Var("orbVersionRef", ref)

err := cl.Run(request, &response)
Expand Down Expand Up @@ -1424,6 +1433,7 @@ func OrbInfo(cl *graphql.Client, orbRef string) (*OrbVersion, error) {
}`

request := graphql.NewRequest(query)
request.SetToken(cl.Token)
request.Var("orbVersionRef", ref)

err := cl.Run(request, &response)
Expand Down Expand Up @@ -1492,6 +1502,7 @@ query ListOrbs ($after: String!, $certifiedOnly: Boolean!) {

for {
request := graphql.NewRequest(query)
request.SetToken(cl.Token)
request.Var("after", currentCursor)
request.Var("certifiedOnly", !uncertified)

Expand Down Expand Up @@ -1864,11 +1875,15 @@ func ListOrbCategories(cl *graphql.Client) (*OrbCategoriesForListing, error) {

// FollowProject initiates an API request to follow a specific project on
// CircleCI. Project slugs are case-sensitive.

var errorMessage = `Unable to follow project`

func FollowProject(config settings.Config, vcs string, owner string, projectName string) (FollowedProject, error) {

requestPath := fmt.Sprintf("%s/api/v1.1/project/%s/%s/%s/follow", config.Host, vcs, owner, projectName)
r, err := http.NewRequest(http.MethodPost, requestPath, nil)
if err != nil {
return FollowedProject{}, err
return FollowedProject{}, errors.Wrap(err, errorMessage)
}
r.Header.Set("Content-Type", "application/json; charset=utf-8")
r.Header.Set("Accept", "application/json; charset=utf-8")
Expand All @@ -1878,11 +1893,14 @@ func FollowProject(config settings.Config, vcs string, owner string, projectName
if err != nil {
return FollowedProject{}, err
}
if response.StatusCode >= 400 {
return FollowedProject{}, errors.New("Could not follow project")
}

var fr FollowedProject
err = json.NewDecoder(response.Body).Decode(&fr)
if err != nil {
return FollowedProject{}, err
return FollowedProject{}, errors.Wrap(err, errorMessage)
}

return fr, nil
Expand Down
Loading

0 comments on commit bf399b8

Please sign in to comment.