Commit 4b68055c by Mario Trangoni Committed by Leonard Gram

scripts/build/*: Fix some golint issues

See,

$ gometalinter --vendor --disable-all --enable=golint ./...
build/release_publisher/externalrelease.go:55:6:warning: type getHttpContents should be getHTTPContents (golint)
build/release_publisher/publisher.go:18:2:warning: struct field apiUri should be apiURI (golint)
build/release_publisher/publisher.go:66:6:warning: exported type ReleaseType should have comment or be unexported (golint)
build/release_publisher/publisher.go:69:2:warning: exported const STABLE should have comment (or a comment on this block) or be unexported (golint)
build/release_publisher/publisher.go:185:16:warning: should replace errors.New(fmt.Sprintf(...)) with fmt.Errorf(...) (golint)
build/release_publisher/publisher_test.go:102:6:warning: type mockHttpGetter should be mockHTTPGetter (golint)
parent d5f63d99
...@@ -17,7 +17,7 @@ type releaseFromExternalContent struct { ...@@ -17,7 +17,7 @@ type releaseFromExternalContent struct {
func (re releaseFromExternalContent) prepareRelease(baseArchiveURL, whatsNewURL string, releaseNotesURL string, nightly bool) (*release, error) { func (re releaseFromExternalContent) prepareRelease(baseArchiveURL, whatsNewURL string, releaseNotesURL string, nightly bool) (*release, error) {
version := re.rawVersion[1:] version := re.rawVersion[1:]
beta := strings.Contains(version, "beta") beta := strings.Contains(version, "beta")
var rt ReleaseType var rt releaseType
if beta { if beta {
rt = BETA rt = BETA
} else if nightly { } else if nightly {
...@@ -52,9 +52,9 @@ type urlGetter interface { ...@@ -52,9 +52,9 @@ type urlGetter interface {
getContents(url string) (string, error) getContents(url string) (string, error)
} }
type getHttpContents struct{} type getHTTPContents struct{}
func (getHttpContents) getContents(url string) (string, error) { func (getHTTPContents) getContents(url string) (string, error) {
response, err := http.Get(url) response, err := http.Get(url)
if err != nil { if err != nil {
return "", err return "", err
......
...@@ -20,7 +20,7 @@ type releaseLocalSources struct { ...@@ -20,7 +20,7 @@ type releaseLocalSources struct {
func (r releaseLocalSources) prepareRelease(baseArchiveURL, whatsNewURL string, releaseNotesURL string, nightly bool) (*release, error) { func (r releaseLocalSources) prepareRelease(baseArchiveURL, whatsNewURL string, releaseNotesURL string, nightly bool) (*release, error) {
if !nightly { if !nightly {
return nil, errors.New("Local releases only supported for nightly builds.") return nil, errors.New("Local releases only supported for nightly builds")
} }
buildData := r.findBuilds(baseArchiveURL) buildData := r.findBuilds(baseArchiveURL)
...@@ -91,5 +91,5 @@ func grabVersion(name string, suffix string) (string, error) { ...@@ -91,5 +91,5 @@ func grabVersion(name string, suffix string) (string, error) {
return string(match[2]), nil return string(match[2]), nil
} }
return "", errors.New("No version found.") return "", errors.New("No version found")
} }
...@@ -72,7 +72,7 @@ func main() { ...@@ -72,7 +72,7 @@ func main() {
} }
} else { } else {
builder = releaseFromExternalContent{ builder = releaseFromExternalContent{
getter: getHttpContents{}, getter: getHTTPContents{},
rawVersion: version, rawVersion: version,
artifactConfigurations: buildArtifacts, artifactConfigurations: buildArtifacts,
} }
...@@ -80,7 +80,7 @@ func main() { ...@@ -80,7 +80,7 @@ func main() {
p := publisher{ p := publisher{
apiKey: apiKey, apiKey: apiKey,
apiUri: "https://grafana.com/api", apiURI: "https://grafana.com/api",
product: product, product: product,
dryRun: dryRun, dryRun: dryRun,
enterprise: enterprise, enterprise: enterprise,
......
...@@ -9,13 +9,11 @@ import ( ...@@ -9,13 +9,11 @@ import (
"net/http" "net/http"
"strings" "strings"
"time" "time"
"github.com/pkg/errors"
) )
type publisher struct { type publisher struct {
apiKey string apiKey string
apiUri string apiURI string
product string product string
dryRun bool dryRun bool
enterprise bool enterprise bool
...@@ -63,23 +61,26 @@ func (p *publisher) postRelease(r *release) error { ...@@ -63,23 +61,26 @@ func (p *publisher) postRelease(r *release) error {
return nil return nil
} }
type ReleaseType int type releaseType int
const ( const (
STABLE ReleaseType = iota + 1 // STABLE is a release type constant
STABLE releaseType = iota + 1
// BETA is a release type constant
BETA BETA
// NIGHTLY is a release type constant
NIGHTLY NIGHTLY
) )
func (rt ReleaseType) beta() bool { func (rt releaseType) beta() bool {
return rt == BETA return rt == BETA
} }
func (rt ReleaseType) stable() bool { func (rt releaseType) stable() bool {
return rt == STABLE return rt == STABLE
} }
func (rt ReleaseType) nightly() bool { func (rt releaseType) nightly() bool {
return rt == NIGHTLY return rt == NIGHTLY
} }
...@@ -89,7 +90,7 @@ type buildArtifact struct { ...@@ -89,7 +90,7 @@ type buildArtifact struct {
urlPostfix string urlPostfix string
} }
func (t buildArtifact) getURL(baseArchiveURL, version string, releaseType ReleaseType) string { func (t buildArtifact) getURL(baseArchiveURL, version string, releaseType releaseType) string {
prefix := "-" prefix := "-"
rhelReleaseExtra := "" rhelReleaseExtra := ""
...@@ -182,13 +183,13 @@ func filterBuildArtifacts(filters []artifactFilter) ([]buildArtifact, error) { ...@@ -182,13 +183,13 @@ func filterBuildArtifacts(filters []artifactFilter) ([]buildArtifact, error) {
} }
if !matched { if !matched {
return nil, errors.New(fmt.Sprintf("No buildArtifact for os=%v, arch=%v", f.os, f.arch)) return nil, fmt.Errorf("No buildArtifact for os=%v, arch=%v", f.os, f.arch)
} }
} }
return artifacts, nil return artifacts, nil
} }
func newBuild(baseArchiveURL string, ba buildArtifact, version string, rt ReleaseType, sha256 string) build { func newBuild(baseArchiveURL string, ba buildArtifact, version string, rt releaseType, sha256 string) build {
return build{ return build{
Os: ba.os, Os: ba.os,
URL: ba.getURL(baseArchiveURL, version, rt), URL: ba.getURL(baseArchiveURL, version, rt),
...@@ -198,7 +199,7 @@ func newBuild(baseArchiveURL string, ba buildArtifact, version string, rt Releas ...@@ -198,7 +199,7 @@ func newBuild(baseArchiveURL string, ba buildArtifact, version string, rt Releas
} }
func (p *publisher) apiURL(url string) string { func (p *publisher) apiURL(url string) string {
return fmt.Sprintf("%s/%s%s", p.apiUri, p.product, url) return fmt.Sprintf("%s/%s%s", p.apiURI, p.product, url)
} }
func (p *publisher) postRequest(url string, obj interface{}, desc string) error { func (p *publisher) postRequest(url string, obj interface{}, desc string) error {
......
...@@ -64,7 +64,7 @@ func TestPreparingReleaseFromRemote(t *testing.T) { ...@@ -64,7 +64,7 @@ func TestPreparingReleaseFromRemote(t *testing.T) {
for _, test := range cases { for _, test := range cases {
builder := releaseFromExternalContent{ builder := releaseFromExternalContent{
getter: mockHttpGetter{}, getter: mockHTTPGetter{},
rawVersion: test.version, rawVersion: test.version,
artifactConfigurations: test.buildArtifacts, artifactConfigurations: test.buildArtifacts,
} }
...@@ -99,9 +99,9 @@ func TestPreparingReleaseFromRemote(t *testing.T) { ...@@ -99,9 +99,9 @@ func TestPreparingReleaseFromRemote(t *testing.T) {
} }
} }
type mockHttpGetter struct{} type mockHTTPGetter struct{}
func (mockHttpGetter) getContents(url string) (string, error) { func (mockHTTPGetter) getContents(url string) (string, error) {
return url, nil return url, nil
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment