Пример #1
0
func main() {
	kingpin.Version(VERSION)
	kingpin.Parse()

	logrus.SetOutput(os.Stderr)

	repo, err := git.OpenRepository(*path)
	if err != nil {
		logrus.Fatal("Not a git repository")
	}

	defer repo.Free()

	if err := checkRemotes(repo); err != nil {
		logrus.Error(err)
		return
	}

	line := liner.NewLiner()
	defer line.Close()
	line.SetCtrlCAborts(true)

	startRef, err := readRef(repo, line, "Start ref: ")
	if err == liner.ErrPromptAborted {
		return
	} else if err != nil {
		logrus.Error(err)
		return
	}

	endRef, err := readRef(repo, line, "End ref: ")
	if err == liner.ErrPromptAborted {
		return
	} else if err != nil {
		logrus.Error(err)
		return
	}

	issueNumbers, err := extractIssueNumbers(repo, startRef, endRef)

	logrus.Infof("Found %d issues...", len(issueNumbers))

	issues, err := getIssues(issueNumbers)
	if err != nil {
		logrus.Error(err)
		return
	}

	fmt.Println(formatIssues(issues))
}
Пример #2
0
func extractIssueNumbers(repo *git.Repository, startTag, endTag git.Object) (issues []int, err error) {
	walker, err := repo.Walk()
	if err != nil {
		return nil, err
	}

	defer walker.Free()

	err = walker.PushRange(startTag.Id().String() + ".." + endTag.Id().String())
	if err != nil {
		return nil, err
	}

	issueStrings := make(map[string]struct{})
	err = walker.Iterate(func(commit *git.Commit) bool {
		matches := issueMatcher.FindAllStringSubmatch(commit.Message(), -1)
		for _, match := range matches {
			for _, issueStr := range match {
				issueStrings[issueStr[1:]] = struct{}{}
			}
		}
		return true
	})

	if err != nil {
		return nil, err
	}

	for issueStr, _ := range issueStrings {
		issue, err := strconv.Atoi(issueStr)
		if err != nil {
			logrus.Error(err)
			continue
		}

		issues = append(issues, issue)
	}

	sort.Ints(issues)

	return
}