Skip to content

Commit

Permalink
feat: improve mock data
Browse files Browse the repository at this point in the history
  • Loading branch information
christophwitzko committed Oct 20, 2023
1 parent d60dd41 commit da0d7b4
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 16 deletions.
7 changes: 6 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,14 @@ module github.com/go-semantic-release/mock-plugin

go 1.21

require github.com/go-semantic-release/semantic-release/v2 v2.28.0
require (
github.com/go-semantic-release/semantic-release/v2 v2.28.0
github.com/stretchr/testify v1.8.4
)

require (
github.com/Masterminds/semver/v3 v3.2.1 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/fatih/color v1.15.0 // indirect
github.com/fsnotify/fsnotify v1.6.0 // indirect
github.com/golang/protobuf v1.5.3 // indirect
Expand All @@ -21,6 +25,7 @@ require (
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/oklog/run v1.1.0 // indirect
github.com/pelletier/go-toml/v2 v2.1.0 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/spf13/afero v1.9.5 // indirect
github.com/spf13/cast v1.5.1 // indirect
github.com/spf13/cobra v1.7.0 // indirect
Expand Down
1 change: 1 addition & 0 deletions mock/commit_analyzer.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ func analyzeCommit(rawCommit *semrel.RawCommit) *semrel.Commit {
msg = splitMessages[0]
cType = ""
}
rawCommit.Annotations["mock"] = "true"
return &semrel.Commit{
SHA: rawCommit.SHA,
Raw: splitMessages,
Expand Down
2 changes: 1 addition & 1 deletion mock/files_updater.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import "github.com/go-semantic-release/semantic-release/v2/pkg/updater"
var _ updater.FilesUpdater = &Mock{}

func (m *Mock) ForFiles() string {
m.Log.Println("listing files to update")
m.Log.Println("allowing *.mock files")
return ".*\\.mock"
}

Expand Down
41 changes: 27 additions & 14 deletions mock/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,35 +19,48 @@ func (m *Mock) GetInfo() (*provider.RepositoryInfo, error) {

func (m *Mock) GetCommits(fromSha, toSha string) ([]*semrel.RawCommit, error) {
m.Log.Printf("getting commits from %s to %s", fromSha, toSha)
annotations := map[string]string{
"mock": "true",
"author_name": "mock",
}
return []*semrel.RawCommit{
{
SHA: "1",
RawMessage: "feat: add feature",
Annotations: map[string]string{
"author_name": "mock",
},
SHA: "1",
RawMessage: "feat: add feature",
Annotations: annotations,
},
{
SHA: "2",
RawMessage: "fix: bug fix",
Annotations: map[string]string{
"author_name": "mock",
},
SHA: "2",
RawMessage: "fix: bug fix",
Annotations: annotations,
},
{
SHA: "2",
RawMessage: "chore: update dependencies",
Annotations: annotations,
},
}, nil
}

func (m *Mock) GetReleases(re string) ([]*semrel.Release, error) {
m.Log.Printf("getting releases: %s", re)
func (m *Mock) GetReleases(rawRe string) ([]*semrel.Release, error) {
m.Log.Printf("getting releases (%s)", rawRe)
return []*semrel.Release{
{
SHA: "0",
SHA: "a",
Version: "1.0.0",
},
{
SHA: "b",
Version: "1.1.0",
},
{
SHA: "c",
Version: "1.1.1",
},
}, nil
}

func (m *Mock) CreateRelease(rc *provider.CreateReleaseConfig) error {
m.Log.Printf("creating release: %s", rc.NewVersion)
m.Log.Printf("creating release %s on branch %s", rc.NewVersion, rc.Branch)
return nil
}

0 comments on commit da0d7b4

Please sign in to comment.