Skip to content

Commit

Permalink
EXT-282-follow-project (#745)
Browse files Browse the repository at this point in the history
* If user is attempting to follow a project that is not in bitbucket or git then warn them we do not support it

* Syntax fixes

* Error correcti0n
  • Loading branch information
corinnesollows authored Jul 4, 2022
1 parent f3c1720 commit 25ac45c
Showing 1 changed file with 21 additions and 14 deletions.
35 changes: 21 additions & 14 deletions cmd/follow.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,31 +14,38 @@ type options struct {
cfg *settings.Config
}

//followProject gets the remote data and attempts to follow its git project
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, vcsShort, remote.Organization, remote.Project)
if err != nil {
return err
//check that project url contains github or bitbucket; our legacy vcs
if remote.VcsType == git.GitHub || remote.VcsType == git.Bitbucket {
vcsShort := "gh"
if remote.VcsType == git.Bitbucket {
vcsShort = "bb"
}
res, err := api.FollowProject(*opts.cfg, vcsShort, remote.Organization, remote.Project)
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).")
}

} else {
//if not warn user their vcs is not supported
return errors.New(errorMessage)
}
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
}

//followProjectCommand follow cobra command creation
func followProjectCommand(config *settings.Config) *cobra.Command {
opts := options{
cfg: config,
Expand Down

0 comments on commit 25ac45c

Please sign in to comment.