Skip to content

Commit

Permalink
Merge pull request #77 from kolomied/enterprise-support
Browse files Browse the repository at this point in the history
GitHub Enterprise support
  • Loading branch information
giorod3 authored Mar 16, 2023
2 parents 7a44c5d + 63bd3c4 commit 5b483d4
Showing 1 changed file with 21 additions and 6 deletions.
27 changes: 21 additions & 6 deletions cmd/commenter/commenter.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"os"
"strconv"
"strings"
"net/url"

"github.com/owenrumney/go-github-pr-commenter/commenter"
)
Expand Down Expand Up @@ -47,7 +48,7 @@ func main() {
}
fmt.Printf("TFSec found %v issues\n", len(results))

c, err := commenter.NewCommenter(token, owner, repo, prNo)
c, err := createCommenter(token, owner, repo, prNo)
if err != nil {
fail(fmt.Sprintf("could not connect to GitHub (%s)", err.Error()))
}
Expand Down Expand Up @@ -101,6 +102,24 @@ func main() {
}
}

func createCommenter(token, owner, repo string, prNo int) (*commenter.Commenter, error) {
var err error
var c *commenter.Commenter

githubApiUrl := os.Getenv("GITHUB_API_URL")
if githubApiUrl == "" || githubApiUrl == "https://api.github.com" {
c, err = commenter.NewCommenter(token, owner, repo, prNo)
} else {
url, err := url.Parse(githubApiUrl)
if err == nil {
enterpriseUrl := fmt.Sprintf("%s://%s", url.Scheme, url.Hostname())
c, err = commenter.NewEnterpriseCommenter(token, enterpriseUrl, enterpriseUrl, owner, repo, prNo)
}
}

return c, err
}

func generateErrorMessage(result result) string {
return fmt.Sprintf(`:warning: tfsec found a **%s** severity issue from rule `+"`%s`"+`:
> %s
Expand All @@ -110,11 +129,7 @@ More information available %s`,
}

func extractPullRequestNumber() (int, error) {
github_event_file := os.Getenv("GITHUB_EVENT_PATH")
if github_event_file == "" {
github_event_file = "/github/workflow/event.json"
}

github_event_file := "/github/workflow/event.json"
file, err := ioutil.ReadFile(github_event_file)
if err != nil {
fail(fmt.Sprintf("GitHub event payload not found in %s", github_event_file))
Expand Down

0 comments on commit 5b483d4

Please sign in to comment.