From 134984f24d939e41335de552fe532fac4b99ba3a Mon Sep 17 00:00:00 2001 From: Fallion Date: Wed, 17 Jun 2020 22:07:44 +0200 Subject: [PATCH] fix: remove hardcoded repository name --- .github/workflows/linters.yml | 2 -- internal/root_runner/run_pr.go | 9 ++++++++- www/docs/usage/github.md | 2 ++ 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/.github/workflows/linters.yml b/.github/workflows/linters.yml index 9cd776f2..e3bbb90b 100644 --- a/.github/workflows/linters.yml +++ b/.github/workflows/linters.yml @@ -18,8 +18,6 @@ jobs: - run: go mod download - name: Run Commitsar run: go run main.go - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} golangci-lint: name: runner / golangci-lint diff --git a/internal/root_runner/run_pr.go b/internal/root_runner/run_pr.go index d42c27dd..0ce6abe9 100644 --- a/internal/root_runner/run_pr.go +++ b/internal/root_runner/run_pr.go @@ -5,6 +5,7 @@ import ( "errors" "io/ioutil" "log" + "strings" "golang.org/x/oauth2" @@ -18,6 +19,12 @@ import ( func (runner *Runner) RunPullRequest(jiraKeys []string) ([]string, error) { ghToken := viper.GetString("GITHUB_TOKEN") + if !viper.IsSet("GITHUB_REPOSITORY") { + return nil, errors.New("missing GITHUB_REPOSITORY env variable. Please provide one in owner/repository format") + } + + split := strings.Split(viper.GetString("GITHUB_REPOSITORY"), "/") + gitRepo, err := history.OpenGit(".", log.New(ioutil.Discard, "", 0)) if err != nil { @@ -39,7 +46,7 @@ func (runner *Runner) RunPullRequest(jiraKeys []string) ([]string, error) { return nil, err } - prs, response, err := client.PullRequests.ListPullRequestsWithCommit(ctx, "aevea", "commitsar", currentCommit.Hash.String(), nil) + prs, response, err := client.PullRequests.ListPullRequestsWithCommit(ctx, split[0], split[1], currentCommit.Hash.String(), nil) if err != nil { return nil, err diff --git a/www/docs/usage/github.md b/www/docs/usage/github.md index 80455bf7..241e75c6 100644 --- a/www/docs/usage/github.md +++ b/www/docs/usage/github.md @@ -72,4 +72,6 @@ validate-commits: ref: ${{ github.event.pull_request.head.sha }} - name: Commitsar check uses: docker://aevea/commitsar + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} ```