Esempio n. 1
0
// Show the reviewers for this pull request
func reviewersCmd(c *cli.Context) {
	if !c.Args().Present() {
		gordon.Fatalf("usage: reviewers ID")
	}

	var (
		patch  io.Reader
		number = c.Args()[0]
	)

	if number == "-" {
		patch = os.Stdin
	} else {
		pr, err := m.GetPullRequest(number)
		if err != nil {
			gordon.Fatalf("%s", err)
		}

		resp, err := http.Get(pr.DiffURL)
		if err != nil {
			gordon.Fatalf("%s", err)
		}
		patch = resp.Body
		defer resp.Body.Close()
	}

	reviewers, err := gordon.GetReviewersForPR(patch, false)
	if err != nil {
		gordon.Fatalf("%s", err)
	}
	gordon.DisplayReviewers(c, reviewers)
}
Esempio n. 2
0
func FilterPullRequests(c *cli.Context, prs []*gh.PullRequest) ([]*gh.PullRequest, error) {
	var (
		yesterday  = time.Now().Add(-24 * time.Hour)
		out        = []*gh.PullRequest{}
		email, err = gordon.GetMaintainerManagerEmail()
	)
	if err != nil {
		return nil, err
	}

	for _, pr := range prs {
		fmt.Printf(".")

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

		if user := c.String("user"); user != "" {
			if pr.User.Login != user {
				continue
			}
		}

		if maintainer := c.String("maintainer"); maintainer != "" || c.Bool("mine") {
			if maintainer == "" {
				maintainer = email
			}

			var found bool
			resp, err := http.Get(pr.DiffURL)
			if err != nil {
				continue
			}
			reviewers, err := gordon.GetReviewersForPR(resp.Body)
			resp.Body.Close()
			if err != nil {
				continue
			}
			for file := range reviewers {
				for _, reviewer := range reviewers[file] {
					if reviewer == maintainer {
						found = true
					}
				}
			}
			if !found {
				continue
			}

		}

		if c.Bool("unassigned") && pr.Assignee != nil {
			continue
		} else if assigned := c.String("assigned"); assigned != "" && (pr.Assignee == nil || pr.Assignee.Login != assigned) {
			continue
		}

		if c.Bool("lgtm") {
			pr.ReviewComments = 0
			maintainersOccurrence := map[string]bool{}
			for _, comment := range pr.CommentsBody {
				// We should check it this LGTM is by a user in
				// the maintainers file
				userName := comment.User.Login
				if strings.Contains(comment.Body, "LGTM") && !maintainersOccurrence[userName] {
					maintainersOccurrence[userName] = true
					pr.ReviewComments += 1
				}
			}
		}

		if c.Bool("no-merge") && pr.Mergeable {
			continue
		}

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

}