Skip to content

Commit

Permalink
Merge branch 'main' into fix/readme-docker-instruction
Browse files Browse the repository at this point in the history
  • Loading branch information
abdelDriowya authored May 10, 2023
2 parents 613fdda + 7b38e08 commit 249f1f7
Show file tree
Hide file tree
Showing 15 changed files with 650 additions and 142 deletions.
6 changes: 6 additions & 0 deletions .pre-commit-hooks.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
- id: config-validate
name: Validate CircleCI config
entry: circleci config validate --skip-update-check
language: golang
files: .circleci/config.yml
2 changes: 2 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
FROM cimg/go:1.20

LABEL maintainer="Developer Experience Team <[email protected]>"

ENV CIRCLECI_CLI_SKIP_UPDATE_CHECK true

COPY ./dist/circleci-cli_linux_amd64/circleci /usr/local/bin
7 changes: 3 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -112,10 +112,9 @@ CircleCI host has been set.
Setup complete. Your configuration has been saved.
```

If you are using this tool on `circleci.com`, accept the provided default `CircleCI Host`.

If you are using this tool on `circleci.com`. accept the provided default `CircleCI Host`.

Server users will have to change the default value to your custom address (i.e. `circleci.my-org.com`).
Server users will have to change the default value to your custom address (e.g., `circleci.my-org.com`).

**Note**: Server does not yet support config processing and orbs, you will only be able to use `circleci local execute` (previously `circleci build`) for now.

Expand Down Expand Up @@ -153,7 +152,7 @@ The following commands are affected:

## Platforms, Deployment and Package Managers

The tool is deployed through a number of channels. The primary release channel is through [GitHub Releases](https://github.com/CircleCI-Public/circleci-cli/releases). Green builds on the `main` branch will publish a new GitHub release. These releases contain binaries for macOS, Linux and Windows. These releases are published from (CircleCI)[https://app.circleci.com/pipelines/github/CircleCI-Public/circleci-cli] using (GoReleaser)[https://goreleaser.com/].
The tool is deployed through a number of channels. The primary release channel is through [GitHub Releases](https://github.com/CircleCI-Public/circleci-cli/releases). Green builds on the `main` branch will publish a new GitHub release. These releases contain binaries for macOS, Linux and Windows. These releases are published from (CircleCI)[https://app.circleci.com/pipelines/github/CircleCI-Public/circleci-cli] using [GoReleaser](https://goreleaser.com/).

### Homebrew

Expand Down
11 changes: 8 additions & 3 deletions api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -513,7 +513,7 @@ func WhoamiQuery(cl *graphql.Client) (*WhoamiResponse, error) {
}

// OrbQuery validated and processes an orb.
func OrbQuery(cl *graphql.Client, configPath string) (*ConfigResponse, error) {
func OrbQuery(cl *graphql.Client, configPath string, ownerId string) (*ConfigResponse, error) {
var response OrbConfigResponse

config, err := loadYaml(configPath)
Expand All @@ -522,8 +522,8 @@ func OrbQuery(cl *graphql.Client, configPath string) (*ConfigResponse, error) {
}

query := `
query ValidateOrb ($config: String!) {
orbConfig(orbYaml: $config) {
query ValidateOrb ($config: String!, $owner: UUID) {
orbConfig(orbYaml: $config, ownerId: $owner) {
valid,
errors { message },
sourceYaml,
Expand All @@ -533,6 +533,11 @@ func OrbQuery(cl *graphql.Client, configPath string) (*ConfigResponse, error) {

request := graphql.NewRequest(query)
request.Var("config", config)

if ownerId != "" {
request.Var("owner", ownerId)
}

request.SetToken(cl.Token)

err = cl.Run(request, &response)
Expand Down
14 changes: 14 additions & 0 deletions api/collaborators/collaborators.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package collaborators

type CollaborationResult struct {
VcsType string `json:"vcs_type"`
OrgSlug string `json:"slug"`
OrgName string `json:"name"`
OrgId string `json:"id"`
AvatarUrl string `json:"avatar_url"`
}

type CollaboratorsClient interface {
GetCollaborationBySlug(slug string) (*CollaborationResult, error)
GetOrgCollaborations() ([]CollaborationResult, error)
}
64 changes: 64 additions & 0 deletions api/collaborators/collaborators_rest.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package collaborators

import (
"net/url"
"strings"

"github.com/CircleCI-Public/circleci-cli/api/rest"
"github.com/CircleCI-Public/circleci-cli/settings"
)

var (
CollaborationsPath = "me/collaborations"
)

type collaboratorsRestClient struct {
client *rest.Client
}

// NewCollaboratorsRestClient returns a new collaboratorsRestClient satisfying the api.CollaboratorsClient
// interface via the REST API.
func NewCollaboratorsRestClient(config settings.Config) (*collaboratorsRestClient, error) {
client := &collaboratorsRestClient{
client: rest.NewFromConfig(config.Host, &config),
}
return client, nil
}

func (c *collaboratorsRestClient) GetOrgCollaborations() ([]CollaborationResult, error) {
req, err := c.client.NewRequest("GET", &url.URL{Path: CollaborationsPath}, nil)
if err != nil {
return nil, err
}

var resp []CollaborationResult
_, err = c.client.DoRequest(req, &resp)
return resp, err
}

func (c *collaboratorsRestClient) GetCollaborationBySlug(slug string) (*CollaborationResult, error) {
// Support for <vcs-name>/<org-name> as well as <vcs-short>/<org-name> for the slug
// requires splitting
collaborations, err := c.GetOrgCollaborations()

if err != nil {
return nil, err
}

slugParts := strings.Split(slug, "/")

for _, v := range collaborations {
// The rest-api allways returns <vsc-short>/<org-name> as a slug
if v.OrgSlug == slug {
return &v, nil
}

// Compare first part of argument slug with the VCSType
splitted := strings.Split(v.OrgSlug, "/")
if len(slugParts) >= 2 && len(splitted) >= 2 && slugParts[0] == v.VcsType && slugParts[1] == splitted[1] {
return &v, nil
}
}

return nil, nil
}
Loading

0 comments on commit 249f1f7

Please sign in to comment.