示例#1
0
func (a BugApplication) Edit(args []string) {
	issues, _ := ioutil.ReadDir(string(bugs.GetRootDir()) + "/issues")

	// No parameters, print a list of all bugs
	if len(args) == 1 {
		idx, err := strconv.Atoi(args[0])
		if idx > len(issues) || idx < 1 {
			fmt.Printf("Invalid issue number %d\n", idx)
			return
		}
		dir := bugs.Directory(bugs.GetRootDir()) + "/issues/" + bugs.Directory(issues[idx-1].Name())
		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)
		}
	} else {
		fmt.Printf("Usage: %s edit issuenum\n", os.Args[0])
		fmt.Printf("\nNo issue number specified\n")
	}
}
示例#2
0
func runtestCommitDirtyTree(tester ManagerTester, t *testing.T) {
	err := tester.Setup()
	if err != nil {
		panic("Something went wrong trying to initialize git:" + err.Error())
	}
	defer tester.TearDown()
	m := tester.GetManager()
	if m == nil {
		t.Error("Could not get manager")
		return
	}
	os.Mkdir("issues", 0755)
	runCmd("bug", "create", "-n", "Test bug")
	if err = ioutil.WriteFile("donotcommit.txt", []byte(""), 0644); err != nil {
		t.Error("Could not write file")
		return
	}
	tester.AssertStagingIndex(t, []FileStatus{
		FileStatus{"donotcommit.txt", "?", "?"},
	})

	m.Commit(bugs.Directory(tester.GetWorkDir()+"/issues"), "Initial commit")
	tester.AssertStagingIndex(t, []FileStatus{
		FileStatus{"donotcommit.txt", "?", "?"},
	})
	tester.StageFile("donotcommit.txt")
	tester.AssertStagingIndex(t, []FileStatus{
		FileStatus{"donotcommit.txt", "A", " "},
	})
	m.Commit(bugs.Directory(tester.GetWorkDir()+"/issues"), "Initial commit")
	tester.AssertStagingIndex(t, []FileStatus{
		FileStatus{"donotcommit.txt", "A", " "},
	})
}
示例#3
0
func runtestRenameCommitsHelper(tester ManagerTester, t *testing.T, expectedDiffs []string) {
	err := tester.Setup()
	defer tester.TearDown()
	if err != nil {
		t.Error("Could not initialize repo")
		return
	}

	m := tester.GetManager()
	if m == nil {
		t.Error("Could not get manager")
		return
	}
	os.MkdirAll("issues/Test-bug", 0755)
	ioutil.WriteFile("issues/Test-bug/Description", []byte(""), 0644)
	m.Commit(bugs.Directory(tester.GetWorkDir()), "Initial commit")
	runCmd("bug", "relabel", "1", "Renamed", "bug")
	m.Commit(bugs.Directory(tester.GetWorkDir()), "This is a test rename")

	tester.AssertCleanTree(t)

	assertLogs(tester, t, []map[string]bool{{
		"Initial commit":          true, // simple format
		`Create issue "Test-bug"`: true, // rich format
	}, {
		"This is a test rename":                    true, // simple format
		`Update issues: "Test-bug", "Renamed-bug"`: true, // rich format
		`Update issues: "Renamed-bug", "Test-bug"`: true, // has two alternatives equally good
	}}, expectedDiffs)

}
示例#4
0
func (a BugApplication) Roadmap() {
	issues, _ := ioutil.ReadDir(string(bugs.GetRootDir()) + "/issues")
	var bgs [](bugs.Bug)
	for idx, _ := range issues {
		b := bugs.Bug{}
		b.LoadBug(bugs.Directory(bugs.GetRootDir() + "/issues/" + bugs.Directory(issues[idx].Name())))
		bgs = append(bgs, b)
	}
	sort.Sort(BugListByMilestone(bgs))

	fmt.Printf("# Roadmap for %s\n", bugs.GetRootDir().GetShortName().ToTitle())
	milestone := ""
	for i := len(bgs) - 1; i >= 0; i -= 1 {
		b := bgs[i]
		newMilestone := b.Milestone()
		if milestone != newMilestone {
			if newMilestone == "" {
				fmt.Printf("\n## No milestone set:\n")
			} else {
				fmt.Printf("\n## %s:\n", newMilestone)
			}
		}
		fmt.Printf("- %s\n", b.Title)
		milestone = newMilestone

	}
}
示例#5
0
func (a BugApplication) List(args []string) {
	issues, _ := ioutil.ReadDir(string(bugs.GetRootDir()) + "/issues")

	// No parameters, print a list of all bugs
	if len(args) == 0 {
		for idx, issue := range issues {
			var dir bugs.Directory = bugs.Directory(issue.Name())
			fmt.Printf("Issue %d: %s\n", idx+1, dir.ToTitle())
		}
		return
	}

	// There were parameters, so show the full description of each
	// of those issues
	b := bugs.Bug{}
	for i, length := 0, len(args); i < length; i += 1 {
		idx, err := strconv.Atoi(args[i])
		if err != nil {
			listTags(issues, args)
			return
		}
		if idx > len(issues) || idx < 1 {
			fmt.Printf("Invalid issue number %d\n", idx)
			continue
		}
		if err == nil {
			b.LoadBug(bugs.Directory(bugs.GetRootDir() + "/issues/" + bugs.Directory(issues[idx-1].Name())))
			b.ViewBug()
			if i < length-1 {
				fmt.Printf("\n--\n\n")
			}
		}
	}
	fmt.Printf("\n")
}
示例#6
0
文件: List.go 项目: Komosa/bug
func listTags(files []os.FileInfo, args ArgumentList) {
	b := bugs.Bug{}
	for idx, _ := range files {
		b.LoadBug(bugs.Directory(bugs.GetIssuesDir() + bugs.Directory(files[idx].Name())))

		for _, tag := range args {
			if b.HasTag(bugs.Tag(tag)) {
				fmt.Printf("%s: %s\n", getBugName(b, idx), b.Title("tags"))
			}
		}
	}
}
示例#7
0
文件: Detect.go 项目: Lanzafame/bug
func DetectSCM() (SCMHandler, bugs.Directory, error) {
	// First look for a Git directory
	wd, _ := os.Getwd()

	dirFound, scmtype := walkAndSearch(wd, []string{".git", ".hg"})
	if dirFound != "" && scmtype == ".git" {
		return GitManager{}, bugs.Directory(dirFound), nil
	}
	if dirFound != "" && scmtype == ".hg" {
		return HgManager{}, bugs.Directory(dirFound), nil
	}

	return nil, "", SCMNotFound{}
}
示例#8
0
func (a BugApplication) List(args ArgumentList) {
	issues, _ := ioutil.ReadDir(string(bugs.GetIssuesDir()))

	var wantTags bool = false
	if args.HasArgument("--tags") {
		wantTags = true
	}

	// No parameters, print a list of all bugs
	if len(args) == 0 || (wantTags && len(args) == 1) {
		for idx, issue := range issues {
			if issue.IsDir() != true {
				continue
			}
			var dir bugs.Directory = bugs.GetIssuesDir() + bugs.Directory(issue.Name())
			b := bugs.Bug{dir}
			if wantTags == false {
				fmt.Printf("Issue %d: %s\n", idx+1, b.Title(""))
			} else {
				fmt.Printf("Issue %d: %s\n", idx+1, b.Title("tags"))
			}
		}
		return
	}

	// There were parameters, so show the full description of each
	// of those issues
	b := bugs.Bug{}
	for i, length := 0, len(args); i < length; i += 1 {
		idx, err := strconv.Atoi(args[i])
		if err != nil {
			listTags(issues, args)
			return
		}
		if idx > len(issues) || idx < 1 {
			fmt.Printf("Invalid issue number %d\n", idx)
			continue
		}
		if err == nil {
			b.LoadBug(bugs.Directory(bugs.GetIssuesDir() + bugs.Directory(issues[idx-1].Name())))
			b.ViewBug()
			if i < length-1 {
				fmt.Printf("\n--\n\n")
			}
		}
	}
	fmt.Printf("\n")
}
示例#9
0
文件: main.go 项目: Lanzafame/bug
func (m BugPageHandler) Get(r *http.Request, extras map[string]interface{}) (string, error) {
	if r.URL.Path == "/issues" || r.URL.Path == "/issues/" {
		return getBugList()
	}
	bugDir := string(bugs.GetRootDir()) + r.URL.Path
	b := bugs.Bug{}
	b.LoadBug(bugs.Directory(bugDir))

	switch r.URL.Query().Get("format") {
	case "json":
		bJSON, _ := json.Marshal(b)
		return string(bJSON), nil
	default:
		page := BugRenderer{Bug: b}
		page.RootElement = "RBugPage"
		page.Title = b.Title("")
		page.JSFiles = []string{
			// Bootstrap JS
			//"https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js",
			// React JS
			"https://cdnjs.cloudflare.com/ajax/libs/react/0.14.3/react.js",
			"https://cdnjs.cloudflare.com/ajax/libs/react/0.14.3/react-dom.js",
			"/js/BugPage.js",
		}
		page.CSSFiles = []string{
			"https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css",
			"https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap-theme.min.css"}
		return HTMLPageRenderer.Render(page), nil
	}

}
示例#10
0
文件: Detect.go 项目: Komosa/bug
func DetectSCM(options map[string]bool) (SCMHandler, bugs.Directory, error) {
	// First look for a Git directory
	wd, _ := os.Getwd()

	dirFound, scmtype := walkAndSearch(wd, []string{".git", ".hg"})
	if dirFound != "" && scmtype == ".git" {
		if val, exists := options["autoclose"]; exists && val == true {
			return GitManager{Autoclose: true}, bugs.Directory(dirFound), nil
		}
		return GitManager{Autoclose: false}, bugs.Directory(dirFound), nil
	}
	if dirFound != "" && scmtype == ".hg" {
		return HgManager{}, bugs.Directory(dirFound), nil
	}

	return nil, "", SCMNotFound{}
}
示例#11
0
文件: List.go 项目: Komosa/bug
func List(args ArgumentList, stdout *os.File) {
	issues, _ := ioutil.ReadDir(string(bugs.GetIssuesDir()))

	var wantTags bool = false
	if args.HasArgument("--tags") {
		wantTags = true
	}

	// No parameters, print a list of all bugs
	if len(args) == 0 || (wantTags && len(args) == 1) {
		//os.Stdout = stdout
		for idx, issue := range issues {
			if issue.IsDir() != true {
				continue
			}
			var dir bugs.Directory = bugs.GetIssuesDir() + bugs.Directory(issue.Name())
			b := bugs.Bug{dir}
			name := getBugName(b, idx)
			if wantTags == false {
				fmt.Printf("%s: %s\n", name, b.Title(""))
			} else {
				fmt.Printf("%s: %s\n", name, b.Title("tags"))
			}
		}
		return
	}

	// getAllTags() is defined in Tag.go
	// Get a list of tags, so that when we encounter
	// an error we can check if it's because the user
	// provided a tagname instead of a BugID. If they
	// did, then list bugs matching that tag instead
	// of full descriptions
	tags := getAllTags()
	// There were parameters, so show the full description of each
	// of those issues
	for i, length := 0, len(args); i < length; i += 1 {
		b, err := bugs.LoadBugByHeuristic(args[i])
		if err != nil {
			for _, tagname := range tags {
				if tagname == args[i] {
					listTags(issues, args)
					return
				}
			}
			fmt.Printf("%s\n", err.Error())
			continue
		}

		b.ViewBug()
		if i < length-1 {
			fmt.Printf("\n--\n\n")
		}
	}
	fmt.Printf("\n")
}
示例#12
0
func listTags(files []os.FileInfo, args []string) {
	hasTag := func(tags []string, tag string) bool {
		for _, candidate := range tags {
			if candidate == tag {
				return true
			}
		}
		return false
	}
	b := bugs.Bug{}
	for idx, _ := range files {
		b.LoadBug(bugs.Directory(bugs.GetRootDir() + "/issues/" + bugs.Directory(files[idx].Name())))

		tags := b.StringTags()
		for _, tag := range args {
			if hasTag(tags, tag) {
				fmt.Printf("Issue %d: %s (%s)\n", idx+1, b.Title, strings.Join(tags, ", "))
			}
		}
	}
}
示例#13
0
func runtestRenameCommitsHelper(tester ManagerTester, t *testing.T, expectedDiffs []string) {
	err := tester.Setup()
	if err != nil {
		panic("Something went wrong trying to initialize git:" + err.Error())
	}
	defer tester.TearDown()

	m := tester.GetManager()
	if m == nil {
		t.Error("Could not get manager")
		return
	}
	os.Mkdir("issues", 0755)
	runCmd("bug", "create", "-n", "Test bug")
	m.Commit(bugs.Directory(tester.GetWorkDir()), "Initial commit")
	runCmd("bug", "relabel", "1", "Renamed bug")
	m.Commit(bugs.Directory(tester.GetWorkDir()), "This is a test rename")

	tester.AssertCleanTree(t)

	assertLogs(tester, t, []string{"Initial commit", "This is a test rename"}, expectedDiffs)

}
示例#14
0
func (a BugApplication) Close(args []string) {
	issues, _ := ioutil.ReadDir(string(bugs.GetRootDir()) + "/issues")

	// No parameters, print a list of all bugs
	if len(args) == 0 {
		fmt.Printf("Usage: %s close IssueNumber\n\nMust provide an IssueNumber to close as parameter\n", os.Args[0])
		return
	}

	// There were parameters, so show the full description of each
	// of those issues
	for i := 0; i < len(args); i += 1 {
		idx, err := strconv.Atoi(args[i])
		if idx > len(issues) || idx < 1 {
			fmt.Printf("Invalid issue number %d\n", idx)
			continue
		}
		if err == nil {
			dir := bugs.GetRootDir() + "/issues/" + bugs.Directory(issues[idx-1].Name())
			fmt.Printf("Removing %s\n", dir)
			os.RemoveAll(string(dir))
		}
	}
}
示例#15
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)
}