Ejemplo n.º 1
0
// listReviews lists all extant reviews.
// TODO(ojarjur): Add flags for filtering the output (e.g. to just open reviews).
func listReviews(args []string) {
	reviews := review.ListAll()
	fmt.Printf("Loaded %d reviews:\n", len(reviews))
	for _, review := range review.ListAll() {
		review.PrintSummary()
	}
}
Ejemplo n.º 2
0
// WriteNewReviews takes a list of reviews read from GitHub, and writes to the repo any review
// data that has not already been written to it.
//
// The passed in logChan variable is used as our intermediary for logging, and allows us to
// use the same logic for logging messages in either our CLI or our App Engine apps, even though
// the two have different logging frameworks.
func WriteNewReviews(reviews []review.Review, repo repository.Repo, logChan chan<- string) error {
	existingReviews := review.ListAll(repo)
	for _, r := range reviews {
		requestNote, err := r.Request.Write()
		if err != nil {
			return err
		}
		if err != nil {
			return err
		}
		alreadyPresent := false
		if existing := findMatchingExistingReview(r, existingReviews); existing != nil {
			alreadyPresent = RequestsOverlap(existing.Request, r.Request)
			r.Revision = existing.Revision
		}
		if !alreadyPresent {
			requestJSON, err := r.GetJSON()
			if err != nil {
				return err
			}
			logChan <- fmt.Sprintf("Found a new review for %.12s:\n%s\n", r.Revision, requestJSON)
			if err := repo.AppendNote(request.Ref, r.Revision, requestNote); err != nil {
				return err
			}
		}
		if err := WriteNewComments(r, repo, logChan); err != nil {
			return err
		}
	}
	return nil
}
Ejemplo n.º 3
0
// listReviews lists all extant reviews.
// TODO(ojarjur): Add more flags for filtering the output (e.g. filtering by reviewer or status).
func listReviews(repo repository.Repo, args []string) error {
	listFlagSet.Parse(args)
	var reviews []review.Summary
	if *listAll {
		reviews = review.ListAll(repo)
		if !*listJSONOutput {
			fmt.Printf("Loaded %d reviews:\n", len(reviews))
		}
	} else {
		reviews = review.ListOpen(repo)
		if !*listJSONOutput {
			fmt.Printf("Loaded %d open reviews:\n", len(reviews))
		}
	}
	if *listJSONOutput {
		b, err := json.MarshalIndent(reviews, "", "  ")
		if err != nil {
			return err
		}
		fmt.Println(string(b))
		return nil
	}
	for _, r := range reviews {
		output.PrintSummary(&r)
	}
	return nil
}
Ejemplo n.º 4
0
func TestMirrorRepo(t *testing.T) {
	repo := repository.NewMockRepoForTest()
	tool := mockReviewTool{make(map[string]request.Request)}
	syncToRemote := true
	mirrorRepoToReview(repo, &tool, syncToRemote)
	if len(tool.Requests) != len(review.ListAll(repo)) {
		t.Errorf("Review requests are not what we expected: %v", tool.Requests)
	}
}
Ejemplo n.º 5
0
// listReviews lists all extant reviews.
// TODO(ojarjur): Add more flags for filtering the output (e.g. filtering by reviewer or status).
func listReviews(repo repository.Repo, args []string) {
	listFlagSet.Parse(args)
	var reviews []review.Summary
	if *listAll {
		reviews = review.ListAll(repo)
		fmt.Printf("Loaded %d reviews:\n", len(reviews))
	} else {
		reviews = review.ListOpen(repo)
		fmt.Printf("Loaded %d open reviews:\n", len(reviews))
	}
	for _, r := range reviews {
		output.PrintSummary(&r)
	}
}
Ejemplo n.º 6
0
func mirrorRepoToReview(repo repository.Repo, tool review_utils.Tool, syncToRemote bool) {
	if syncToRemote {
		repo.PullNotes("origin", "refs/notes/devtools/*")
	}

	stateHash, err := repo.GetRepoStateHash()
	if err != nil {
		log.Fatal(err)
	}
	if processedStates[repo.GetPath()] != stateHash {
		log.Print("Mirroring repo: ", repo)
		for _, r := range review.ListAll(repo) {
			reviewJson, err := r.GetJSON()
			if err != nil {
				log.Fatal(err)
			}
			log.Println("Mirroring review: ", reviewJson)
			existingComments[r.Revision] = r.Comments
			reviewDetails, err := r.Details()
			if err == nil {
				tool.EnsureRequestExists(repo, *reviewDetails)
			}
		}
		openReviews[repo.GetPath()] = tool.ListOpenReviews(repo)
		processedStates[repo.GetPath()] = stateHash
		tool.Refresh(repo)
	}
ReviewLoop:
	for _, phabricatorReview := range openReviews[repo.GetPath()] {
		if reviewCommit := phabricatorReview.GetFirstCommit(repo); reviewCommit != "" {
			log.Println("Processing review: ", reviewCommit)
			r, err := review.GetSummary(repo, reviewCommit)
			if err != nil {
				log.Fatal(err)
			} else if r == nil {
				log.Printf("Skipping unknown review %q", reviewCommit)
				continue ReviewLoop
			}
			revisionComments := existingComments[reviewCommit]
			log.Printf("Loaded %d comments for %v\n", len(revisionComments), reviewCommit)
			for _, c := range phabricatorReview.LoadComments() {
				if !hasOverlap(c, revisionComments) {
					// The comment is new.
					note, err := c.Write()
					if err != nil {
						log.Fatal(err)
					}
					log.Printf("Appending a comment: %s", string(note))
					repo.AppendNote(comment.Ref, reviewCommit, note)
				} else {
					log.Printf("Skipping '%v', as it has already been written\n", c)
				}
			}
		}
	}
	if syncToRemote {
		if err := repo.PushNotes("origin", "refs/notes/devtools/*"); err != nil {
			log.Printf("Failed to push updates to the repo %v: %v\n", repo, err)
		}
	}
}