Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1490)

Unified Diff: milo/buildsource/rawpresentation/build.go

Issue 2977863002: [milo] Refactor all html knowledge out of backends. (Closed)
Patch Set: now with case insensitivity Created 3 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « milo/buildsource/id.go ('k') | milo/buildsource/rawpresentation/html.go » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: milo/buildsource/rawpresentation/build.go
diff --git a/milo/buildsource/rawpresentation/build.go b/milo/buildsource/rawpresentation/build.go
index 79fb8eee260e32ac419f8b20bf9a54b0cfadf4b6..d9d0167f5c38526def77559d7fbafb7917c0303c 100644
--- a/milo/buildsource/rawpresentation/build.go
+++ b/milo/buildsource/rawpresentation/build.go
@@ -15,10 +15,13 @@
package rawpresentation
import (
- "errors"
- "fmt"
+ "strings"
"time"
+ "github.com/golang/protobuf/proto"
+ "golang.org/x/net/context"
+
+ "github.com/luci/luci-go/common/errors"
log "github.com/luci/luci-go/common/logging"
"github.com/luci/luci-go/common/proto/google"
miloProto "github.com/luci/luci-go/common/proto/milo"
@@ -29,9 +32,7 @@ import (
"github.com/luci/luci-go/luci_config/common/cfgtypes"
"github.com/luci/luci-go/milo/api/resp"
"github.com/luci/luci-go/milo/buildsource/rawpresentation/internal"
-
- "github.com/golang/protobuf/proto"
- "golang.org/x/net/context"
+ "github.com/luci/luci-go/milo/common"
)
const (
@@ -60,11 +61,11 @@ type AnnotationStream struct {
// Normalize validates and normalizes the stream's parameters.
func (as *AnnotationStream) Normalize() error {
if err := as.Project.Validate(); err != nil {
- return fmt.Errorf("Invalid project name: %s", as.Project)
+ return errors.Annotate(err, "Invalid project name: %s", as.Project).Tag(common.CodeParameterError).Err()
}
if err := as.Path.Validate(); err != nil {
- return fmt.Errorf("Invalid log stream path %q: %s", as.Path, err)
+ return errors.Annotate(err, "Invalid log stream path %q", as.Path).Tag(common.CodeParameterError).Err()
}
return nil
@@ -231,3 +232,59 @@ func (b *ViewerURLBuilder) BuildLink(l *miloProto.Link) *resp.Link {
return nil
}
}
+
+// BuildID implements buildsource.ID.
+type BuildID struct {
+ Host string
+ Project cfgtypes.ProjectName
+ Path types.StreamPath
+}
+
+// GetLog implements buildsource.ID.
+func (b *BuildID) GetLog(context.Context, string) (string, bool, error) { panic("not implemented") }
+
+// Get implements buildsource.ID.
+func (b *BuildID) Get(c context.Context) (*resp.MiloBuild, error) {
+ as := AnnotationStream{
+ Project: b.Project,
+ Path: b.Path,
+ }
+ if err := as.Normalize(); err != nil {
+ return nil, err
+ }
+
+ // Setup our LogDog client.
+ var err error
+ if as.Client, err = NewClient(c, b.Host); err != nil {
+ return nil, errors.Annotate(err, "generating LogDog Client").Err()
+ }
+
+ // Load the Milo annotation protobuf from the annotation stream.
+ switch _, err := as.Fetch(c); errors.Unwrap(err) {
+ case nil, errNoEntries:
+
+ case coordinator.ErrNoSuchStream:
+ return nil, common.CodeNotFound.Tag().Apply(err)
+
+ case coordinator.ErrNoAccess:
+ return nil, common.CodeNoAccess.Tag().Apply(err)
+
+ case errNotMilo, errNotDatagram:
+ // The user requested a LogDog url that isn't a Milo annotation.
+ return nil, common.CodeParameterError.Tag().Apply(err)
+
+ default:
+ return nil, errors.Annotate(err, "failed to load stream").Err()
+ }
+
+ return as.toMiloBuild(c), nil
+}
+
+// NewBuildID generates a new un-validated BuildID.
+func NewBuildID(host, project, path string) *BuildID {
+ return &BuildID{
+ strings.TrimSpace(host),
+ cfgtypes.ProjectName(project),
+ types.StreamPath(strings.Trim(path, "/")),
+ }
+}
« no previous file with comments | « milo/buildsource/id.go ('k') | milo/buildsource/rawpresentation/html.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698