Skip to content

Commit fc95988

Browse files
John Frederickbzon
authored andcommitted
Add describe tag command
1 parent 14f9cda commit fc95988

3 files changed

Lines changed: 127 additions & 1 deletion

File tree

cmd/desc_tag.go

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
// Copyright © 2018 github.com/devopsctl authors
2+
//
3+
// Permission is hereby granted, free of charge, to any person obtaining a copy
4+
// of this software and associated documentation files (the "Software"), to deal
5+
// in the Software without restriction, including without limitation the rights
6+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7+
// copies of the Software, and to permit persons to whom the Software is
8+
// furnished to do so, subject to the following conditions:
9+
//
10+
// The above copyright notice and this permission notice shall be included in
11+
// all copies or substantial portions of the Software.
12+
//
13+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19+
// THE SOFTWARE.
20+
21+
package cmd
22+
23+
import (
24+
"github.com/spf13/cobra"
25+
)
26+
27+
var descTagCmd = &cobra.Command{
28+
Use: "tag",
29+
Aliases: []string{"t"},
30+
Short: "Describe a tag of a specified project",
31+
Example: "gitlabctl describe tag v5.0 --project=devopsctl/gitlabctl",
32+
SilenceErrors: true,
33+
SilenceUsage: true,
34+
DisableAutoGenTag: true,
35+
Args: cobra.ExactArgs(1),
36+
RunE: func(cmd *cobra.Command, args []string) error {
37+
return descTag(
38+
getFlagString(cmd, "project"),
39+
args[0],
40+
getFlagString(cmd, "out"),
41+
)
42+
},
43+
}
44+
45+
func init() {
46+
descCmd.AddCommand(descTagCmd)
47+
addProjectFlag(descTagCmd)
48+
verifyMarkFlagRequired(descTagCmd, "project")
49+
}
50+
51+
func descTag(project, tag, out string) error {
52+
git, err := newGitlabClient()
53+
if err != nil {
54+
return err
55+
}
56+
tagInfo, _, err := git.Tags.GetTag(project, tag)
57+
if err != nil {
58+
return err
59+
}
60+
printTagsOut(out, tagInfo)
61+
return nil
62+
}

cmd/desc_tag_test.go

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
// Copyright © 2018 github.com/devopsctl authors
2+
//
3+
// Permission is hereby granted, free of charge, to any person obtaining a copy
4+
// of this software and associated documentation files (the "Software"), to deal
5+
// in the Software without restriction, including without limitation the rights
6+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7+
// copies of the Software, and to permit persons to whom the Software is
8+
// furnished to do so, subject to the following conditions:
9+
//
10+
// The above copyright notice and this permission notice shall be included in
11+
// all copies or substantial portions of the Software.
12+
//
13+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19+
// THE SOFTWARE.
20+
21+
package cmd
22+
23+
import (
24+
"testing"
25+
)
26+
27+
func TestDescTagCmd(t *testing.T) {
28+
tt := []struct {
29+
name string
30+
flagsMap map[string]string
31+
args []string
32+
expect testResult
33+
}{
34+
{
35+
name: "describe project tag",
36+
flagsMap: map[string]string{
37+
"project": "1",
38+
},
39+
args: []string{"sample_1.0"},
40+
expect: pass,
41+
},
42+
{
43+
name: "describing a non existent tag fails",
44+
flagsMap: map[string]string{
45+
"project": "1",
46+
},
47+
args: []string{"sample_2.0"},
48+
expect: fail,
49+
},
50+
}
51+
52+
for _, tc := range tt {
53+
t.Run(tc.name, func(t *testing.T) {
54+
execT := execTestCmdFlags{
55+
t: t,
56+
cmd: descTagCmd,
57+
flagsMap: tc.flagsMap,
58+
args: tc.args,
59+
}
60+
stdout, execResult := execT.executeCommand()
61+
assertEqualResult(t, execResult, tc.expect, printFlagsTable(tc.flagsMap, stdout))
62+
})
63+
}
64+
}

cmd/helpers.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,7 @@ func printTagsOut(format string, tags ...*gitlab.Tag) {
364364
for _, v := range tags {
365365
rows = append(rows, []string{
366366
v.Name,
367-
v.Commit.ID,
367+
v.Commit.ShortID,
368368
})
369369
}
370370
printTable(header, rows)

0 commit comments

Comments
 (0)