changelog-web: Use build-num for crosland link
Changelog error will replace image name with build number when generating crosland links, since go/crosland does not support image name.
BUG=b/160901711
TEST=unittests, run local
Change-Id: Ic8299d4efdeeba3f233638107e1014748dde9a28
diff --git a/src/pkg/changelog/changelog.go b/src/pkg/changelog/changelog.go
index 3193619..de5b49f 100644
--- a/src/pkg/changelog/changelog.go
+++ b/src/pkg/changelog/changelog.go
@@ -189,7 +189,7 @@
// mappedManifest retrieves a Manifest file from GoB and unmarshals XML.
// Returns a mapping of repository ID to repository data.
-func mappedManifest(client gitilesProto.GitilesClient, repo string, buildNum string) (map[string]*repo, utils.ChangelogError) {
+func mappedManifest(client gitilesProto.GitilesClient, repo string, buildInput, buildNum string) (map[string]*repo, utils.ChangelogError) {
log.Debugf("Retrieving manifest file for build %s\n", buildNum)
response, err := utils.DownloadManifest(client, repo, buildNum)
if err != nil {
@@ -198,7 +198,7 @@
if httpCode == "403" {
return nil, utils.ForbiddenError
} else if httpCode == "404" {
- return nil, utils.BuildNotFound(buildNum)
+ return nil, utils.BuildNotFound(buildInput)
}
return nil, utils.InternalServerError
}
@@ -207,7 +207,7 @@
log.Errorf("mappedManifest: error retrieving mapped manifest file from repo %s for build %s:\n%v", repo, buildNum, err)
httpCode := utils.GitilesErrCode(err)
if httpCode == "404" {
- return nil, utils.BuildNotFound(buildNum)
+ return nil, utils.BuildNotFound(buildInput)
}
return nil, utils.InternalServerError
}
@@ -338,10 +338,10 @@
if err != nil {
return nil, nil, err
}
- sourceRepos, sourceErr := mappedManifest(manifestClient, repo, sourceBuildNum)
- targetRepos, targetErr := mappedManifest(manifestClient, repo, targetBuildNum)
+ sourceRepos, sourceErr := mappedManifest(manifestClient, repo, source, sourceBuildNum)
+ targetRepos, targetErr := mappedManifest(manifestClient, repo, target, targetBuildNum)
if sourceErr != nil && sourceErr.HTTPCode() == "404" && targetErr != nil && targetErr.HTTPCode() == "404" {
- return nil, nil, utils.BothBuildsNotFound(croslandURL, source, target)
+ return nil, nil, utils.BothBuildsNotFound(croslandURL, source, target, sourceBuildNum, targetBuildNum)
} else if sourceErr != nil {
return nil, nil, sourceErr
} else if targetErr != nil {
diff --git a/src/pkg/utils/changelogerror.go b/src/pkg/utils/changelogerror.go
index f59a206..b7e734d 100644
--- a/src/pkg/utils/changelogerror.go
+++ b/src/pkg/utils/changelogerror.go
@@ -125,7 +125,7 @@
}
// BothBuildsNotFound indicates that neither build was not found
-func BothBuildsNotFound(croslandURL, source, target string) *UtilChangelogError {
+func BothBuildsNotFound(croslandURL, source, target, sourceBuildNum, targetBuildNum string) *UtilChangelogError {
return &UtilChangelogError{
httpCode: "404",
header: "Build Not Found",
@@ -146,8 +146,8 @@
"could not be found.",
"It may be possible that the inputs are either invalid or both belong to pre-Cusky builds.",
"If both of the inputs belong to pre-Cusky builds, please check",
- croslandLink(croslandURL, source, target),
- croslandLink(croslandURL, source, target),
+ croslandLink(croslandURL, sourceBuildNum, targetBuildNum),
+ croslandLink(croslandURL, sourceBuildNum, targetBuildNum),
"Otherwise, please input valid build numbers",
"(example: 13310.1035.0) or valid image names (example: cos-rc-85-13310-1034-0).",
),
diff --git a/src/pkg/utils/changelogerror_test.go b/src/pkg/utils/changelogerror_test.go
index f24ea1a..3e68abf 100644
--- a/src/pkg/utils/changelogerror_test.go
+++ b/src/pkg/utils/changelogerror_test.go
@@ -89,8 +89,8 @@
}
func TestBothBuildsNotFound(t *testing.T) {
- source := "1a"
- target := "ddddddd"
+ source := "cos-stable-81-12871-103-0"
+ target := "cos-stable-81-12871-117-0"
croslandURL := "https://www.google.com"
expectedCode := "404"
expectedErrHeader := "Build Not Found"
@@ -116,7 +116,7 @@
"Otherwise, please input valid build numbers",
"(example: 13310.1035.0) or valid image names (example: cos-rc-85-13310-1034-0).",
)
- err := BothBuildsNotFound(croslandURL, source, target)
+ err := BothBuildsNotFound(croslandURL, source, target, source, target)
if err.HTTPCode() != expectedCode {
t.Errorf("expected HTTP code %s, got %s", expectedCode, err.HTTPCode())
} else if err.Header() != expectedErrHeader {
@@ -131,7 +131,7 @@
}
func TestBuildNotFound(t *testing.T) {
- buildNumber := "15000.0.0"
+ buildNumber := "cos-stable-81-12871-117-0"
expectedCode := "404"
expectedErrHeader := "Build Not Found"
expectedErrStr := strings.Join([]string{