Skip to content

Commit

Permalink
Merge pull request #78 from aquasecurity/azure-params
Browse files Browse the repository at this point in the history
Add azure params from outside to Azure commenter
  • Loading branch information
davidsalame1 authored Apr 8, 2024
2 parents decbf40 + 62619bf commit 4338d16
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 8 deletions.
13 changes: 12 additions & 1 deletion pkg/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,20 @@ func NewApp() *cli.App {
Name: "owner",
Usage: "The repo owner",
},
&cli.StringFlag{
Name: "project",
Usage: "The project name (azure)",
},
&cli.StringFlag{
Name: "collection-url",
Usage: "The collection url (azure)",
},
&cli.StringFlag{
Name: "repo-id",
Usage: "The repository ID (azure)",
},
},
},
}

return app
}
5 changes: 3 additions & 2 deletions pkg/app/commenter.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@ package app

import (
"fmt"
"os"

"github.com/aquasecurity/go-git-pr-commenter/pkg/commenter"
"github.com/aquasecurity/go-git-pr-commenter/pkg/commenter/azure"
"github.com/aquasecurity/go-git-pr-commenter/pkg/commenter/bitbucket"
"github.com/aquasecurity/go-git-pr-commenter/pkg/commenter/github"
"github.com/aquasecurity/go-git-pr-commenter/pkg/commenter/gitlab"
"github.com/aquasecurity/go-git-pr-commenter/pkg/commenter/mock"
"github.com/urfave/cli/v2"
"os"
)

func Action(ctx *cli.Context) (err error) {
Expand All @@ -34,7 +35,7 @@ func Action(ctx *cli.Context) (err error) {
c = commenter.Repository(r)
case "azure":
token := os.Getenv("AZURE_TOKEN")
r, err := azure.NewAzure(token)
r, err := azure.NewAzure(token, ctx.String("project"), ctx.String("collection-url"), ctx.String("repo-id"), ctx.String("pr-number"))
if err != nil {
return err
}
Expand Down
26 changes: 21 additions & 5 deletions pkg/commenter/azure/azure.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,30 @@ type Comment struct {
Content string `json:"content,omitempty"`
}

func NewAzure(token string) (b *Azure, err error) {
func NewAzure(token, project, collectionUrl, repoId, prNumber string) (b *Azure, err error) {
projectNameParm := project
if projectNameParm == "" {
projectNameParm = os.Getenv("SYSTEM_TEAMPROJECT")
}
apiURLParam := collectionUrl
if apiURLParam == "" {
apiURLParam = os.Getenv("SYSTEM_COLLECTIONURI")
}
repoIDParam := repoId
if repoIDParam == "" {
repoIDParam = os.Getenv("BUILD_REPOSITORY_ID")
}
prNumberParam := prNumber
if prNumberParam == "" {
prNumberParam = os.Getenv("SYSTEM_PULLREQUEST_PULLREQUESTID")
}

return &Azure{
Project: os.Getenv("SYSTEM_TEAMPROJECT"),
ApiUrl: os.Getenv("SYSTEM_COLLECTIONURI"),
Project: projectNameParm,
ApiUrl: apiURLParam,
Token: token,
RepoID: os.Getenv("BUILD_REPOSITORY_ID"),
PrNumber: os.Getenv("SYSTEM_PULLREQUEST_PULLREQUESTID"),
RepoID: repoIDParam,
PrNumber: prNumberParam,
}, nil
}

Expand Down

0 comments on commit 4338d16

Please sign in to comment.