Skip to content

Commit c39be3f

Browse files
committed
#6 Complete Create Issue Command, and also refine commands code structure
1 parent 4af878e commit c39be3f

File tree

6 files changed

+50
-8
lines changed

6 files changed

+50
-8
lines changed

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,14 +65,14 @@ Project Layout:
6565
│   └── reaction_groups_test.go
6666
├── build
6767
│   └── windows
68-
│   ├── gh.wixproj
69-
│   ├── gh.wxs
68+
│   ├── ci.wixproj
69+
│   ├── ci.wxs
7070
│   └── ui.wxs
7171
├── cmd
7272
│   ├── gen-docs
7373
│   │   ├── main.go
7474
│   │   └── main_test.go
75-
│   └── gh
75+
│   └── ci
7676
│   ├── main.go
7777
│   └── main_test.go
7878
├── context
@@ -82,7 +82,7 @@ Project Layout:
8282
├── docs
8383
│   ├── README.md
8484
│   ├── command-line-syntax.md
85-
│   ├── gh-vs-hub.md
85+
│   ├── ci-vs-hub.md
8686
│   ├── install_linux.md
8787
│   ├── multiple-accounts.md
8888
│   ├── project-layout.md

cmd/actions/issue.go

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
package actions
2+
3+
import (
4+
"github.com/fluent-qa/qgops/internal/utils"
5+
"github.com/fluent-qa/qgops/internal/utils/shell"
6+
_ "log/slog"
7+
8+
"github.com/spf13/cobra"
9+
)
10+
11+
func runGhIssueCreate(title string, body string) (int, error) {
12+
template := "gh issue create --label enhancement -t \"{{.Title}}\" -b \"{{.Body}}\""
13+
commandStr := utils.RenderTemplate(template, map[string]string{
14+
"Title": title,
15+
"Body": body,
16+
})
17+
return shell.ExecShellCommand(commandStr)
18+
}
19+
20+
func init() {
21+
IssueCmd.Flags().StringVarP(&issueTitle, "title", "t", "", "Title of the issue")
22+
IssueCmd.Flags().StringVarP(&issueBody, "body", "b", "", "Body of the issue")
23+
IssueCmd.MarkFlagRequired("title")
24+
IssueCmd.MarkFlagRequired("body")
25+
}
26+
27+
var (
28+
issueTitle string
29+
issueBody string
30+
IssueCmd = &cobra.Command{
31+
Use: "issue",
32+
Short: "Create a new issue",
33+
Long: "Create a new issue with a title and body",
34+
Run: func(cmd *cobra.Command, args []string) {
35+
_, err := runGhIssueCreate(issueTitle, issueBody)
36+
if err != nil {
37+
cmd.PrintErrf("Error creating issue: %v\n", err)
38+
}
39+
},
40+
}
41+
)

cmd/starter/commands.go renamed to cmd/actions/starter.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package starter
1+
package actions
22

33
import (
44
_ "log/slog"

cmd/starter/commands_test.go renamed to cmd/actions/starter_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package starter
1+
package actions
22

33
import (
44
"fmt"
File renamed without changes.

cmd/fluent.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
package main
22

33
import (
4+
"github.com/fluent-qa/qgops/cmd/actions"
45
"github.com/fluent-qa/qgops/cmd/base"
5-
"github.com/fluent-qa/qgops/cmd/starter" // Add this import
66
)
77

88
func init() {
9-
base.CmdRoot.AddCommand(starter.StarterCmd)
9+
base.CmdRoot.AddCommand(actions.StarterCmd)
10+
base.CmdRoot.AddCommand(actions.IssueCmd)
1011
}
1112
func main() {
1213
_ = base.CmdRoot.Execute()

0 commit comments

Comments
 (0)