Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EXT-282-follow-project #745

Merged
merged 4 commits into from
Jul 4, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I noticed there's similar logic in cmd/open.go. Would it make sense to add an isLegacyVcs method to the Remote struct in git/git.go?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That also would definitely work. While I was writing this I was under the assumption that it was part of an external package. That being said, I dont know if its worth going back and changing, since these are most likely going to be the only two places using this and we're looking to eventually get rid of VCSType completely.

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)
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you might need an else clause here otherwise the conditions on lines 36 and 38 would print messages and then print an error

Suggested change
}
return nil
} else {
//if not warn user their vcs is not supported
return errors.New(errorMessage)
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup, added

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