Exemplo n.º 1
0
func (arc Arcanist) mirrorStatusesForEachCommit(r review.Review, commitToDiffIDMap map[string]int) {
	for commitHash, diffID := range commitToDiffIDMap {
		ciNotes := r.Repo.GetNotes(ci.Ref, commitHash)
		ciReports := ci.ParseAllValid(ciNotes)
		latestCIReport, err := ci.GetLatestCIReport(ciReports)
		if err != nil {
			log.Println("Failed to load the continuous integration reports: " + err.Error())
		} else if latestCIReport != nil {
			arc.reportUnitResults(diffID, *latestCIReport)
		}

		analysesNotes := r.Repo.GetNotes(analyses.Ref, commitHash)
		analysesReports := analyses.ParseAllValid(analysesNotes)
		latestAnalysesReport, err := analyses.GetLatestAnalysesReport(analysesReports)
		if err != nil {
			log.Println("Failed to load the static analysis reports: " + err.Error())
		} else if latestAnalysesReport != nil {
			lintResults, err := latestAnalysesReport.GetLintReportResult()
			if err != nil {
				log.Println("Failed to load the static analysis reports: " + err.Error())
			} else {
				arc.reportLintResults(diffID, lintResults)
			}
		}
	}
}
Exemplo n.º 2
0
// WriteNewReports takes a list of CI reports read from GitHub, and writes to the repo any that are new.
//
// 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 WriteNewReports(reportsMap map[string][]ci.Report, repo repository.Repo, logChan chan<- string) error {
	for commit, commitReports := range reportsMap {
		existingReports := ci.ParseAllValid(repo.GetNotes(ci.Ref, commit))
		for _, report := range commitReports {
			bytes, err := json.Marshal(report)
			note := repository.Note(bytes)
			if err != nil {
				return err
			}
			missing := true
			for _, existing := range existingReports {
				if existing == report {
					missing = false
				}
			}
			if missing {
				logChan <- fmt.Sprintf("Found a new report for %.12s: %q", commit, string(bytes))
				if err := repo.AppendNote(ci.Ref, commit, note); err != nil {
					return err
				}
			}
		}
	}
	return nil
}
Exemplo n.º 3
0
// Details returns the detailed review for the given summary.
func (r *Summary) Details() (*Review, error) {
	review := Review{
		Summary: r,
	}
	currentCommit, err := review.GetHeadCommit()
	if err == nil {
		review.Reports = ci.ParseAllValid(review.Repo.GetNotes(ci.Ref, currentCommit))
		review.Analyses = analyses.ParseAllValid(review.Repo.GetNotes(analyses.Ref, currentCommit))
	}
	return &review, nil
}
Exemplo n.º 4
0
// GetCurrent returns the current, open code review.
//
// If there are multiple matching reviews, then an error is returned.
func GetCurrent(repo repository.Repo) (*Review, error) {
	reviewRef := repo.GetHeadRef()
	currentCommit := repo.GetCommitHash(reviewRef)
	var matchingReviews []Review
	for _, review := range ListOpen(repo) {
		if review.Request.ReviewRef == reviewRef {
			matchingReviews = append(matchingReviews, review)
		}
	}
	if matchingReviews == nil {
		return nil, nil
	}
	if len(matchingReviews) != 1 {
		return nil, fmt.Errorf("There are %d open reviews for the ref \"%s\"", len(matchingReviews), reviewRef)
	}
	r := &matchingReviews[0]
	reports := ci.ParseAllValid(repo.GetNotes(ci.Ref, currentCommit))
	r.Reports = reports
	return r, nil
}
Exemplo n.º 5
0
// Get returns the specified code review.
//
// If no review request exists, the returned review is nil.
func Get(repo repository.Repo, revision string) *Review {
	requestNotes := repo.GetNotes(request.Ref, revision)
	requests := request.ParseAllValid(requestNotes)
	if requests == nil {
		return nil
	}
	review := Review{
		Repo:     repo,
		Revision: revision,
		Request:  requests[len(requests)-1],
	}
	review.Comments = review.loadComments()
	review.Resolved = updateThreadsStatus(review.Comments)
	review.Submitted = repo.IsAncestor(revision, review.Request.TargetRef)
	currentCommit, err := review.GetHeadCommit()
	if err == nil {
		review.Reports = ci.ParseAllValid(repo.GetNotes(ci.Ref, currentCommit))
		review.Analyses = analyses.ParseAllValid(repo.GetNotes(analyses.Ref, currentCommit))
	}
	return &review
}