mirror of
https://github.com/lukaszraczylo/semver-generator.git
synced 2026-06-20 01:51:22 +00:00
Compare commits
5 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 67d110295f | |||
| 5c63edcc2e | |||
|
1bf33c3a65
|
|||
| 3859fe0469 | |||
| ac953ab411 |
@@ -78,6 +78,7 @@ Flags:
|
|||||||
-h, --help help for semver-gen
|
-h, --help help for semver-gen
|
||||||
-l, --local Use local repository
|
-l, --local Use local repository
|
||||||
-r, --repository string Remote repository URL. (default "https://github.com/lukaszraczylo/simple-gql-client")
|
-r, --repository string Remote repository URL. (default "https://github.com/lukaszraczylo/simple-gql-client")
|
||||||
|
-b, --branch string Remote repository URL Branch. (default "main")
|
||||||
-s, --strict Strict matching
|
-s, --strict Strict matching
|
||||||
-u, --update Update binary with latest
|
-u, --update Update binary with latest
|
||||||
-v, --version Display version
|
-v, --version Display version
|
||||||
|
|||||||
+5
-2
@@ -70,6 +70,7 @@ type SemVer struct {
|
|||||||
type Setup struct {
|
type Setup struct {
|
||||||
RepositoryHandler *git.Repository
|
RepositoryHandler *git.Repository
|
||||||
RepositoryName string
|
RepositoryName string
|
||||||
|
RepositoryBranch string
|
||||||
RepositoryLocalPath string
|
RepositoryLocalPath string
|
||||||
LocalConfigFile string
|
LocalConfigFile string
|
||||||
Wording Wording
|
Wording Wording
|
||||||
@@ -247,10 +248,12 @@ func (s *Setup) Prepare() error {
|
|||||||
fmt.Println("Unable to parse repository URL", s.RepositoryName, "Error:", err.Error())
|
fmt.Println("Unable to parse repository URL", s.RepositoryName, "Error:", err.Error())
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
s.RepositoryLocalPath = fmt.Sprintf("/tmp/semver/%s", u.Path)
|
s.RepositoryLocalPath = fmt.Sprintf("/tmp/semver/%s/%s", u.Path, s.RepositoryBranch)
|
||||||
os.RemoveAll(s.RepositoryLocalPath)
|
os.RemoveAll(s.RepositoryLocalPath)
|
||||||
s.RepositoryHandler, err = git.PlainClone(s.RepositoryLocalPath, false, &git.CloneOptions{
|
s.RepositoryHandler, err = git.PlainClone(s.RepositoryLocalPath, false, &git.CloneOptions{
|
||||||
URL: s.RepositoryName,
|
URL: s.RepositoryName,
|
||||||
|
ReferenceName: plumbing.NewBranchReferenceName(s.RepositoryBranch),
|
||||||
|
SingleBranch: true,
|
||||||
Auth: &http.BasicAuth{
|
Auth: &http.BasicAuth{
|
||||||
Username: os.Getenv("GITHUB_USERNAME"),
|
Username: os.Getenv("GITHUB_USERNAME"),
|
||||||
Password: os.Getenv("GITHUB_TOKEN"),
|
Password: os.Getenv("GITHUB_TOKEN"),
|
||||||
|
|||||||
+22
-5
@@ -39,6 +39,7 @@ func (suite *Tests) SetupTest() {
|
|||||||
os.Chdir(testCurrentPath)
|
os.Chdir(testCurrentPath)
|
||||||
assert = assertions.New(suite.T())
|
assert = assertions.New(suite.T())
|
||||||
params.varDebug = true
|
params.varDebug = true
|
||||||
|
params.varRepoBranch = "main"
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestSuite(t *testing.T) {
|
func TestSuite(t *testing.T) {
|
||||||
@@ -286,6 +287,7 @@ func (suite *Tests) TestSetup_ListCommits() {
|
|||||||
type fields struct {
|
type fields struct {
|
||||||
RepositoryHandler *git.Repository
|
RepositoryHandler *git.Repository
|
||||||
RepositoryName string
|
RepositoryName string
|
||||||
|
RepositoryBranch string
|
||||||
RepositoryLocalPath string
|
RepositoryLocalPath string
|
||||||
LocalConfigFile string
|
LocalConfigFile string
|
||||||
Wording Wording
|
Wording Wording
|
||||||
@@ -303,7 +305,8 @@ func (suite *Tests) TestSetup_ListCommits() {
|
|||||||
{
|
{
|
||||||
name: "List commits from existing repository",
|
name: "List commits from existing repository",
|
||||||
fields: fields{
|
fields: fields{
|
||||||
RepositoryName: "https://github.com/lukaszraczylo/simple-gql-client",
|
RepositoryName: "https://github.com/lukaszraczylo/simple-gql-client",
|
||||||
|
RepositoryBranch: "master",
|
||||||
},
|
},
|
||||||
noCommits: false,
|
noCommits: false,
|
||||||
wantErr: false,
|
wantErr: false,
|
||||||
@@ -311,7 +314,8 @@ func (suite *Tests) TestSetup_ListCommits() {
|
|||||||
{
|
{
|
||||||
name: "List commits from non-existing repository",
|
name: "List commits from non-existing repository",
|
||||||
fields: fields{
|
fields: fields{
|
||||||
RepositoryName: "https://github.com/lukaszraczylo/simple-gql-client-dead",
|
RepositoryName: "https://github.com/lukaszraczylo/simple-gql-client-dead",
|
||||||
|
RepositoryBranch: "main",
|
||||||
},
|
},
|
||||||
noCommits: true,
|
noCommits: true,
|
||||||
wantErr: true,
|
wantErr: true,
|
||||||
@@ -319,7 +323,8 @@ func (suite *Tests) TestSetup_ListCommits() {
|
|||||||
{
|
{
|
||||||
name: "List commits starting with certain hash",
|
name: "List commits starting with certain hash",
|
||||||
fields: fields{
|
fields: fields{
|
||||||
RepositoryName: "https://github.com/lukaszraczylo/simple-gql-client",
|
RepositoryName: "https://github.com/lukaszraczylo/simple-gql-client",
|
||||||
|
RepositoryBranch: "master",
|
||||||
Force: Force{
|
Force: Force{
|
||||||
Commit: "f6ee82113afb32ee95eac892d1155582a2f85166",
|
Commit: "f6ee82113afb32ee95eac892d1155582a2f85166",
|
||||||
},
|
},
|
||||||
@@ -333,6 +338,7 @@ func (suite *Tests) TestSetup_ListCommits() {
|
|||||||
s := &Setup{}
|
s := &Setup{}
|
||||||
s.ReadConfig(tt.fields.LocalConfigFile)
|
s.ReadConfig(tt.fields.LocalConfigFile)
|
||||||
s.RepositoryName = tt.fields.RepositoryName
|
s.RepositoryName = tt.fields.RepositoryName
|
||||||
|
s.RepositoryBranch = tt.fields.RepositoryBranch
|
||||||
s.Force = tt.fields.Force
|
s.Force = tt.fields.Force
|
||||||
s.Prepare()
|
s.Prepare()
|
||||||
listOfCommits, err := s.ListCommits()
|
listOfCommits, err := s.ListCommits()
|
||||||
@@ -349,6 +355,7 @@ func (suite *Tests) TestSetup_ListCommits() {
|
|||||||
func (suite *Tests) TestSetup_CalculateSemver() {
|
func (suite *Tests) TestSetup_CalculateSemver() {
|
||||||
type fields struct {
|
type fields struct {
|
||||||
RepositoryName string
|
RepositoryName string
|
||||||
|
BranchName string
|
||||||
LocalConfigFile string
|
LocalConfigFile string
|
||||||
Force Force
|
Force Force
|
||||||
}
|
}
|
||||||
@@ -368,6 +375,7 @@ func (suite *Tests) TestSetup_CalculateSemver() {
|
|||||||
fields: fields{
|
fields: fields{
|
||||||
RepositoryName: "https://github.com/lukaszraczylo/semver-generator-test-repo",
|
RepositoryName: "https://github.com/lukaszraczylo/semver-generator-test-repo",
|
||||||
LocalConfigFile: "meta.yaml",
|
LocalConfigFile: "meta.yaml",
|
||||||
|
BranchName: "main",
|
||||||
},
|
},
|
||||||
strictMatching: false,
|
strictMatching: false,
|
||||||
wantSemver: wantSemver{
|
wantSemver: wantSemver{
|
||||||
@@ -381,6 +389,7 @@ func (suite *Tests) TestSetup_CalculateSemver() {
|
|||||||
fields: fields{
|
fields: fields{
|
||||||
RepositoryName: "https://github.com/lukaszraczylo/semver-generator-test-repo",
|
RepositoryName: "https://github.com/lukaszraczylo/semver-generator-test-repo",
|
||||||
LocalConfigFile: "meta.yaml",
|
LocalConfigFile: "meta.yaml",
|
||||||
|
BranchName: "main",
|
||||||
},
|
},
|
||||||
strictMatching: true,
|
strictMatching: true,
|
||||||
wantSemver: wantSemver{
|
wantSemver: wantSemver{
|
||||||
@@ -394,6 +403,7 @@ func (suite *Tests) TestSetup_CalculateSemver() {
|
|||||||
fields: fields{
|
fields: fields{
|
||||||
RepositoryName: "https://github.com/lukaszraczylo/semver-generator-test-repo",
|
RepositoryName: "https://github.com/lukaszraczylo/semver-generator-test-repo",
|
||||||
LocalConfigFile: "meta.yaml",
|
LocalConfigFile: "meta.yaml",
|
||||||
|
BranchName: "main",
|
||||||
Force: Force{
|
Force: Force{
|
||||||
Major: 1,
|
Major: 1,
|
||||||
Minor: 1,
|
Minor: 1,
|
||||||
@@ -412,6 +422,7 @@ func (suite *Tests) TestSetup_CalculateSemver() {
|
|||||||
fields: fields{
|
fields: fields{
|
||||||
RepositoryName: "https://github.com/lukaszraczylo/semver-generator-test-repo",
|
RepositoryName: "https://github.com/lukaszraczylo/semver-generator-test-repo",
|
||||||
LocalConfigFile: "meta.yaml",
|
LocalConfigFile: "meta.yaml",
|
||||||
|
BranchName: "main",
|
||||||
Force: Force{
|
Force: Force{
|
||||||
Major: 1,
|
Major: 1,
|
||||||
Minor: 1,
|
Minor: 1,
|
||||||
@@ -442,6 +453,7 @@ func (suite *Tests) TestSetup_CalculateSemver() {
|
|||||||
s := &Setup{}
|
s := &Setup{}
|
||||||
s.ReadConfig(tt.fields.LocalConfigFile)
|
s.ReadConfig(tt.fields.LocalConfigFile)
|
||||||
s.RepositoryName = tt.fields.RepositoryName
|
s.RepositoryName = tt.fields.RepositoryName
|
||||||
|
s.RepositoryBranch = tt.fields.BranchName
|
||||||
s.Prepare()
|
s.Prepare()
|
||||||
s.ForcedVersioning()
|
s.ForcedVersioning()
|
||||||
s.Force = tt.fields.Force
|
s.Force = tt.fields.Force
|
||||||
@@ -480,6 +492,7 @@ func (suite *Tests) Test_debugPrint() {
|
|||||||
func (suite *Tests) Test_main() {
|
func (suite *Tests) Test_main() {
|
||||||
type vars struct {
|
type vars struct {
|
||||||
varRepoName string
|
varRepoName string
|
||||||
|
varRepoBranch string
|
||||||
varLocalCfg string
|
varLocalCfg string
|
||||||
varUseLocal bool
|
varUseLocal bool
|
||||||
varShowVersion bool
|
varShowVersion bool
|
||||||
@@ -586,6 +599,7 @@ func (suite *Tests) TestSetup_ListExistingTags() {
|
|||||||
type fields struct {
|
type fields struct {
|
||||||
RepositoryHandler *git.Repository
|
RepositoryHandler *git.Repository
|
||||||
RepositoryName string
|
RepositoryName string
|
||||||
|
RepositoryBranch string
|
||||||
RepositoryLocalPath string
|
RepositoryLocalPath string
|
||||||
LocalConfigFile string
|
LocalConfigFile string
|
||||||
Wording Wording
|
Wording Wording
|
||||||
@@ -602,14 +616,16 @@ func (suite *Tests) TestSetup_ListExistingTags() {
|
|||||||
{
|
{
|
||||||
name: "List tags from existing repository",
|
name: "List tags from existing repository",
|
||||||
fields: fields{
|
fields: fields{
|
||||||
RepositoryName: "https://github.com/lukaszraczylo/simple-gql-client",
|
RepositoryName: "https://github.com/lukaszraczylo/simple-gql-client",
|
||||||
|
RepositoryBranch: "master",
|
||||||
},
|
},
|
||||||
noTags: false,
|
noTags: false,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "List tags from non-existing repository",
|
name: "List tags from non-existing repository",
|
||||||
fields: fields{
|
fields: fields{
|
||||||
RepositoryName: "https://github.com/lukaszraczylo/simple-gql-client-dead",
|
RepositoryName: "https://github.com/lukaszraczylo/simple-gql-client-dead",
|
||||||
|
RepositoryBranch: "master",
|
||||||
},
|
},
|
||||||
noTags: true,
|
noTags: true,
|
||||||
},
|
},
|
||||||
@@ -619,6 +635,7 @@ func (suite *Tests) TestSetup_ListExistingTags() {
|
|||||||
s := &Setup{}
|
s := &Setup{}
|
||||||
s.ReadConfig(tt.fields.LocalConfigFile)
|
s.ReadConfig(tt.fields.LocalConfigFile)
|
||||||
s.RepositoryName = tt.fields.RepositoryName
|
s.RepositoryName = tt.fields.RepositoryName
|
||||||
|
s.RepositoryBranch = tt.fields.RepositoryBranch
|
||||||
s.Force = tt.fields.Force
|
s.Force = tt.fields.Force
|
||||||
s.Prepare()
|
s.Prepare()
|
||||||
s.ListExistingTags()
|
s.ListExistingTags()
|
||||||
|
|||||||
+10
-1
@@ -5,7 +5,7 @@ Licensed under the Apache License, Version 2.0 (the "License");
|
|||||||
you may not use this file except in compliance with the License.
|
you may not use this file except in compliance with the License.
|
||||||
You may obtain a copy of the License at
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
http://www.apache.org/licenses/LICENSE-2.0
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
Unless required by applicable law or agreed to in writing, software
|
Unless required by applicable law or agreed to in writing, software
|
||||||
distributed under the License is distributed on an "AS IS" BASIS,
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
@@ -16,6 +16,8 @@ limitations under the License.
|
|||||||
package cmd
|
package cmd
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
|
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -41,6 +43,11 @@ func (r *Setup) setupCobra() {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
r.RepositoryBranch, err = rootCmd.Flags().GetString("branch")
|
||||||
|
fmt.Println(">>> branch", r.RepositoryBranch)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
r.LocalConfigFile, err = rootCmd.Flags().GetString("config")
|
r.LocalConfigFile, err = rootCmd.Flags().GetString("config")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
@@ -53,6 +60,7 @@ func (r *Setup) setupCobra() {
|
|||||||
|
|
||||||
type myParams struct {
|
type myParams struct {
|
||||||
varRepoName string
|
varRepoName string
|
||||||
|
varRepoBranch string
|
||||||
varLocalCfg string
|
varLocalCfg string
|
||||||
varUseLocal bool
|
varUseLocal bool
|
||||||
varShowVersion bool
|
varShowVersion bool
|
||||||
@@ -69,6 +77,7 @@ func init() {
|
|||||||
repo = &Setup{}
|
repo = &Setup{}
|
||||||
cobra.OnInitialize(repo.setupCobra)
|
cobra.OnInitialize(repo.setupCobra)
|
||||||
rootCmd.PersistentFlags().StringVarP(¶ms.varRepoName, "repository", "r", "https://github.com/lukaszraczylo/simple-gql-client", "Remote repository URL.")
|
rootCmd.PersistentFlags().StringVarP(¶ms.varRepoName, "repository", "r", "https://github.com/lukaszraczylo/simple-gql-client", "Remote repository URL.")
|
||||||
|
rootCmd.PersistentFlags().StringVarP(¶ms.varRepoBranch, "branch", "b", "main", "Remote repository URL Branch.")
|
||||||
rootCmd.PersistentFlags().StringVarP(¶ms.varLocalCfg, "config", "c", "semver.yaml", "Path to config file")
|
rootCmd.PersistentFlags().StringVarP(¶ms.varLocalCfg, "config", "c", "semver.yaml", "Path to config file")
|
||||||
rootCmd.PersistentFlags().BoolVarP(¶ms.varUseLocal, "local", "l", false, "Use local repository")
|
rootCmd.PersistentFlags().BoolVarP(¶ms.varUseLocal, "local", "l", false, "Use local repository")
|
||||||
rootCmd.PersistentFlags().BoolVarP(¶ms.varShowVersion, "version", "v", false, "Display version")
|
rootCmd.PersistentFlags().BoolVarP(¶ms.varShowVersion, "version", "v", false, "Display version")
|
||||||
|
|||||||
@@ -18,6 +18,10 @@ if [[ ! -z "$INPUT_REPOSITORY_URL" ]]; then
|
|||||||
FLAGS="${FLAGS} -r $INPUT_REPOSITORY_URL"
|
FLAGS="${FLAGS} -r $INPUT_REPOSITORY_URL"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
if [[ ! -z "$INPUT_REPOSITORY_BRANCH" ]]; then
|
||||||
|
FLAGS="${FLAGS} -b $INPUT_REPOSITORY_BRANCH"
|
||||||
|
fi
|
||||||
|
|
||||||
if [[ ! -z "$INPUT_REPOSITORY_LOCAL" ]]; then
|
if [[ ! -z "$INPUT_REPOSITORY_LOCAL" ]]; then
|
||||||
FLAGS="${FLAGS} -l"
|
FLAGS="${FLAGS} -l"
|
||||||
fi
|
fi
|
||||||
|
|||||||
Reference in New Issue
Block a user