github.com/grantbow/fit@v0.7.1-0.20220916164603-1f7c88ac81e6/fitapp/Import.go (about) 1 package fitapp 2 3 import ( 4 "fmt" 5 bugs "github.com/grantbow/fit/issues" 6 "os" 7 "strings" 8 ) 9 10 //var dops = bugs.Directory(os.PathSeparator) 11 //var sops = string(os.PathSeparator) 12 13 // Import is a subcommand to read from a bugsEverywhere.org or github.com systems and create identical issues. 14 func Import(args argumentList, config bugs.Config) { 15 if len(args) < 1 { 16 fmt.Printf("Usage: %s import {--github,--be} <repo>\n", os.Args[0]) 17 //fmt.Printf("Usage: %s import {<github.com/user/repo>,--be}\n", os.Args[0]) 18 return 19 } 20 switch args[0] { 21 case "--github": 22 if githubRepo := args.GetArgument("--github", ""); githubRepo != "" { 23 numStrings := strings.Count(githubRepo, "/") 24 pieces := strings.Split(githubRepo, "/") 25 //fmt.Printf("ns %v\np %v\n", numStrings, pieces) 26 if numStrings == 1 { 27 githubImportIssues(pieces[0], pieces[1], config) 28 } else if numStrings == 2 && 29 pieces[2] == "projects" { 30 if config.GithubPersonalAccessToken != "" { 31 githubImportProjects(pieces[0], pieces[1], config) 32 } else { 33 fmt.Fprintf(os.Stderr, "GithubPersonalAccessToken missing for %s\n", githubRepo) 34 } 35 } else { 36 fmt.Fprintf(os.Stderr, "GitHub invalid: %s\n", githubRepo) 37 return 38 } 39 } 40 case "--be": 41 if len(args) > 1 { 42 fmt.Fprintf(os.Stderr, "BugsEverywhere repo ignored: %s\n", args[1:]) 43 } 44 beImport(config) 45 default: 46 fmt.Fprintf(os.Stderr, "usage: %s import --github user/repo\n", os.Args[0]) 47 //fmt.Fprintf(os.Stderr, "usage: %s import github.com/user/repo\n", os.Args[0]) 48 fmt.Fprintf(os.Stderr, " %s import --be\n", os.Args[0]) 49 fmt.Fprintf(os.Stderr, ` 50 Use this command to import an external bug database into the local 51 issues/ directory. 52 53 Either "--github <user>/repo>" is required to import issues 54 or "--github <user>/<repo>/projects" to import projects 55 or "--be" found relative to the current path to import a local BugsEverywhere database. 56 GitHub projects require a configured GithubPersonalAccessToken value. 57 `) 58 } 59 return 60 }