Skip to content

Commit

Permalink
Refactor packages (#75)
Browse files Browse the repository at this point in the history
* Refactor: move di package

* Refactor: move adaptor packages

* Refactor: move github client package

* Refactor: move git package

* Refactor: move usecase packages

* Refactor: fix import alias
  • Loading branch information
int128 authored Jan 23, 2021
1 parent d041807 commit 7552549
Show file tree
Hide file tree
Showing 51 changed files with 227 additions and 227 deletions.
46 changes: 0 additions & 46 deletions di/di.go

This file was deleted.

2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package main
import (
"os"

"github.com/int128/ghcp/di"
"github.com/int128/ghcp/pkg/di"
)

var version = "HEAD"
Expand Down
20 changes: 10 additions & 10 deletions adaptors/cmd/cmd.go → pkg/cmd/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ import (
"fmt"

"github.com/google/wire"
"github.com/int128/ghcp/adaptors/env"
"github.com/int128/ghcp/adaptors/logger"
"github.com/int128/ghcp/infrastructure/github"
"github.com/int128/ghcp/usecases/commit"
"github.com/int128/ghcp/usecases/forkcommit"
"github.com/int128/ghcp/usecases/pullrequest"
"github.com/int128/ghcp/usecases/release"
"github.com/int128/ghcp/pkg/env"
"github.com/int128/ghcp/pkg/github/client"
"github.com/int128/ghcp/pkg/logger"
"github.com/int128/ghcp/pkg/usecases/commit"
"github.com/int128/ghcp/pkg/usecases/forkcommit"
"github.com/int128/ghcp/pkg/usecases/pullrequest"
"github.com/int128/ghcp/pkg/usecases/release"
"github.com/spf13/cobra"
"github.com/spf13/pflag"
"golang.org/x/xerrors"
Expand Down Expand Up @@ -47,7 +47,7 @@ type Interface interface {
type Runner struct {
Env env.Interface
NewLogger logger.NewFunc
NewGitHub github.NewFunc
NewGitHub client.NewFunc
NewInternalRunner NewInternalRunnerFunc
}

Expand Down Expand Up @@ -100,7 +100,7 @@ func (r *Runner) newRootCmd(o *globalOptions) *cobra.Command {
return c
}

type NewInternalRunnerFunc func(logger.Interface, github.Interface) *InternalRunner
type NewInternalRunnerFunc func(logger.Interface, client.Interface) *InternalRunner

// InternalRunner has the set of use-cases.
type InternalRunner struct {
Expand Down Expand Up @@ -134,7 +134,7 @@ func (r *Runner) newInternalRunner(o *globalOptions) (*InternalRunner, error) {
log.Debugf("Using GitHub Enterprise URL from environment variable $%s", envGitHubAPI)
}
}
gh, err := r.NewGitHub(github.Option{
gh, err := r.NewGitHub(client.Option{
Token: o.GitHubToken,
URLv3: o.GitHubAPI,
})
Expand Down
76 changes: 38 additions & 38 deletions adaptors/cmd/cmd_test.go → pkg/cmd/cmd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,20 @@ import (
"github.com/golang/mock/gomock"
"github.com/google/go-cmp/cmp"

"github.com/int128/ghcp/adaptors/env/mock_env"
"github.com/int128/ghcp/adaptors/logger"
testingLogger "github.com/int128/ghcp/adaptors/logger/testing"
"github.com/int128/ghcp/domain/git"
"github.com/int128/ghcp/domain/git/commitstrategy"
"github.com/int128/ghcp/infrastructure/github"
"github.com/int128/ghcp/usecases/commit"
"github.com/int128/ghcp/usecases/commit/mock_commit"
"github.com/int128/ghcp/usecases/forkcommit"
"github.com/int128/ghcp/usecases/forkcommit/mock_forkcommit"
"github.com/int128/ghcp/usecases/pullrequest"
"github.com/int128/ghcp/usecases/pullrequest/mock_pullrequest"
"github.com/int128/ghcp/usecases/release"
"github.com/int128/ghcp/usecases/release/mock_release"
"github.com/int128/ghcp/pkg/env/mock_env"
"github.com/int128/ghcp/pkg/git"
"github.com/int128/ghcp/pkg/git/commitstrategy"
"github.com/int128/ghcp/pkg/github/client"
"github.com/int128/ghcp/pkg/logger"
testingLogger "github.com/int128/ghcp/pkg/logger/testing"
"github.com/int128/ghcp/pkg/usecases/commit"
"github.com/int128/ghcp/pkg/usecases/commit/mock_commit"
"github.com/int128/ghcp/pkg/usecases/forkcommit"
"github.com/int128/ghcp/pkg/usecases/forkcommit/mock_forkcommit"
"github.com/int128/ghcp/pkg/usecases/pullrequest"
"github.com/int128/ghcp/pkg/usecases/pullrequest/mock_pullrequest"
"github.com/int128/ghcp/pkg/usecases/release"
"github.com/int128/ghcp/pkg/usecases/release/mock_release"
)

func TestCmd_Run(t *testing.T) {
Expand All @@ -43,7 +43,7 @@ func TestCmd_Run(t *testing.T) {
})
r := Runner{
NewLogger: newLogger(t, logger.Option{}),
NewGitHub: newGitHub(t, github.Option{Token: "YOUR_TOKEN"}),
NewGitHub: newGitHub(t, client.Option{Token: "YOUR_TOKEN"}),
Env: newEnv(ctrl, map[string]string{envGitHubAPI: ""}),
NewInternalRunner: newInternalRunner(InternalRunner{CommitUseCase: commitUseCase}),
}
Expand Down Expand Up @@ -78,7 +78,7 @@ func TestCmd_Run(t *testing.T) {
})
r := Runner{
NewLogger: newLogger(t, logger.Option{}),
NewGitHub: newGitHub(t, github.Option{Token: "YOUR_TOKEN"}),
NewGitHub: newGitHub(t, client.Option{Token: "YOUR_TOKEN"}),
Env: newEnv(ctrl, map[string]string{envGitHubAPI: ""}),
NewInternalRunner: newInternalRunner(InternalRunner{CommitUseCase: commitUseCase}),
}
Expand Down Expand Up @@ -114,7 +114,7 @@ func TestCmd_Run(t *testing.T) {
})
r := Runner{
NewLogger: newLogger(t, logger.Option{}),
NewGitHub: newGitHub(t, github.Option{Token: "YOUR_TOKEN"}),
NewGitHub: newGitHub(t, client.Option{Token: "YOUR_TOKEN"}),
Env: newEnv(ctrl, map[string]string{envGitHubAPI: ""}),
NewInternalRunner: newInternalRunner(InternalRunner{CommitUseCase: commitUseCase}),
}
Expand Down Expand Up @@ -151,7 +151,7 @@ func TestCmd_Run(t *testing.T) {
})
r := Runner{
NewLogger: newLogger(t, logger.Option{}),
NewGitHub: newGitHub(t, github.Option{Token: "YOUR_TOKEN"}),
NewGitHub: newGitHub(t, client.Option{Token: "YOUR_TOKEN"}),
Env: newEnv(ctrl, map[string]string{envGitHubAPI: ""}),
NewInternalRunner: newInternalRunner(InternalRunner{CommitUseCase: commitUseCase}),
}
Expand All @@ -178,7 +178,7 @@ func TestCmd_Run(t *testing.T) {
defer ctrl.Finish()
r := Runner{
NewLogger: newLogger(t, logger.Option{}),
NewGitHub: newGitHub(t, github.Option{Token: "YOUR_TOKEN"}),
NewGitHub: newGitHub(t, client.Option{Token: "YOUR_TOKEN"}),
Env: newEnv(ctrl, nil),
NewInternalRunner: newInternalRunner(InternalRunner{}),
}
Expand Down Expand Up @@ -206,7 +206,7 @@ func TestCmd_Run(t *testing.T) {
defer ctrl.Finish()
r := Runner{
NewLogger: newLogger(t, logger.Option{}),
NewGitHub: newGitHub(t, github.Option{Token: "YOUR_TOKEN"}),
NewGitHub: newGitHub(t, client.Option{Token: "YOUR_TOKEN"}),
Env: newEnv(ctrl, nil),
NewInternalRunner: newInternalRunner(InternalRunner{}),
}
Expand All @@ -231,7 +231,7 @@ func TestCmd_Run(t *testing.T) {
defer ctrl.Finish()
r := Runner{
NewLogger: newLogger(t, logger.Option{}),
NewGitHub: newGitHub(t, github.Option{Token: "YOUR_TOKEN"}),
NewGitHub: newGitHub(t, client.Option{Token: "YOUR_TOKEN"}),
Env: newEnv(ctrl, nil),
NewInternalRunner: newInternalRunner(InternalRunner{}),
}
Expand Down Expand Up @@ -266,7 +266,7 @@ func TestCmd_Run(t *testing.T) {
})
r := Runner{
NewLogger: newLogger(t, logger.Option{}),
NewGitHub: newGitHub(t, github.Option{Token: "YOUR_TOKEN"}),
NewGitHub: newGitHub(t, client.Option{Token: "YOUR_TOKEN"}),
Env: newEnv(ctrl, map[string]string{envGitHubAPI: ""}),
NewInternalRunner: newInternalRunner(InternalRunner{CommitUseCase: commitUseCase}),
}
Expand Down Expand Up @@ -302,7 +302,7 @@ func TestCmd_Run(t *testing.T) {
})
r := Runner{
NewLogger: newLogger(t, logger.Option{}),
NewGitHub: newGitHub(t, github.Option{Token: "YOUR_TOKEN"}),
NewGitHub: newGitHub(t, client.Option{Token: "YOUR_TOKEN"}),
Env: newEnv(ctrl, map[string]string{envGitHubAPI: ""}),
NewInternalRunner: newInternalRunner(InternalRunner{CommitUseCase: commitUseCase}),
}
Expand Down Expand Up @@ -338,7 +338,7 @@ func TestCmd_Run(t *testing.T) {
})
r := Runner{
NewLogger: newLogger(t, logger.Option{}),
NewGitHub: newGitHub(t, github.Option{Token: "YOUR_TOKEN"}),
NewGitHub: newGitHub(t, client.Option{Token: "YOUR_TOKEN"}),
Env: newEnv(ctrl, map[string]string{envGitHubAPI: ""}),
NewInternalRunner: newInternalRunner(InternalRunner{CommitUseCase: commitUseCase}),
}
Expand Down Expand Up @@ -372,7 +372,7 @@ func TestCmd_Run(t *testing.T) {
})
r := Runner{
NewLogger: newLogger(t, logger.Option{}),
NewGitHub: newGitHub(t, github.Option{Token: "YOUR_TOKEN"}),
NewGitHub: newGitHub(t, client.Option{Token: "YOUR_TOKEN"}),
Env: newEnv(ctrl, map[string]string{envGitHubAPI: ""}),
NewInternalRunner: newInternalRunner(InternalRunner{ForkCommitUseCase: commitUseCase}),
}
Expand Down Expand Up @@ -407,7 +407,7 @@ func TestCmd_Run(t *testing.T) {
})
r := Runner{
NewLogger: newLogger(t, logger.Option{}),
NewGitHub: newGitHub(t, github.Option{Token: "YOUR_TOKEN"}),
NewGitHub: newGitHub(t, client.Option{Token: "YOUR_TOKEN"}),
Env: newEnv(ctrl, map[string]string{envGitHubAPI: ""}),
NewInternalRunner: newInternalRunner(InternalRunner{ForkCommitUseCase: commitUseCase}),
}
Expand Down Expand Up @@ -444,7 +444,7 @@ func TestCmd_Run(t *testing.T) {
})
r := Runner{
NewLogger: newLogger(t, logger.Option{}),
NewGitHub: newGitHub(t, github.Option{Token: "YOUR_TOKEN"}),
NewGitHub: newGitHub(t, client.Option{Token: "YOUR_TOKEN"}),
Env: newEnv(ctrl, map[string]string{envGitHubAPI: ""}),
NewInternalRunner: newInternalRunner(InternalRunner{PullRequestUseCase: useCase}),
}
Expand Down Expand Up @@ -477,7 +477,7 @@ func TestCmd_Run(t *testing.T) {
})
r := Runner{
NewLogger: newLogger(t, logger.Option{}),
NewGitHub: newGitHub(t, github.Option{Token: "YOUR_TOKEN"}),
NewGitHub: newGitHub(t, client.Option{Token: "YOUR_TOKEN"}),
Env: newEnv(ctrl, map[string]string{envGitHubAPI: ""}),
NewInternalRunner: newInternalRunner(InternalRunner{PullRequestUseCase: useCase}),
}
Expand Down Expand Up @@ -515,7 +515,7 @@ func TestCmd_Run(t *testing.T) {
})
r := Runner{
NewLogger: newLogger(t, logger.Option{}),
NewGitHub: newGitHub(t, github.Option{Token: "YOUR_TOKEN"}),
NewGitHub: newGitHub(t, client.Option{Token: "YOUR_TOKEN"}),
Env: newEnv(ctrl, map[string]string{envGitHubAPI: ""}),
NewInternalRunner: newInternalRunner(InternalRunner{ReleaseUseCase: releaseUseCase}),
}
Expand Down Expand Up @@ -554,7 +554,7 @@ func TestCmd_Run(t *testing.T) {
Do(ctx, input)
r := Runner{
NewLogger: newLogger(t, logger.Option{Debug: true}),
NewGitHub: newGitHub(t, github.Option{Token: "YOUR_TOKEN"}),
NewGitHub: newGitHub(t, client.Option{Token: "YOUR_TOKEN"}),
Env: newEnv(ctrl, map[string]string{envGitHubAPI: ""}),
NewInternalRunner: newInternalRunner(InternalRunner{CommitUseCase: commitUseCase}),
}
Expand Down Expand Up @@ -586,7 +586,7 @@ func TestCmd_Run(t *testing.T) {
Chdir("dir")
r := Runner{
NewLogger: newLogger(t, logger.Option{}),
NewGitHub: newGitHub(t, github.Option{Token: "YOUR_TOKEN"}),
NewGitHub: newGitHub(t, client.Option{Token: "YOUR_TOKEN"}),
Env: mockEnv,
NewInternalRunner: newInternalRunner(InternalRunner{CommitUseCase: commitUseCase}),
}
Expand Down Expand Up @@ -615,7 +615,7 @@ func TestCmd_Run(t *testing.T) {
Do(ctx, input)
r := Runner{
NewLogger: newLogger(t, logger.Option{}),
NewGitHub: newGitHub(t, github.Option{Token: "YOUR_TOKEN"}),
NewGitHub: newGitHub(t, client.Option{Token: "YOUR_TOKEN"}),
Env: newEnv(ctrl, map[string]string{envGitHubToken: "YOUR_TOKEN", envGitHubAPI: ""}),
NewInternalRunner: newInternalRunner(InternalRunner{CommitUseCase: commitUseCase}),
}
Expand All @@ -639,7 +639,7 @@ func TestCmd_Run(t *testing.T) {
defer ctrl.Finish()
r := Runner{
NewLogger: newLogger(t, logger.Option{}),
NewGitHub: newGitHub(t, github.Option{}),
NewGitHub: newGitHub(t, client.Option{}),
Env: newEnv(ctrl, map[string]string{envGitHubToken: ""}),
NewInternalRunner: newInternalRunner(InternalRunner{}),
}
Expand All @@ -666,7 +666,7 @@ func TestCmd_Run(t *testing.T) {
Do(ctx, input)
r := Runner{
NewLogger: newLogger(t, logger.Option{}),
NewGitHub: newGitHub(t, github.Option{Token: "YOUR_TOKEN", URLv3: "https://github.example.com/api/v3/"}),
NewGitHub: newGitHub(t, client.Option{Token: "YOUR_TOKEN", URLv3: "https://github.example.com/api/v3/"}),
Env: newEnv(ctrl, nil),
NewInternalRunner: newInternalRunner(InternalRunner{CommitUseCase: commitUseCase}),
}
Expand Down Expand Up @@ -695,7 +695,7 @@ func TestCmd_Run(t *testing.T) {
Do(ctx, input)
r := Runner{
NewLogger: newLogger(t, logger.Option{}),
NewGitHub: newGitHub(t, github.Option{Token: "YOUR_TOKEN", URLv3: "https://github.example.com/api/v3/"}),
NewGitHub: newGitHub(t, client.Option{Token: "YOUR_TOKEN", URLv3: "https://github.example.com/api/v3/"}),
Env: newEnv(ctrl, map[string]string{envGitHubAPI: "https://github.example.com/api/v3/"}),
NewInternalRunner: newInternalRunner(InternalRunner{CommitUseCase: commitUseCase}),
}
Expand Down Expand Up @@ -726,8 +726,8 @@ func newLogger(t *testing.T, want logger.Option) logger.NewFunc {
}
}

func newGitHub(t *testing.T, want github.Option) github.NewFunc {
return func(got github.Option) (github.Interface, error) {
func newGitHub(t *testing.T, want client.Option) client.NewFunc {
return func(got client.Option) (client.Interface, error) {
if diff := cmp.Diff(want, got); diff != "" {
t.Errorf("mismatch (-want +got):\n%s", diff)
}
Expand All @@ -744,7 +744,7 @@ func newEnv(ctrl *gomock.Controller, getenv map[string]string) *mock_env.MockInt
}

func newInternalRunner(base InternalRunner) NewInternalRunnerFunc {
return func(l logger.Interface, g github.Interface) *InternalRunner {
return func(l logger.Interface, g client.Interface) *InternalRunner {
base.Logger = l
return &base
}
Expand Down
6 changes: 3 additions & 3 deletions adaptors/cmd/commit.go → pkg/cmd/commit.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ import (
"github.com/spf13/pflag"
"golang.org/x/xerrors"

"github.com/int128/ghcp/domain/git"
"github.com/int128/ghcp/domain/git/commitstrategy"
"github.com/int128/ghcp/usecases/commit"
"github.com/int128/ghcp/pkg/git"
"github.com/int128/ghcp/pkg/git/commitstrategy"
"github.com/int128/ghcp/pkg/usecases/commit"
)

const commitCmdExample = ` To commit files to the default branch:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"github.com/spf13/pflag"
"golang.org/x/xerrors"

"github.com/int128/ghcp/domain/git"
"github.com/int128/ghcp/pkg/git"
)

type commitAttributeOptions struct {
Expand Down
6 changes: 3 additions & 3 deletions adaptors/cmd/empty_commit.go → pkg/cmd/empty_commit.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ import (
"github.com/spf13/pflag"
"golang.org/x/xerrors"

"github.com/int128/ghcp/domain/git"
"github.com/int128/ghcp/domain/git/commitstrategy"
"github.com/int128/ghcp/usecases/commit"
"github.com/int128/ghcp/pkg/git"
"github.com/int128/ghcp/pkg/git/commitstrategy"
"github.com/int128/ghcp/pkg/usecases/commit"
)

const emptyCommitCmdExample = ` To create an empty commit to the default branch:
Expand Down
6 changes: 3 additions & 3 deletions adaptors/cmd/forkcommit.go → pkg/cmd/forkcommit.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ import (
"github.com/spf13/pflag"
"golang.org/x/xerrors"

"github.com/int128/ghcp/domain/git"
"github.com/int128/ghcp/domain/git/commitstrategy"
"github.com/int128/ghcp/usecases/forkcommit"
"github.com/int128/ghcp/pkg/git"
"github.com/int128/ghcp/pkg/git/commitstrategy"
"github.com/int128/ghcp/pkg/usecases/forkcommit"
)

func (r *Runner) newForkCommitCmd(ctx context.Context, gOpts *globalOptions) *cobra.Command {
Expand Down
Loading

0 comments on commit 7552549

Please sign in to comment.