-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathimport_cmd.go
More file actions
79 lines (70 loc) · 1.8 KB
/
import_cmd.go
File metadata and controls
79 lines (70 loc) · 1.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
package main
import (
"fmt"
"os"
"github.com/spf13/cobra"
"github.com/glestaris/issuez/tracker"
"github.com/glestaris/issuez/domain"
)
var jiraProjectKey string
func init() {
importCmd.PersistentFlags().StringVarP(
&jiraProjectKey, "project-key", "p", "", "JIRA project key",
)
rootCmd.AddCommand(importCmd)
}
var importCmd = &cobra.Command{
Use: "import <Path to Markdown file>",
Short: "Imports markdown file as JIRA issues",
Args: cobra.ExactArgs(1),
Run: func(cmd *cobra.Command, args []string) {
markdownFilePath := args[0]
markdownFile, err := os.Open(markdownFilePath)
if err != nil {
fmt.Printf(
"Failed to open markdown file '%s': %s\n", markdownFilePath,
err,
)
os.Exit(1)
}
defer markdownFile.Close()
issues, err := ParseImportFile(markdownFile)
if err != nil {
fmt.Printf("Failed to parse markdown file: %s\n", err)
os.Exit(1)
}
if len(issues) == 0 {
fmt.Println("No issues were found")
os.Exit(0)
} else {
fmt.Printf("Found %d issues in the markdown file\n", len(issues))
}
trackerService, err := tracker.NewTrackerService(domain.Tracker{
Type: "jira",
Config: map[string]string{
"apiHost": jiraAPIHost,
"apiUsername": jiraAPIUsername,
"apiToken": jiraAPIToken,
"projectKey": jiraProjectKey,
},
})
if err != nil {
fmt.Printf("Failed to initalise tracker service: %s\n", err)
os.Exit(1)
}
err = trackerService.ImportIssues(issues)
if err != nil {
fmt.Printf("Failed to import issues: %s\n", err)
os.Exit(1)
}
fmt.Printf("Imported issues:\n")
for _, issue := range issues {
// - Task (TEST-124): Subject
if issue.ID == "" {
fmt.Printf("- %s (FAILED): %s\n", issue.Type, issue.Title)
} else {
fmt.Printf("- %s (%s): %s\n", issue.Type, issue.ID, issue.Title)
}
}
},
}