Skip to content

Commit

Permalink
refactor(github): decouple trellogithub and "github.com/google/go-git…
Browse files Browse the repository at this point in the history
…hub/v42/github"

closes devstream-io#307
  • Loading branch information
warren830 committed Mar 12, 2022
1 parent b9b60b8 commit 26d444d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
10 changes: 3 additions & 7 deletions internal/pkg/plugin/trellogithub/github.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,10 @@ import (
"net/http"
"strings"

githubx "github.com/google/go-github/v42/github"
"github.com/spf13/viper"

"github.com/merico-dev/stream/pkg/util/github"
"github.com/merico-dev/stream/pkg/util/log"
"github.com/merico-dev/stream/pkg/util/mapz"
"github.com/spf13/viper"
)

// VerifyWorkflows get the workflows with names "wf1.yml", "wf2.yml", then:
Expand All @@ -37,12 +35,11 @@ func (tg *TrelloGithub) VerifyWorkflows(workflows []*github.Workflow) (map[strin

func (tg *TrelloGithub) FetchRemoteContent(wsFiles []string) ([]string, map[string]error, error) {
var filesInRemoteDir = make([]string, 0)
_, dirContent, resp, err := tg.client.Repositories.GetContents(
dirContent, resp, err := tg.client.GetContents(
tg.ctx,
tg.options.Owner,
tg.options.Repo,
".github/workflows",
&githubx.RepositoryContentGetOptions{},
)

// error reason is not 404
Expand Down Expand Up @@ -119,12 +116,11 @@ func (tg *TrelloGithub) AddTrelloIdSecret(trelloId *TrelloItemId) error {
}

func (tg *TrelloGithub) GetWorkflowPath() (string, error) {
_, _, resp, err := tg.client.Repositories.GetContents(
_, resp, err := tg.client.GetContents(
tg.ctx,
tg.options.Owner,
tg.options.Repo,
".github/workflows",
&githubx.RepositoryContentGetOptions{},
)

// error reason is not 404
Expand Down
10 changes: 9 additions & 1 deletion pkg/util/github/github.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"fmt"
"os"

"github.com/google/go-github/v42/github"
github "github.com/google/go-github/v42/github"
"golang.org/x/oauth2"

"github.com/merico-dev/stream/pkg/util/log"
Expand Down Expand Up @@ -99,3 +99,11 @@ func NewClient(option *Option) (*Client, error) {

return client, nil
}

func (*Client) GetContents(ctx context.Context, owner string, repo string, path string) ([]*github.RepositoryContent, *github.Response, error) {
_, dirContent, resp, err := client.Repositories.GetContents(
ctx, owner, repo, path,
&github.RepositoryContentGetOptions{},
)
return dirContent, resp, err
}

0 comments on commit 26d444d

Please sign in to comment.