[buildbucket] Add package deprecated

Move all legacy code to go.chromium.org/luci/buildbucket/deprecated.
Update usages.

Bug: 826006
Change-Id: I3789aeb661aba5f95b2822b40c1553310287a031
Reviewed-on: https://chromium-review.googlesource.com/c/infra/luci/luci-go/+/1564726
Commit-Queue: Ryan Tseng <hinoka@chromium.org>
Reviewed-by: Ryan Tseng <hinoka@chromium.org>
Auto-Submit: Nodir Turakulov <nodir@chromium.org>
diff --git a/buildbucket/README.md b/buildbucket/README.md
deleted file mode 100644
index 64b9c8b..0000000
--- a/buildbucket/README.md
+++ /dev/null
@@ -1,4 +0,0 @@
-# Buildbucket
-
-Buildbucket is a generic build queue. Read more at
-https://chromium.googlesource.com/infra/infra/+/master/appengine/cr-buildbucket/README.md
diff --git a/buildbucket/annotations.go b/buildbucket/deprecated/annotations.go
similarity index 99%
rename from buildbucket/annotations.go
rename to buildbucket/deprecated/annotations.go
index ff2e4a0..bfda7e1 100644
--- a/buildbucket/annotations.go
+++ b/buildbucket/deprecated/annotations.go
@@ -12,7 +12,7 @@
 // See the License for the specific language governing permissions and
 // limitations under the License.
 
-package buildbucket
+package deprecated
 
 import (
 	"context"
diff --git a/buildbucket/annotations_test.go b/buildbucket/deprecated/annotations_test.go
similarity index 98%
rename from buildbucket/annotations_test.go
rename to buildbucket/deprecated/annotations_test.go
index 40339a2..e5330de 100644
--- a/buildbucket/annotations_test.go
+++ b/buildbucket/deprecated/annotations_test.go
@@ -12,7 +12,7 @@
 // See the License for the specific language governing permissions and
 // limitations under the License.
 
-package buildbucket
+package deprecated
 
 import (
 	"context"
diff --git a/buildbucket/build.go b/buildbucket/deprecated/build.go
similarity index 99%
rename from buildbucket/build.go
rename to buildbucket/deprecated/build.go
index 6cbb1a2..2dcb9a1 100644
--- a/buildbucket/build.go
+++ b/buildbucket/deprecated/build.go
@@ -12,7 +12,7 @@
 // See the License for the specific language governing permissions and
 // limitations under the License.
 
-package buildbucket
+package deprecated
 
 import (
 	"context"
diff --git a/buildbucket/build_test.go b/buildbucket/deprecated/build_test.go
similarity index 99%
rename from buildbucket/build_test.go
rename to buildbucket/deprecated/build_test.go
index 94995ae..df980d2 100644
--- a/buildbucket/build_test.go
+++ b/buildbucket/deprecated/build_test.go
@@ -12,7 +12,7 @@
 // See the License for the specific language governing permissions and
 // limitations under the License.
 
-package buildbucket
+package deprecated
 
 import (
 	"encoding/json"
diff --git a/buildbucket/deprecated/doc.go b/buildbucket/deprecated/doc.go
new file mode 100644
index 0000000..c83cd8f
--- /dev/null
+++ b/buildbucket/deprecated/doc.go
@@ -0,0 +1,17 @@
+// Copyright 2018 The LUCI Authors.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//      http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+// Package deprecated is deprecated part of the buildbucket library.
+// TODO(nodir): delete it when Buildbot is dead.
+package deprecated
diff --git a/buildbucket/testdata/annotations/annotations.pb.txt b/buildbucket/deprecated/testdata/annotations/annotations.pb.txt
similarity index 100%
rename from buildbucket/testdata/annotations/annotations.pb.txt
rename to buildbucket/deprecated/testdata/annotations/annotations.pb.txt
diff --git a/buildbucket/testdata/annotations/expected_steps.pb.txt b/buildbucket/deprecated/testdata/annotations/expected_steps.pb.txt
similarity index 100%
rename from buildbucket/testdata/annotations/expected_steps.pb.txt
rename to buildbucket/deprecated/testdata/annotations/expected_steps.pb.txt
diff --git a/buildbucket/testdata/build.json b/buildbucket/deprecated/testdata/build.json
similarity index 100%
rename from buildbucket/testdata/build.json
rename to buildbucket/deprecated/testdata/build.json
diff --git a/buildbucket/testdata/v1_builds.json b/buildbucket/deprecated/testdata/v1_builds.json
similarity index 100%
rename from buildbucket/testdata/v1_builds.json
rename to buildbucket/deprecated/testdata/v1_builds.json
diff --git a/buildbucket/testdata/v2_builds.json b/buildbucket/deprecated/testdata/v2_builds.json
similarity index 100%
rename from buildbucket/testdata/v2_builds.json
rename to buildbucket/deprecated/testdata/v2_builds.json
diff --git a/buildbucket/v1.go b/buildbucket/deprecated/v1.go
similarity index 99%
rename from buildbucket/v1.go
rename to buildbucket/deprecated/v1.go
index 5e4f56a..84c2c6b 100644
--- a/buildbucket/v1.go
+++ b/buildbucket/deprecated/v1.go
@@ -12,7 +12,7 @@
 // See the License for the specific language governing permissions and
 // limitations under the License.
 
-package buildbucket
+package deprecated
 
 import (
 	"encoding/json"
diff --git a/buildbucket/v1_test.go b/buildbucket/deprecated/v1_test.go
similarity index 99%
rename from buildbucket/v1_test.go
rename to buildbucket/deprecated/v1_test.go
index d562cfa..02035af 100644
--- a/buildbucket/v1_test.go
+++ b/buildbucket/deprecated/v1_test.go
@@ -12,7 +12,7 @@
 // See the License for the specific language governing permissions and
 // limitations under the License.
 
-package buildbucket
+package deprecated
 
 import (
 	"bytes"
diff --git a/buildbucket/doc.go b/buildbucket/doc.go
index cd21908..45a95f7 100644
--- a/buildbucket/doc.go
+++ b/buildbucket/doc.go
@@ -12,6 +12,5 @@
 // See the License for the specific language governing permissions and
 // limitations under the License.
 
-// Package buildbucket defines Go types that are more convenient than the API
-// types in "go.chromium.org/luci/common/api/buildbucket/buildbucket/v1"
+// Package buildbucket is a client library for Buildbucket service.
 package buildbucket
diff --git a/milo/buildsource/buildbot/buildstore/build.go b/milo/buildsource/buildbot/buildstore/build.go
index f28378b..316e969 100644
--- a/milo/buildsource/buildbot/buildstore/build.go
+++ b/milo/buildsource/buildbot/buildstore/build.go
@@ -26,7 +26,7 @@
 
 	"go.chromium.org/gae/service/datastore"
 
-	"go.chromium.org/luci/buildbucket"
+	"go.chromium.org/luci/buildbucket/deprecated"
 	buildbucketpb "go.chromium.org/luci/buildbucket/proto"
 	"go.chromium.org/luci/buildbucket/protoutil"
 	bbv1 "go.chromium.org/luci/common/api/buildbucket/buildbucket/v1"
@@ -97,7 +97,7 @@
 
 // EmulationOf returns the Buildbucket build that the given Buildbot build is emulating.
 // Returns (nil, nil) if build is not found.
-func EmulationOf(c context.Context, id buildbot.BuildID) (*buildbucket.Build, error) {
+func EmulationOf(c context.Context, id buildbot.BuildID) (*deprecated.Build, error) {
 	bb, err := buildbucketClient(c)
 	if err != nil {
 		return nil, err
@@ -122,7 +122,7 @@
 	case len(msgs) == 0:
 		return nil, nil
 	default:
-		var b buildbucket.Build
+		var b deprecated.Build
 		return &b, b.ParseMessage(msgs[0])
 	}
 }
diff --git a/milo/buildsource/buildbot/buildstore/buildbucket.go b/milo/buildsource/buildbot/buildstore/buildbucket.go
index 6bae17d..2f59b8c 100644
--- a/milo/buildsource/buildbot/buildstore/buildbucket.go
+++ b/milo/buildsource/buildbot/buildstore/buildbucket.go
@@ -21,7 +21,7 @@
 	"strconv"
 	"strings"
 
-	"go.chromium.org/luci/buildbucket"
+	"go.chromium.org/luci/buildbucket/deprecated"
 	buildbucketpb "go.chromium.org/luci/buildbucket/proto"
 	"go.chromium.org/luci/buildbucket/protoutil"
 	bbv1 "go.chromium.org/luci/common/api/buildbucket/buildbucket/v1"
@@ -49,7 +49,7 @@
 //
 // Does not populate OSFamily, OSVersion, Blame or SourceStamp.Changes
 // fields.
-func buildFromBuildbucket(c context.Context, master string, b *buildbucket.Build, fetchAnnotations bool) (*buildbot.Build, error) {
+func buildFromBuildbucket(c context.Context, master string, b *deprecated.Build, fetchAnnotations bool) (*buildbot.Build, error) {
 	num, err := buildNumber(b)
 	if err != nil {
 		return nil, err
@@ -151,7 +151,7 @@
 	return client, nil
 }
 
-func buildNumber(b *buildbucket.Build) (int, error) {
+func buildNumber(b *deprecated.Build) (int, error) {
 	address := b.Tags.Get("build_address")
 	if address == "" {
 		return 0, errors.Reason("no build_address in build %d", b.ID).Tag(ErrNoBuildNumber).Err()
@@ -181,7 +181,7 @@
 	}
 }
 
-func logLocation(b *buildbucket.Build) (*types.StreamAddr, error) {
+func logLocation(b *deprecated.Build) (*types.StreamAddr, error) {
 	swarmingTags := strpair.ParseMap(b.Tags["swarming_tag"])
 	logLocation := swarmingTags.Get("log_location")
 	if logLocation == "" {
diff --git a/milo/buildsource/buildbot/buildstore/query.go b/milo/buildsource/buildbot/buildstore/query.go
index 55d5aac..42a8666 100644
--- a/milo/buildsource/buildbot/buildstore/query.go
+++ b/milo/buildsource/buildbot/buildstore/query.go
@@ -24,7 +24,7 @@
 
 	"go.chromium.org/gae/service/datastore"
 	"go.chromium.org/gae/service/memcache"
-	"go.chromium.org/luci/buildbucket"
+	"go.chromium.org/luci/buildbucket/deprecated"
 	bbv1 "go.chromium.org/luci/common/api/buildbucket/buildbucket/v1"
 	"go.chromium.org/luci/common/clock"
 	"go.chromium.org/luci/common/data/strpair"
@@ -191,7 +191,7 @@
 	}
 
 	// Extract project and annotate context to use project scoped account.
-	project, _ := buildbucket.BucketNameToV2(bucket)
+	project, _ := deprecated.BucketNameToV2(bucket)
 	if project == "" {
 		return nil, errors.Annotate(err, "unable to extract project from bucket name").Err()
 	}
@@ -229,7 +229,7 @@
 			i := i
 			msg := msg
 			work <- func() error {
-				var buildbucketBuild buildbucket.Build
+				var buildbucketBuild deprecated.Build
 				if err := buildbucketBuild.ParseMessage(msg); err != nil {
 					return err
 				}
diff --git a/milo/buildsource/buildbucket/build_legacy.go b/milo/buildsource/buildbucket/build_legacy.go
index e8bb8b8..980cde0 100644
--- a/milo/buildsource/buildbucket/build_legacy.go
+++ b/milo/buildsource/buildbucket/build_legacy.go
@@ -24,7 +24,7 @@
 
 	"go.chromium.org/gae/service/datastore"
 	"go.chromium.org/luci/auth/identity"
-	"go.chromium.org/luci/buildbucket"
+	"go.chromium.org/luci/buildbucket/deprecated"
 	buildbucketpb "go.chromium.org/luci/buildbucket/proto"
 	"go.chromium.org/luci/buildbucket/protoutil"
 	bbv1 "go.chromium.org/luci/common/api/buildbucket/buildbucket/v1"
@@ -89,7 +89,7 @@
 	if err != nil {
 		return
 	}
-	build, err := buildbucket.GetByAddress(c, client, buildAddress)
+	build, err := deprecated.GetByAddress(c, client, buildAddress)
 	switch {
 	case err != nil:
 		err = errors.Annotate(err, "could not get build at %q", buildAddress).Err()
@@ -144,9 +144,9 @@
 // In case of an error, returns a build with a description of the error
 // and logs the error.
 func toMiloBuildInMemory(c context.Context, msg *bbv1.ApiCommonBuildMessage) (*ui.MiloBuildLegacy, error) {
-	// Parse the build message into a buildbucket.Build struct, filling in the
+	// Parse the build message into a deprecated.Build struct, filling in the
 	// input and output properties that we expect to receive.
-	var b buildbucket.Build
+	var b deprecated.Build
 	var props struct {
 		Revision string `json:"revision"`
 	}
@@ -237,7 +237,7 @@
 		"Swarming task page for task "+task)
 
 	// Use v2 bucket names.
-	_, bucket := buildbucket.BucketNameToV2(b.Bucket)
+	_, bucket := deprecated.BucketNameToV2(b.Bucket)
 
 	result.Summary.ParentLabel = ui.NewLink(
 		b.Builder,
diff --git a/milo/buildsource/buildbucket/builder.go b/milo/buildsource/buildbucket/builder.go
index c090b75..43891ec 100644
--- a/milo/buildsource/buildbucket/builder.go
+++ b/milo/buildsource/buildbucket/builder.go
@@ -27,7 +27,7 @@
 	"google.golang.org/api/googleapi"
 
 	"go.chromium.org/gae/service/memcache"
-	bb "go.chromium.org/luci/buildbucket"
+	"go.chromium.org/luci/buildbucket/deprecated"
 	buildbucketpb "go.chromium.org/luci/buildbucket/proto"
 	bbv1 "go.chromium.org/luci/common/api/buildbucket/buildbucket/v1"
 	"go.chromium.org/luci/common/clock"
@@ -52,7 +52,7 @@
 
 // NewBuilderID does what it says.
 func NewBuilderID(v1Bucket, builder string) (bid BuilderID) {
-	bid.Project, bid.Bucket = bb.BucketNameToV2(v1Bucket)
+	bid.Project, bid.Bucket = deprecated.BucketNameToV2(v1Bucket)
 	bid.Builder = builder
 	return
 }
diff --git a/milo/buildsource/buildbucket/pubsub.go b/milo/buildsource/buildbucket/pubsub.go
index fde9d38..3852fed 100644
--- a/milo/buildsource/buildbucket/pubsub.go
+++ b/milo/buildsource/buildbucket/pubsub.go
@@ -25,7 +25,7 @@
 	"github.com/golang/protobuf/ptypes"
 	"github.com/golang/protobuf/ptypes/timestamp"
 	"go.chromium.org/gae/service/datastore"
-	"go.chromium.org/luci/buildbucket"
+	"go.chromium.org/luci/buildbucket/deprecated"
 	buildbucketpb "go.chromium.org/luci/buildbucket/proto"
 	"go.chromium.org/luci/buildbucket/protoutil"
 	bbv1 "go.chromium.org/luci/common/api/buildbucket/buildbucket/v1"
@@ -184,9 +184,9 @@
 		return errors.Annotate(err, "could not parse pubsub message data").Err()
 	}
 
-	build := buildbucket.Build{}
+	build := deprecated.Build{}
 	if err := build.ParseMessage(&event.Build); err != nil {
-		return errors.Annotate(err, "could not parse buildbucket.Build").Err()
+		return errors.Annotate(err, "could not parse deprecated.Build").Err()
 	}
 
 	bucket = build.Bucket
diff --git a/milo/common/model/build_summary.go b/milo/common/model/build_summary.go
index 830cd36..abab9eb 100644
--- a/milo/common/model/build_summary.go
+++ b/milo/common/model/build_summary.go
@@ -26,7 +26,7 @@
 
 	"go.chromium.org/gae/service/datastore"
 
-	bb "go.chromium.org/luci/buildbucket"
+	"go.chromium.org/luci/buildbucket/deprecated"
 	buildbucketpb "go.chromium.org/luci/buildbucket/proto"
 	"go.chromium.org/luci/buildbucket/protoutil"
 	bbv1 "go.chromium.org/luci/common/api/buildbucket/buildbucket/v1"
@@ -383,7 +383,7 @@
 		address := strings.TrimPrefix(b, source+"/")
 		id, proj, v1bucket, builder, number, err := bbv1.ParseBuildAddress(address)
 		// Use v2 bucket names.
-		_, bucket := bb.BucketNameToV2(v1bucket)
+		_, bucket := deprecated.BucketNameToV2(v1bucket)
 		switch {
 		case err != nil:
 			return InvalidBuildIDURL
diff --git a/milo/frontend/routes.go b/milo/frontend/routes.go
index d68090e..aa0d7d8 100644
--- a/milo/frontend/routes.go
+++ b/milo/frontend/routes.go
@@ -28,7 +28,7 @@
 	"go.chromium.org/luci/appengine/gaeauth/server"
 	"go.chromium.org/luci/appengine/gaemiddleware"
 	"go.chromium.org/luci/appengine/gaemiddleware/standard"
-	bb "go.chromium.org/luci/buildbucket"
+	"go.chromium.org/luci/buildbucket/deprecated"
 	buildbucketpb "go.chromium.org/luci/buildbucket/proto"
 	"go.chromium.org/luci/common/logging"
 	"go.chromium.org/luci/grpc/discovery"
@@ -132,7 +132,7 @@
 	// and common/model/builder_summary.go:SelfLink.
 	r.GET("/p/:project/builders/:bucket/:builder", projectMW, handleError(func(c *router.Context) error {
 		// Handle either v1 or v2 bucket name.
-		_, bucket := bb.BucketNameToV2(c.Params.ByName("bucket"))
+		_, bucket := deprecated.BucketNameToV2(c.Params.ByName("bucket"))
 		if bucket == "" {
 			bucket = c.Params.ByName("bucket")
 		}
@@ -266,7 +266,7 @@
 	bucket := c.Params.ByName("bucket")
 	builder := c.Params.ByName("builder")
 
-	project, _ := bb.BucketNameToV2(bucket)
+	project, _ := deprecated.BucketNameToV2(bucket)
 	u := *c.Request.URL
 	u.Path = fmt.Sprintf("/p/%s/builders/%s/%s", project, bucket, builder)
 	http.Redirect(c.Writer, c.Request, u.String(), http.StatusMovedPermanently)
diff --git a/milo/frontend/view_build.go b/milo/frontend/view_build.go
index 270d089..3a739ae 100644
--- a/milo/frontend/view_build.go
+++ b/milo/frontend/view_build.go
@@ -20,7 +20,7 @@
 	"strconv"
 	"strings"
 
-	bb "go.chromium.org/luci/buildbucket"
+	"go.chromium.org/luci/buildbucket/deprecated"
 	buildbucketpb "go.chromium.org/luci/buildbucket/proto"
 	"go.chromium.org/luci/common/errors"
 	"go.chromium.org/luci/common/logging"
@@ -51,7 +51,7 @@
 	numberOrId := c.Params.ByName("numberOrId")
 	forceBlamelist := c.Request.FormValue("blamelist") != ""
 
-	if _, v2Bucket := bb.BucketNameToV2(bucket); v2Bucket != "" {
+	if _, v2Bucket := deprecated.BucketNameToV2(bucket); v2Bucket != "" {
 		// Params bucket is a v1 bucket, so call the legacy endpoint.
 		return handleLUCIBuildLegacy(c, bucket, buildername, numberOrId)
 	}
diff --git a/milo/frontend/view_builders.go b/milo/frontend/view_builders.go
index fd08192..13cf20a 100644
--- a/milo/frontend/view_builders.go
+++ b/milo/frontend/view_builders.go
@@ -20,8 +20,8 @@
 	"sort"
 
 	"go.chromium.org/gae/service/datastore"
-	bb "go.chromium.org/luci/buildbucket"
 	"go.chromium.org/luci/buildbucket/access"
+	"go.chromium.org/luci/buildbucket/deprecated"
 	buildbucketpb "go.chromium.org/luci/buildbucket/proto"
 	"go.chromium.org/luci/common/data/stringset"
 	"go.chromium.org/luci/common/errors"
@@ -74,7 +74,7 @@
 			}
 			for _, bBucket := range builders.Buckets {
 				// This uses v1 style bucket names, which are luci.project.bucket.
-				project, bucket := bb.BucketNameToV2(bBucket.Name)
+				project, bucket := deprecated.BucketNameToV2(bBucket.Name)
 				if project != projectID {
 					continue
 				}