Compare commits

...

7 Commits

Author SHA1 Message Date
lukaszraczylo 67d110295f Merge pull request #22 from lukaszraczylo/add-branch-support
Modify tests to reflect addition of the branch flag.
2023-05-09 11:20:17 +00:00
lukaszraczylo 5c63edcc2e Merge pull request #21 from username-dorf/feat/branch-support
Add branch support for remote repository
2023-05-09 11:19:54 +00:00
lukaszraczylo 1bf33c3a65 Modify tests to reflect addition of the branch flag. 2023-05-09 12:14:49 +01:00
username-dorf 3859fe0469 Update README 2023-05-08 12:03:01 +03:00
username-dorf ac953ab411 Add branch selection for remote repo 2023-05-05 15:12:21 +03:00
lukaszraczylo 9e333c7a45 Update dependencies. 2023-04-11 13:53:17 +01:00
lukaszraczylo 80e669e5b5 Update dependencies. 2023-04-08 21:41:53 +01:00
7 changed files with 51 additions and 17 deletions
+1
View File
@@ -78,6 +78,7 @@ Flags:
-h, --help help for semver-gen
-l, --local Use local repository
-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
-u, --update Update binary with latest
-v, --version Display version
+5 -2
View File
@@ -70,6 +70,7 @@ type SemVer struct {
type Setup struct {
RepositoryHandler *git.Repository
RepositoryName string
RepositoryBranch string
RepositoryLocalPath string
LocalConfigFile string
Wording Wording
@@ -247,10 +248,12 @@ func (s *Setup) Prepare() error {
fmt.Println("Unable to parse repository URL", s.RepositoryName, "Error:", err.Error())
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)
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{
Username: os.Getenv("GITHUB_USERNAME"),
Password: os.Getenv("GITHUB_TOKEN"),
+22 -5
View File
@@ -39,6 +39,7 @@ func (suite *Tests) SetupTest() {
os.Chdir(testCurrentPath)
assert = assertions.New(suite.T())
params.varDebug = true
params.varRepoBranch = "main"
}
func TestSuite(t *testing.T) {
@@ -286,6 +287,7 @@ func (suite *Tests) TestSetup_ListCommits() {
type fields struct {
RepositoryHandler *git.Repository
RepositoryName string
RepositoryBranch string
RepositoryLocalPath string
LocalConfigFile string
Wording Wording
@@ -303,7 +305,8 @@ func (suite *Tests) TestSetup_ListCommits() {
{
name: "List commits from existing repository",
fields: fields{
RepositoryName: "https://github.com/lukaszraczylo/simple-gql-client",
RepositoryName: "https://github.com/lukaszraczylo/simple-gql-client",
RepositoryBranch: "master",
},
noCommits: false,
wantErr: false,
@@ -311,7 +314,8 @@ func (suite *Tests) TestSetup_ListCommits() {
{
name: "List commits from non-existing repository",
fields: fields{
RepositoryName: "https://github.com/lukaszraczylo/simple-gql-client-dead",
RepositoryName: "https://github.com/lukaszraczylo/simple-gql-client-dead",
RepositoryBranch: "main",
},
noCommits: true,
wantErr: true,
@@ -319,7 +323,8 @@ func (suite *Tests) TestSetup_ListCommits() {
{
name: "List commits starting with certain hash",
fields: fields{
RepositoryName: "https://github.com/lukaszraczylo/simple-gql-client",
RepositoryName: "https://github.com/lukaszraczylo/simple-gql-client",
RepositoryBranch: "master",
Force: Force{
Commit: "f6ee82113afb32ee95eac892d1155582a2f85166",
},
@@ -333,6 +338,7 @@ func (suite *Tests) TestSetup_ListCommits() {
s := &Setup{}
s.ReadConfig(tt.fields.LocalConfigFile)
s.RepositoryName = tt.fields.RepositoryName
s.RepositoryBranch = tt.fields.RepositoryBranch
s.Force = tt.fields.Force
s.Prepare()
listOfCommits, err := s.ListCommits()
@@ -349,6 +355,7 @@ func (suite *Tests) TestSetup_ListCommits() {
func (suite *Tests) TestSetup_CalculateSemver() {
type fields struct {
RepositoryName string
BranchName string
LocalConfigFile string
Force Force
}
@@ -368,6 +375,7 @@ func (suite *Tests) TestSetup_CalculateSemver() {
fields: fields{
RepositoryName: "https://github.com/lukaszraczylo/semver-generator-test-repo",
LocalConfigFile: "meta.yaml",
BranchName: "main",
},
strictMatching: false,
wantSemver: wantSemver{
@@ -381,6 +389,7 @@ func (suite *Tests) TestSetup_CalculateSemver() {
fields: fields{
RepositoryName: "https://github.com/lukaszraczylo/semver-generator-test-repo",
LocalConfigFile: "meta.yaml",
BranchName: "main",
},
strictMatching: true,
wantSemver: wantSemver{
@@ -394,6 +403,7 @@ func (suite *Tests) TestSetup_CalculateSemver() {
fields: fields{
RepositoryName: "https://github.com/lukaszraczylo/semver-generator-test-repo",
LocalConfigFile: "meta.yaml",
BranchName: "main",
Force: Force{
Major: 1,
Minor: 1,
@@ -412,6 +422,7 @@ func (suite *Tests) TestSetup_CalculateSemver() {
fields: fields{
RepositoryName: "https://github.com/lukaszraczylo/semver-generator-test-repo",
LocalConfigFile: "meta.yaml",
BranchName: "main",
Force: Force{
Major: 1,
Minor: 1,
@@ -442,6 +453,7 @@ func (suite *Tests) TestSetup_CalculateSemver() {
s := &Setup{}
s.ReadConfig(tt.fields.LocalConfigFile)
s.RepositoryName = tt.fields.RepositoryName
s.RepositoryBranch = tt.fields.BranchName
s.Prepare()
s.ForcedVersioning()
s.Force = tt.fields.Force
@@ -480,6 +492,7 @@ func (suite *Tests) Test_debugPrint() {
func (suite *Tests) Test_main() {
type vars struct {
varRepoName string
varRepoBranch string
varLocalCfg string
varUseLocal bool
varShowVersion bool
@@ -586,6 +599,7 @@ func (suite *Tests) TestSetup_ListExistingTags() {
type fields struct {
RepositoryHandler *git.Repository
RepositoryName string
RepositoryBranch string
RepositoryLocalPath string
LocalConfigFile string
Wording Wording
@@ -602,14 +616,16 @@ func (suite *Tests) TestSetup_ListExistingTags() {
{
name: "List tags from existing repository",
fields: fields{
RepositoryName: "https://github.com/lukaszraczylo/simple-gql-client",
RepositoryName: "https://github.com/lukaszraczylo/simple-gql-client",
RepositoryBranch: "master",
},
noTags: false,
},
{
name: "List tags from non-existing repository",
fields: fields{
RepositoryName: "https://github.com/lukaszraczylo/simple-gql-client-dead",
RepositoryName: "https://github.com/lukaszraczylo/simple-gql-client-dead",
RepositoryBranch: "master",
},
noTags: true,
},
@@ -619,6 +635,7 @@ func (suite *Tests) TestSetup_ListExistingTags() {
s := &Setup{}
s.ReadConfig(tt.fields.LocalConfigFile)
s.RepositoryName = tt.fields.RepositoryName
s.RepositoryBranch = tt.fields.RepositoryBranch
s.Force = tt.fields.Force
s.Prepare()
s.ListExistingTags()
+10 -1
View File
@@ -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 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
distributed under the License is distributed on an "AS IS" BASIS,
@@ -16,6 +16,8 @@ limitations under the License.
package cmd
import (
"fmt"
"github.com/spf13/cobra"
)
@@ -41,6 +43,11 @@ func (r *Setup) setupCobra() {
if err != nil {
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")
if err != nil {
panic(err)
@@ -53,6 +60,7 @@ func (r *Setup) setupCobra() {
type myParams struct {
varRepoName string
varRepoBranch string
varLocalCfg string
varUseLocal bool
varShowVersion bool
@@ -69,6 +77,7 @@ func init() {
repo = &Setup{}
cobra.OnInitialize(repo.setupCobra)
rootCmd.PersistentFlags().StringVarP(&params.varRepoName, "repository", "r", "https://github.com/lukaszraczylo/simple-gql-client", "Remote repository URL.")
rootCmd.PersistentFlags().StringVarP(&params.varRepoBranch, "branch", "b", "main", "Remote repository URL Branch.")
rootCmd.PersistentFlags().StringVarP(&params.varLocalCfg, "config", "c", "semver.yaml", "Path to config file")
rootCmd.PersistentFlags().BoolVarP(&params.varUseLocal, "local", "l", false, "Use local repository")
rootCmd.PersistentFlags().BoolVarP(&params.varShowVersion, "version", "v", false, "Display version")
+4
View File
@@ -18,6 +18,10 @@ if [[ ! -z "$INPUT_REPOSITORY_URL" ]]; then
FLAGS="${FLAGS} -r $INPUT_REPOSITORY_URL"
fi
if [[ ! -z "$INPUT_REPOSITORY_BRANCH" ]]; then
FLAGS="${FLAGS} -b $INPUT_REPOSITORY_BRANCH"
fi
if [[ ! -z "$INPUT_REPOSITORY_LOCAL" ]]; then
FLAGS="${FLAGS} -l"
fi
+3 -3
View File
@@ -6,7 +6,7 @@ require (
github.com/go-git/go-git/v5 v5.6.1
github.com/lithammer/fuzzysearch v1.1.5
github.com/lukaszraczylo/ask v0.0.0-20230407165749-41ac0d88c13d
github.com/lukaszraczylo/go-simple-graphql v1.1.11
github.com/lukaszraczylo/go-simple-graphql v1.1.30
github.com/lukaszraczylo/pandati v0.0.20
github.com/melbahja/got v0.7.0
github.com/spf13/cobra v1.7.0
@@ -16,9 +16,9 @@ require (
require (
github.com/Microsoft/go-winio v0.6.0 // indirect
github.com/ProtonMail/go-crypto v0.0.0-20230331115716-d34776aa93ec // indirect
github.com/ProtonMail/go-crypto v0.0.0-20230411080316-8b3893ee7fca // indirect
github.com/acomagu/bufpipe v1.0.4 // indirect
github.com/allegro/bigcache v1.2.1 // indirect
github.com/akyoto/cache v1.0.6 // indirect
github.com/avast/retry-go/v4 v4.3.3 // indirect
github.com/cloudflare/circl v1.3.2 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
+6 -6
View File
@@ -42,12 +42,12 @@ github.com/Microsoft/go-winio v0.5.2/go.mod h1:WpS1mjBmmwHBEWmogvA2mj8546UReBk4v
github.com/Microsoft/go-winio v0.6.0 h1:slsWYD/zyx7lCXoZVlvQrj0hPTM1HI4+v1sIda2yDvg=
github.com/Microsoft/go-winio v0.6.0/go.mod h1:cTAf44im0RAYeL23bpB+fzCyDH2MJiz2BO69KH/soAE=
github.com/ProtonMail/go-crypto v0.0.0-20230217124315-7d5c6f04bbb8/go.mod h1:I0gYDMZ6Z5GRU7l58bNFSkPTFN6Yl12dsUlAZ8xy98g=
github.com/ProtonMail/go-crypto v0.0.0-20230331115716-d34776aa93ec h1:eQusauqzE1cAFR5hGnwkuSmFxKoy3+j9/cVaDeYfjjs=
github.com/ProtonMail/go-crypto v0.0.0-20230331115716-d34776aa93ec/go.mod h1:8TI4H3IbrackdNgv+92dI+rhpCaLqM0IfpgCgenFvRE=
github.com/ProtonMail/go-crypto v0.0.0-20230411080316-8b3893ee7fca h1:3N4LNZ++dKh8SXcBRsT6P6mxhDm5swmkgmahlIS9yb0=
github.com/ProtonMail/go-crypto v0.0.0-20230411080316-8b3893ee7fca/go.mod h1:8TI4H3IbrackdNgv+92dI+rhpCaLqM0IfpgCgenFvRE=
github.com/acomagu/bufpipe v1.0.4 h1:e3H4WUzM3npvo5uv95QuJM3cQspFNtFBzvJ2oNjKIDQ=
github.com/acomagu/bufpipe v1.0.4/go.mod h1:mxdxdup/WdsKVreO5GpW4+M/1CE2sMG4jeGJ2sYmHc4=
github.com/allegro/bigcache v1.2.1 h1:hg1sY1raCwic3Vnsvje6TT7/pnZba83LeFck5NrFKSc=
github.com/allegro/bigcache v1.2.1/go.mod h1:Cb/ax3seSYIx7SuZdm2G2xzfwmv3TPSk2ucNfQESPXM=
github.com/akyoto/cache v1.0.6 h1:5XGVVYoi2i+DZLLPuVIXtsNIJ/qaAM16XT0LaBaXd2k=
github.com/akyoto/cache v1.0.6/go.mod h1:WfxTRqKhfgAG71Xh6E3WLpjhBtZI37O53G4h5s+3iM4=
github.com/anmitsu/go-shlex v0.0.0-20200514113438-38f4b401e2be h1:9AeTilPcZAjCFIImctFaOjnTIavg87rW78vTPkQqLI8=
github.com/anmitsu/go-shlex v0.0.0-20200514113438-38f4b401e2be/go.mod h1:ySMOLuWl6zY27l47sB3qLNK6tF2fkHG55UZxx8oIVo4=
github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5 h1:0CwZNZbxp69SHPdPJAN/hZIm0C4OItdklCFmMRWYpio=
@@ -193,8 +193,8 @@ github.com/lithammer/fuzzysearch v1.1.5 h1:Ag7aKU08wp0R9QCfF4GoGST9HbmAIeLP7xwMr
github.com/lithammer/fuzzysearch v1.1.5/go.mod h1:1R1LRNk7yKid1BaQkmuLQaHruxcC4HmAH30Dh61Ih1Q=
github.com/lukaszraczylo/ask v0.0.0-20230407165749-41ac0d88c13d h1:ydn3p85tHJP+8uDYDDGqR4vslcEYwDQ6xBGn1XS/nSk=
github.com/lukaszraczylo/ask v0.0.0-20230407165749-41ac0d88c13d/go.mod h1:M+UVdyqZs++xtEPrascaVmZdOMhCnxjZ2SgH+xHpR0c=
github.com/lukaszraczylo/go-simple-graphql v1.1.11 h1:2Y2hE2fD9WN8thQrtWv/PEw1tLTJ7kUhrcG3msPW5fc=
github.com/lukaszraczylo/go-simple-graphql v1.1.11/go.mod h1:isKTPbnk5Wp302lErjGEwdQbGPA+/4nIuBdeUMMmyjA=
github.com/lukaszraczylo/go-simple-graphql v1.1.30 h1:tQ+BNcSmvWiovyCzNze2pxO9KnZMBd/rtcwAzpE90BI=
github.com/lukaszraczylo/go-simple-graphql v1.1.30/go.mod h1:W/5VDE8PFajDWmWyF4mfbGQIkvWKnbCVLa+9Y3ID6Vs=
github.com/lukaszraczylo/pandati v0.0.20 h1:LqF7CS3z9Zi04KwEY8wd/YUpfWKSwi0nc7pagKQLXHc=
github.com/lukaszraczylo/pandati v0.0.20/go.mod h1:ZegK9ll9UebKV1uNMF73qdLb43G/O4CSOdPglu6NniQ=
github.com/magiconair/properties v1.8.7 h1:IeQXZAiQcpL9mgcAe1Nu6cX9LLw6ExEHKjN0VQdvPDY=