code: func UpdateBuilderForBuild(c context.Context, build *BuildSummary) error {
  	if datastore.CurrentTransaction(c) == nil {
  		panic("UpdateBuilderForBuild was called outside of a transaction")
  	}
  
  	if !build.Summary.Status.Terminal() {
  		// this build did not complete yet.
  		// There is no new info for the builder.
  		// Do not even bother starting a transaction.
  		return nil
  	}
  
  	// Get or create the relevant BuilderSummary.
  	builder := &BuilderSummary{BuilderID: build.BuilderID}
  	switch err := datastore.Get(c, builder); {
  	case err == datastore.ErrNoSuchEntity:
  		logging.Warningf(c, "creating new BuilderSummary for BuilderID: %s", build.BuilderID)
  	case err != nil:
  		return err
  	case build.Created.Before(builder.LastFinishedCreated):
  		logging.Warningf(c, "message for build %s is out of order", build.BuildID)
  		return nil
  	}
  
  	// Overwrite previous value of ProjectID in case a builder has moved to
  	// another project.
  	builder.ProjectID = build.ProjectID
  	builder.LastFinishedBuildID = build.BuildID
  	builder.LastFinishedCreated = build.Created
  	builder.LastFinishedExperimental = build.Experimental
  	builder.LastFinishedStatus = build.Summary.Status
  	return datastore.Put(c, builder)
  }
docs: // UpdateBuilderForBuild updates the appropriate BuilderSummary for the
  // provided BuildSummary, if needed.
  // In particular, a BuilderSummary is updated with a BuildSummary if the latter is marked complete
  // and has a more recent creation time than the one stored in the BuilderSummary.
  // If there is no existing BuilderSummary for the BuildSummary provided, one is created.
  // Idempotent.
  // c must have a current datastore transaction.