File tree Expand file tree Collapse file tree 2 files changed +53
-9
lines changed Expand file tree Collapse file tree 2 files changed +53
-9
lines changed Original file line number Diff line number Diff line change 5
5
"os"
6
6
7
7
"github.com/barelyhuman/commitlog/pkg"
8
+ "github.com/go-git/go-git/v5"
9
+ "github.com/go-git/go-git/v5/config"
10
+ "github.com/go-git/go-git/v5/plumbing"
8
11
"github.com/urfave/cli/v2"
9
12
)
10
13
@@ -46,13 +49,48 @@ func Release(c *cli.Context) (err error) {
46
49
return err
47
50
}
48
51
49
- // TODO:
50
- // add commit
51
- // add tagging
52
- // add push
53
- // methods to the `releaser`
54
-
55
52
err = os .WriteFile (".commitlog.release" , []byte (releaser .String ()), os .ModePerm )
53
+ if err != nil {
54
+ return
55
+ }
56
+
57
+ openRepo , err := git .PlainOpen (c .String ("path" ))
58
+ if err != nil {
59
+ return err
60
+ }
61
+
62
+ var commitHash plumbing.Hash
63
+ wt , err := openRepo .Worktree ()
64
+ if err != nil {
65
+ return err
66
+ }
67
+
68
+ if c .Bool ("commit" ) {
69
+ wt .Add (".commitlog.release" )
70
+ commitHash , err = wt .Commit ("chore: version" + releaser .String (), & git.CommitOptions {})
71
+ if err != nil {
72
+ return err
73
+ }
74
+
75
+ _ , err = openRepo .CreateTag (releaser .String (), commitHash , & git.CreateTagOptions {})
76
+ if err != nil {
77
+ err = fmt .Errorf ("looks like there was error while creating a tag for the version commit, please try again or create a tag manually: %v" , err )
78
+ return err
79
+ }
80
+ }
81
+
82
+ if c .Bool ("push" ) {
83
+ _ , err := wt .Status ()
84
+ if err != nil {
85
+ return err
86
+ }
87
+
88
+ openRepo .Push (& git.PushOptions {
89
+ RemoteName : "origin" ,
90
+ Progress : os .Stdout ,
91
+ RefSpecs : []config.RefSpec {config .RefSpec ("refs/tags/*:refs/tags/*" )},
92
+ })
93
+ }
56
94
57
95
return err
58
96
}
Original file line number Diff line number Diff line change @@ -84,6 +84,12 @@ func main() {
84
84
Name : "init" ,
85
85
Usage : "initialise commitlog release" ,
86
86
},
87
+ & cli.StringFlag {
88
+ Name : "path" ,
89
+ Value : "." ,
90
+ Aliases : []string {"p" },
91
+ Usage : "root with the '.git' folder `PATH`" ,
92
+ },
87
93
& cli.BoolFlag {
88
94
Name : "pre-release" ,
89
95
Usage : "create a pre-release version. will default to patch increment unless" +
@@ -109,12 +115,12 @@ func main() {
109
115
& cli.BoolFlag {
110
116
Name : "commit" ,
111
117
Value : false ,
112
- Usage : "if true will create a commit, of the changed version" ,
118
+ Usage : "if true will create a commit and tag , of the changed version" ,
113
119
},
114
120
& cli.BoolFlag {
115
- Name : "tag " ,
121
+ Name : "push " ,
116
122
Value : false ,
117
- Usage : "if true will create a tag, with the given version " ,
123
+ Usage : "if true will create push the created release commit + tag on origin " ,
118
124
},
119
125
},
120
126
},
You can’t perform that action at this time.
0 commit comments