refactor(*): clean up code

This commit is contained in:
Nightapes
2019-06-15 23:03:27 +02:00
parent 1bc7f4bc67
commit cf0431846b
15 changed files with 517 additions and 405 deletions

View File

@@ -3,40 +3,49 @@ package cache
import (
"io/ioutil"
"path"
"gopkg.in/yaml.v2"
)
// VersionFileContent struct
type VersionFileContent struct {
Version string `yaml:"version"`
NextVersion string `yaml:"nextVersion"`
Commit string `yaml:"commit"`
Branch string `yaml:"branch"`
type ReleaseVersion struct {
Last ReleaseVersionEntry `yaml:"last"`
Next ReleaseVersionEntry `yaml:"next"`
Branch string `yaml:"branch"`
}
//VersionFileEntry struct
type ReleaseVersionEntry struct {
Commit string `yaml:"commit"`
Version string `yaml:"version"`
}
// Write version into .version
func Write(versionFileContent VersionFileContent) error {
func Write(repository string, versionFileContent ReleaseVersion) error {
completePath := path.Join(path.Dir(repository), ".version")
data, err := yaml.Marshal(&versionFileContent)
if err != nil {
return err
}
return ioutil.WriteFile(".version", data, 0644)
return ioutil.WriteFile(completePath, data, 0644)
}
// Read version into .version
func Read() (*VersionFileContent, error) {
func Read(repository string) (*ReleaseVersion, error) {
completePath := path.Join(path.Dir(repository), ".version")
content, err := ioutil.ReadFile(".version")
content, err := ioutil.ReadFile(completePath)
if err != nil {
return &VersionFileContent{}, err
return &ReleaseVersion{}, err
}
var versionFileContent VersionFileContent
var versionFileContent ReleaseVersion
err = yaml.Unmarshal(content, &versionFileContent)
if err != nil {
return &VersionFileContent{}, err
return &ReleaseVersion{}, err
}
return &versionFileContent, nil