func writeBadge(ctx context.Context, cfg *Config, build *cbpb.Build) error {
	if build.BuildTriggerId == "" {
		return errors.New("no build trigger ID")
	}

	name := build.BuildTriggerId + ".svg"
	log.Printf("Writing badge %v to bucket %v", name, cfg.badgeBucket)

	client, err := storage.NewClient(ctx)
	if err != nil {
		return err
	}

	w := client.Bucket(cfg.badgeBucket).Object(name).NewWriter(ctx)
	w.ContentType = "image/svg+xml"
	w.CacheControl = badgeCacheControl
	if err := CreateBadge(w, build); err != nil {
		return err
	} else if err := w.Close(); err != nil {
		return err
	}

	if cfg.badgeReports {
		rname := build.BuildTriggerId + ".html"
		w := client.Bucket(cfg.badgeBucket).Object(rname).NewWriter(ctx)
		w.ContentType = "text/html; charset=UTF-8"
		w.CacheControl = badgeCacheControl
		if err := CreateReport(w, build); err != nil {
			return err
		} else if err := w.Close(); err != nil {
			return err
		}
	}
	return nil
}
// writeBadge writes a badge image describing build per cfg.
// cfg.checkBadge must be called first to check that a badge should actually be written.
writeBadge writes a badge image describing build per cfg.
cfg.checkBadge must be called first to check that a badge should actually be written.
// writeBadge writes a badge image describing build per cfg . // cfg . checkBadge must be called first to check that a badge should actually be written .
func writeBadge(ctx context.Context, cfg *Config, build *cbpb.Build) error {
	if build.BuildTriggerId == "" {
		return errors.New("no build trigger ID")
	}
	name := build.BuildTriggerId + ".svg"
	log.Printf("Writing badge %v to bucket %v", name, cfg.badgeBucket)
	client, err := storage.NewClient(ctx)
	if err != nil {
		return err
	}
	w := client.Bucket(cfg.badgeBucket).Object(name).NewWriter(ctx)
	w.ContentType = "image/svg+xml"
	w.CacheControl = badgeCacheControl
	if err := CreateBadge(w, build); err != nil {
		return err
	} else if err := w.Close(); err != nil {
		return err
	}
	if cfg.badgeReports {
		rname := build.BuildTriggerId + ".html"
		w := client.Bucket(cfg.badgeBucket).Object(rname).NewWriter(ctx)
		w.ContentType = "text/html; charset=UTF-8"
		w.CacheControl = badgeCacheControl
		if err := CreateReport(w, build); err != nil {
			return err
		} else if err := w.Close(); err != nil {
			return err
		}
	}
	return nil
}
func writeBadge ( ctx context . Context , cfg * Config , build * cbpb . Build ) error { if build . BuildTriggerId == " " { return errors . New ( " " ) } name := build . BuildTriggerId + " " log . Printf ( " " , name , cfg . badgeBucket ) client , err := storage . NewClient ( ctx ) if err != nil { return err } w := client . Bucket ( cfg . badgeBucket ) . Object ( name ) . NewWriter ( ctx ) w . ContentType = " " w . CacheControl = badgeCacheControl if err := CreateBadge ( w , build ) ; err != nil { return err } else if err := w . Close ( ) ; err != nil { return err } if cfg . badgeReports { rname := build . BuildTriggerId + " " w := client . Bucket ( cfg . badgeBucket ) . Object ( rname ) . NewWriter ( ctx ) w . ContentType = " " w . CacheControl = badgeCacheControl if err := CreateReport ( w , build ) ; err != nil { return err } else if err := w . Close ( ) ; err != nil { return err } } return nil }
writeBadge writes a badge image describing build per cfg.
writeBadge writes a badge image describing build per cfg .