示例#1
0
func (a BugApplication) Create(Args ArgumentList) {
	if len(Args) < 1 || (len(Args) < 2 && Args[0] == "-n") {
		fmt.Printf("Usage: %s create [-n] Bug Description\n", os.Args[0])
		fmt.Printf("\nNo Bug Description provided.\n")
		return
	}
	var noDesc bool = false

	if Args.HasArgument("-n") {
		noDesc = true
		Args = Args[1:]
	}

	var bug bugs.Bug
	bug = bugs.Bug{
		Dir: bugs.GetIssuesDir() + bugs.TitleToDir(strings.Join(Args, " ")),
	}

	dir, _ := bug.GetDirectory()
	fmt.Printf("Created issue: %s\n", bug.Title(""))

	var mode os.FileMode
	mode = 0775
	os.Mkdir(string(dir), mode)

	if noDesc {
		txt := []byte("")
		ioutil.WriteFile(string(dir)+"/Description", txt, 0644)
	} else {
		cmd := exec.Command(getEditor(), string(dir)+"/Description")

		cmd.Stdin = os.Stdin
		cmd.Stdout = os.Stdout
		cmd.Stderr = os.Stderr
		err := cmd.Run()

		if err != nil {
			log.Fatal(err)
		}
	}
}
示例#2
0
func (a BugApplication) Relabel(Args []string) {
	if len(Args) < 2 {
		fmt.Printf("Usage: %s relabel issuenum New Title\n", os.Args[0])
		return
	}

	b, err := bugs.LoadBugByStringIndex(Args[0])

	if err != nil {
		fmt.Printf("Could not load bug: %s\n", err.Error())
		return
	}

	currentDir, _ := b.GetDirectory()
	newDir := bugs.GetRootDir() + "/issues/" + bugs.TitleToDir(strings.Join(Args[1:], " "))
	fmt.Printf("Moving %s to %s\n", currentDir, newDir)
	err = os.Rename(string(currentDir), string(newDir))
	if err != nil {
		fmt.Printf("Error moving directory\n")
	}
}
示例#3
0
文件: Relabel.go 项目: Komosa/bug
func Relabel(Args ArgumentList) {
	if len(Args) < 2 {
		fmt.Printf("Usage: %s relabel BugID New Title\n", os.Args[0])
		return
	}

	b, err := bugs.LoadBugByHeuristic(Args[0])

	if err != nil {
		fmt.Printf("Could not load bug: %s\n", err.Error())
		return
	}

	currentDir := b.GetDirectory()
	newDir := bugs.GetIssuesDir() + bugs.TitleToDir(strings.Join(Args[1:], " "))
	fmt.Printf("Moving %s to %s\n", currentDir, newDir)
	err = os.Rename(string(currentDir), string(newDir))
	if err != nil {
		fmt.Printf("Error moving directory\n")
	}
}
示例#4
0
文件: Create.go 项目: Komosa/bug
func Create(Args ArgumentList) {
	if len(Args) < 1 || (len(Args) < 2 && Args[0] == "-n") {
		fmt.Fprintf(os.Stderr, "Usage: %s create [-n] Bug Description\n", os.Args[0])
		fmt.Fprintf(os.Stderr, "\nNo Bug Description provided.\n")
		return
	}
	var noDesc bool = false

	if Args.HasArgument("-n") {
		noDesc = true
		Args = Args[1:]
	}

	Args, argVals := Args.GetAndRemoveArguments([]string{"--tag", "--status", "--priority", "--milestone", "--identifier"})
	tag := argVals[0]
	status := argVals[1]
	priority := argVals[2]
	milestone := argVals[3]
	identifier := argVals[4]

	if Args.HasArgument("--generate-id") {
		for i, token := range Args {
			if token == "--generate-id" {
				if i+1 < len(Args) {
					Args = append(Args[:i], Args[i+1:]...)
					break
				} else {
					Args = Args[:i]
					break
				}
			}
		}
		identifier = generateID(strings.Join(Args, " "))
	}

	var bug bugs.Bug
	bug = bugs.Bug{
		Dir: bugs.GetIssuesDir() + bugs.TitleToDir(strings.Join(Args, " ")),
	}

	dir := bug.GetDirectory()

	var mode os.FileMode
	mode = 0775
	os.Mkdir(string(dir), mode)

	if noDesc {
		txt := []byte("")
		ioutil.WriteFile(string(dir)+"/Description", txt, 0644)
	} else {
		cmd := exec.Command(getEditor(), string(dir)+"/Description")

		cmd.Stdin = os.Stdin
		cmd.Stdout = os.Stdout
		cmd.Stderr = os.Stderr
		err := cmd.Run()

		if err != nil {
			log.Fatal(err)
		}
	}

	if tag != "" {
		bug.TagBug(bugs.Tag(tag))
	}
	if status != "" {
		bug.SetStatus(status)
	}
	if priority != "" {
		bug.SetPriority(priority)
	}
	if milestone != "" {
		bug.SetMilestone(milestone)
	}
	if identifier != "" {
		bug.SetIdentifier(identifier)
	}
	fmt.Printf("Created issue: %s\n", bug.Title(""))
}
示例#5
0
文件: be.go 项目: Komosa/bug
func beImportBug(identifier, issuesDir, fullbepath string) {
	/* BE appears to store the top level data of a bug
	   ins a json file named values with the format:
	    {
	        "creator": "Dave MacFarlane <*****@*****.**>",
	        "reporter": "Dave MacFarlane <*****@*****.**>",
	        "severity": "minor",
	        "status": "open",
	        "summary": "abc",
	        "time": "Tue, 12 Jan 2016 00:05:28 +0000"
	    }

	    and the description of bugs entirely in comments.
	    All we really care about is the summary so that we
	    can get the directory name for the issues/ directory,
	    but the severity+status can also be used as a status
	    to ensure that we have at least 1 file to be tracked
	    by git.
	*/

	type BeValues struct {
		Creator  string `json:creator`
		Reporter string `json:reporter`
		Severity string `json:severity`
		Status   string `json:status`
		Summary  string `json:summary`
		Time     string `json:time`
	}
	file := fullbepath + "/values"

	fmt.Printf("File: %s\n", file)
	data, _ := ioutil.ReadFile(file)
	var beBug BeValues
	err := json.Unmarshal([]byte(data), &beBug)
	if err != nil {
		fmt.Printf("Error unmarshalling data: %s\n", err.Error())
	}

	fmt.Printf("%s\n", beBug)

	bugdir := bugs.TitleToDir(beBug.Summary)

	b := bugs.Bug{bugs.Directory(issuesDir) + bugdir}
	if dir := b.GetDirectory(); dir != "" {
		os.Mkdir(string(dir), 0755)
	}
	if beBug.Status != "" && beBug.Severity != "" {
		b.SetStatus(beBug.Status + ":" + beBug.Severity)
	}

	comments := fullbepath + "/comments/"
	dir, err := os.Open(comments)

	files, err := dir.Readdir(-1)
	var Description string
	if len(files) > 0 && err == nil {
		for _, file := range files {
			if file.IsDir() {
				Description = Description + "\n" +
					beImportComments(b, comments+file.Name(), len(files) > 1)
			}
		}
	}
	b.SetDescription(Description)
	b.SetIdentifier(identifier)
}