Skip to content

Commit

Permalink
Respond to bitbucket cloud/server username.
Browse files Browse the repository at this point in the history
Looks like we forgot to add the ability for bitbucket cloud/server users
to invoke Atlantis using the name of the user they're running it as.
  • Loading branch information
lkysow committed Mar 13, 2019
1 parent 0c59540 commit 11b97a4
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 18 deletions.
16 changes: 10 additions & 6 deletions server/events/comment_parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,9 @@ type CommentBuilder interface {

// CommentParser implements CommentParsing
type CommentParser struct {
GithubUser string
GithubToken string
GitlabUser string
GitlabToken string
GithubUser string
GitlabUser string
BitbucketUser string
}

// CommentParseResult describes the result of parsing a comment as a command.
Expand Down Expand Up @@ -117,9 +116,14 @@ func (e *CommentParser) Parse(comment string, vcsHost models.VCSHostType) Commen

// Atlantis can be invoked using the name of the VCS host user we're
// running under. Need to be able to match against that user.
vcsUser := e.GithubUser
if vcsHost == models.Gitlab {
var vcsUser string
switch vcsHost {
case models.Github:
vcsUser = e.GithubUser
case models.Gitlab:
vcsUser = e.GitlabUser
case models.BitbucketCloud, models.BitbucketServer:
vcsUser = e.BitbucketUser
}
executableNames := []string{"run", atlantisExecutable, "@" + vcsUser}
if !e.stringInSlice(args[0], executableNames) {
Expand Down
42 changes: 38 additions & 4 deletions server/events/comment_parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,8 @@ import (
)

var commentParser = events.CommentParser{
GithubUser: "github-user",
GithubToken: "github-token",
GitlabUser: "gitlab-user",
GitlabToken: "gitlab-token",
GithubUser: "github-user",
GitlabUser: "gitlab-user",
}

func TestParse_Ignored(t *testing.T) {
Expand Down Expand Up @@ -644,6 +642,42 @@ func TestBuildPlanApplyComment(t *testing.T) {
}
}

func TestParse_VCSUsername(t *testing.T) {
cp := events.CommentParser{
GithubUser: "gh",
GitlabUser: "gl",
BitbucketUser: "bb",
}
cases := []struct {
vcs models.VCSHostType
user string
}{
{
vcs: models.Github,
user: "gh",
},
{
vcs: models.Gitlab,
user: "gl",
},
{
vcs: models.BitbucketServer,
user: "bb",
},
{
vcs: models.BitbucketCloud,
user: "bb",
},
}

for _, c := range cases {
t.Run(c.vcs.String(), func(t *testing.T) {
r := cp.Parse(fmt.Sprintf("@%s %s", c.user, "help"), c.vcs)
Equals(t, events.HelpComment, r.CommentResponse)
})
}
}

var PlanUsage = `Usage of plan:
-d, --dir string Which directory to run plan in relative to root of repo,
ex. 'child/dir'.
Expand Down
6 changes: 2 additions & 4 deletions server/events_controller_e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -368,10 +368,8 @@ func setupE2E(t *testing.T) (server.EventsController, *vcsmocks.MockClient, *moc
GitlabToken: "gitlab-token",
}
commentParser := &events.CommentParser{
GithubUser: "github-user",
GithubToken: "github-token",
GitlabUser: "gitlab-user",
GitlabToken: "gitlab-token",
GithubUser: "github-user",
GitlabUser: "gitlab-user",
}
terraformClient, err := terraform.NewClient(dataDir, "")
Ok(t, err)
Expand Down
7 changes: 3 additions & 4 deletions server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,10 +217,9 @@ func NewServer(userConfig UserConfig, config Config) (*Server, error) {
BitbucketServerURL: userConfig.BitbucketBaseURL,
}
commentParser := &events.CommentParser{
GithubUser: userConfig.GithubUser,
GithubToken: userConfig.GithubToken,
GitlabUser: userConfig.GitlabUser,
GitlabToken: userConfig.GitlabToken,
GithubUser: userConfig.GithubUser,
GitlabUser: userConfig.GitlabUser,
BitbucketUser: userConfig.BitbucketUser,
}
defaultTfVersion := terraformClient.Version()
pendingPlanFinder := &events.DefaultPendingPlanFinder{}
Expand Down

0 comments on commit 11b97a4

Please sign in to comment.