-
Notifications
You must be signed in to change notification settings - Fork 234
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Gabriel Simmer
authored
Sep 28, 2020
1 parent
bb01183
commit 6b7fd00
Showing
9 changed files
with
648 additions
and
28 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
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,54 @@ | ||
package cmd | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/CircleCI-Public/circleci-cli/api" | ||
"github.com/CircleCI-Public/circleci-cli/git" | ||
"github.com/CircleCI-Public/circleci-cli/settings" | ||
"github.com/pkg/errors" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
type options struct { | ||
cfg *settings.Config | ||
} | ||
|
||
func followProject(opts options) error { | ||
|
||
remote, err := git.InferProjectFromGitRemotes() | ||
|
||
if err != nil { | ||
return errors.Wrap(err, errorMessage) | ||
} | ||
|
||
vcsShort := "gh" | ||
if remote.VcsType == "BITBUCKET" { | ||
vcsShort = "bb" | ||
} | ||
res, err := api.FollowProject(opts.cfg.Host, vcsShort, remote.Organization, remote.Project, opts.cfg.Token) | ||
if err != nil { | ||
return err | ||
} | ||
if res.Followed { | ||
fmt.Println("Project successfully followed!") | ||
} else if res.Message == "Project not found" { | ||
fmt.Println("Unable to determine project slug for CircleCI (slug is case sensitive).") | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func followProjectCommand(config *settings.Config) *cobra.Command { | ||
opts := options{ | ||
cfg: config, | ||
} | ||
followCommand := &cobra.Command{ | ||
Use: "follow", | ||
Short: "Attempt to follow the project for the current git repository.", | ||
RunE: func(_ *cobra.Command, _ []string) error { | ||
return followProject(opts) | ||
}, | ||
} | ||
return followCommand | ||
} |
Oops, something went wrong.