コード例 #1
0
ファイル: filters.go プロジェクト: rogaha/gordon
func noMergePullRequestsFilter(prs []*gh.PullRequest, err error) ([]*gh.PullRequest, error) {
	if err != nil {
		return nil, err
	}

	out := []*gh.PullRequest{}
	for _, pr := range prs {
		fmt.Printf(".")
		// We have to fetch the single pr to get the merge state
		// it sucks but we have to do it
		client := gh.NewClient()
		org, name, err := gordon.GetOriginUrl()
		if err != nil {
			panic(err)
		}
		t, err := gordon.NewMaintainerManager(client, org, name)
		if err != nil {
			panic(err)
		}
		pr, _, err := t.GetPullRequest(strconv.Itoa(pr.Number), false)
		if err != nil {
			return nil, err
		}
		if !pr.Mergeable {
			out = append(out, pr)
		}
	}
	return out, nil
}
コード例 #2
0
ファイル: filters.go プロジェクト: rogaha/gordon
func voteIssuesFilter(issues []*gh.Issue, numVotes int, err error) ([]*gh.Issue, error) {
	if err != nil {
		return nil, err
	}

	out := []*gh.Issue{}
	for _, issue := range issues {
		fmt.Printf(".")
		client := gh.NewClient()
		org, name, err := gordon.GetOriginUrl()
		if err != nil {
			panic(err)
		}
		t, err := gordon.NewMaintainerManager(client, org, name)
		if err != nil {
			panic(err)
		}
		comments, err := t.GetComments(strconv.Itoa(issue.Number))
		if err != nil {
			return nil, err
		}
		issue.Comments = 0
		for _, comment := range comments {
			if strings.Contains(comment.Body, "+1") {
				issue.Comments += 1
			}
		}
		if issue.Comments >= numVotes {
			out = append(out, issue)
		}
	}
	return out, nil
}
コード例 #3
0
ファイル: filters.go プロジェクト: rogaha/gordon
func lgtmPullRequestsFilter(prs []*gh.PullRequest, err error) ([]*gh.PullRequest, error) {
	if err != nil {
		return nil, err
	}

	for _, pr := range prs {
		fmt.Printf(".")
		client := gh.NewClient()
		org, name, err := gordon.GetOriginUrl()
		if err != nil {
			panic(err)
		}
		t, err := gordon.NewMaintainerManager(client, org, name)
		if err != nil {
			panic(err)
		}
		comments, err := t.GetComments(strconv.Itoa(pr.Number))
		if err != nil {
			return nil, err
		}
		pr.ReviewComments = 0
		maintainersOccurrence := map[string]bool{}
		for _, comment := range comments {
			// We should check it this LGTM is by a user in
			// the maintainers file
			userName := comment.User.Login
			if strings.Contains(comment.Body, "LGTM") && t.IsMaintainer(userName) && !maintainersOccurrence[userName] {
				maintainersOccurrence[userName] = true
				pr.ReviewComments += 1
			}
		}
	}
	return prs, nil
}
コード例 #4
0
ファイル: main.go プロジェクト: rogaha/gordon
func main() {

	app := cli.NewApp()

	app.Name = "pulls"
	app.Usage = "Manage github pull requests for project maintainers"
	app.Version = "0.0.1"

	client := gh.NewClient()

	org, name, err := gordon.GetOriginUrl()
	if err != nil {
		fmt.Fprintf(os.Stderr, "The current directory is not a valid git repository.\n")
		os.Exit(1)
	}
	t, err := gordon.NewMaintainerManager(client, org, name)
	if err != nil {
		gordon.WriteError("%s", err)
	}
	m = t

	loadCommands(app)

	app.Run(os.Args)
}
コード例 #5
0
ファイル: main.go プロジェクト: pombredanne/pulls
func before(c *cli.Context) error {
	client := gh.NewClient()

	org, name, err := gordon.GetRemoteUrl(c.String("remote"))
	if err != nil {
		return fmt.Errorf("The current directory is not a valid git repository (%s).\n", err)
	}
	t, err := gordon.NewMaintainerManager(client, org, name)
	if err != nil {
		return err
	}
	m = t
	return nil
}
コード例 #6
0
ファイル: filters.go プロジェクト: pombredanne/pulls
func FilterIssues(c *cli.Context, issues []*gh.Issue) ([]*gh.Issue, error) {
	var (
		yesterday      = time.Now().Add(-24 * time.Hour)
		out            = []*gh.Issue{}
		client         = gh.NewClient()
		org, name, err = gordon.GetOriginUrl()
	)
	if err != nil {
		return nil, err
	}
	t, err := gordon.NewMaintainerManager(client, org, name)
	if err != nil {
		return nil, err
	}

	for _, issue := range issues {
		fmt.Printf(".")

		if c.Bool("new") && !issue.CreatedAt.After(yesterday) {
			continue
		}

		if milestone := c.String("milestone"); milestone != "" && issue.Milestone.Title != milestone {
			continue
		}

		if numVotes := c.Int("votes"); numVotes > 0 {
			comments, err := t.GetComments(strconv.Itoa(issue.Number))
			if err != nil {
				return nil, err
			}
			issue.Comments = 0
			for _, comment := range comments {
				if strings.Contains(comment.Body, "+1") {
					issue.Comments += 1
				}
			}
			if issue.Comments < numVotes {
				continue
			}
		}

		out = append(out, issue)
	}
	return out, nil

}