Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into megacheck-fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
klauern committed Aug 12, 2017
2 parents eb6a363 + c579ca2 commit 2ac3573
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 36 deletions.
4 changes: 2 additions & 2 deletions artifact.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,15 +87,15 @@ func (a Artifact) SaveToDir(dir string) (bool, error) {
func (a Artifact) validateDownload(path string) (bool, error) {
localHash := a.getMD5local(path)

fp := Fingerprint{Jenkins: a.Jenkins, Base: "/fingerprint/", Id: localHash, Raw: new(fingerPrintResponse)}
fp := FingerPrint{Jenkins: a.Jenkins, Base: "/fingerprint/", Id: localHash, Raw: new(FingerPrintResponse)}

valid, err := fp.ValidateForBuild(a.FileName, a.Build)

if err != nil {
return false, err
}
if !valid {
return false, errors.New("Fingerprint of the downloaded artifact could not be verified")
return false, errors.New("FingerPrint of the downloaded artifact could not be verified")
}
return true, nil
}
Expand Down
26 changes: 13 additions & 13 deletions build.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ type BuildResponse struct {
FullName string `json:"fullName"`
} `json:"author"`
Comment string `json:"comment"`
CommitId string `json:"commitId"`
CommitID string `json:"commitId"`
Date string `json:"date"`
ID string `json:"id"`
Msg string `json:"msg"`
Expand All @@ -144,16 +144,16 @@ type BuildResponse struct {
ID string `json:"id"`
KeepLog bool `json:"keepLog"`
Number int64 `json:"number"`
QueueId int64 `json:"queueId"`
QueueID int64 `json:"queueId"`
Result string `json:"result"`
Timestamp int64 `json:"timestamp"`
URL string `json:"url"`
MavenArtifacts interface{} `json:"mavenArtifacts"`
MavenVersionUsed string `json:"mavenVersionUsed"`
Fingerprint []fingerPrintResponse
FingerPrint []FingerPrintResponse
Runs []struct {
Number int64
Url string
URL string
} `json:"runs"`
}

Expand Down Expand Up @@ -253,12 +253,12 @@ func (b *Build) GetDownstreamBuilds() ([]*Build, error) {
return nil, err
}
for _, job := range downstreamJobs {
allBuildIds, err := job.GetAllBuildIds()
allBuildIDs, err := job.GetAllBuildIds()
if err != nil {
return nil, err
}
for _, buildId := range allBuildIds {
build, err := job.GetBuild(buildId.Number)
for _, buildID := range allBuildIDs {
build, err := job.GetBuild(buildID.Number)
if err != nil {
return nil, err
}
Expand All @@ -276,7 +276,7 @@ func (b *Build) GetDownstreamBuilds() ([]*Build, error) {
func (b *Build) GetDownstreamJobNames() []string {
result := make([]string, 0)
downstreamJobs := b.Job.GetDownstreamJobsMetadata()
fingerprints := b.GetAllFingerprints()
fingerprints := b.GetAllFingerPrints()
for _, fingerprint := range fingerprints {
for _, usage := range fingerprint.Raw.Usage {
for _, job := range downstreamJobs {
Expand All @@ -289,11 +289,11 @@ func (b *Build) GetDownstreamJobNames() []string {
return result
}

func (b *Build) GetAllFingerprints() []*Fingerprint {
func (b *Build) GetAllFingerPrints() []*FingerPrint {
b.Poll(3)
result := make([]*Fingerprint, len(b.Raw.Fingerprint))
for i, f := range b.Raw.Fingerprint {
result[i] = &Fingerprint{Jenkins: b.Jenkins, Base: "/fingerprint/", Id: f.Hash, Raw: &f}
result := make([]*FingerPrint, len(b.Raw.FingerPrint))
for i, f := range b.Raw.FingerPrint {
result[i] = &FingerPrint{Jenkins: b.Jenkins, Base: "/fingerprint/", Id: f.Hash, Raw: &f}
}
return result
}
Expand Down Expand Up @@ -353,7 +353,7 @@ func (b *Build) GetMatrixRuns() ([]*Build, error) {
r, _ := regexp.Compile(`job/(.*?)/(.*?)/(\d+)/`)

for i, run := range runs {
result[i] = &Build{Jenkins: b.Jenkins, Job: b.Job, Raw: new(BuildResponse), Depth: 1, Base: "/" + r.FindString(run.Url)}
result[i] = &Build{Jenkins: b.Jenkins, Job: b.Job, Raw: new(BuildResponse), Depth: 1, Base: "/" + r.FindString(run.URL)}
result[i].Poll()
}
return result, nil
Expand Down
12 changes: 6 additions & 6 deletions build_history.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
)

// Parse jenkins ajax response in order find the current jenkins build history
func parseBuildHistory(d io.ReadCloser) []*History {
func parseBuildHistory(d io.Reader) []*History {
z := html.NewTokenizer(d)
depth := 0
buildRowCellDepth := -1
Expand All @@ -29,7 +29,7 @@ func parseBuildHistory(d io.ReadCloser) []*History {
a := attr(z)
// <img src="/static/f2881562/images/16x16/red.png" alt="Failed &gt; Console Output" tooltip="Failed &gt; Console Output" style="width: 16px; height: 16px; " class="icon-red icon-sm" />
if string(tn) == "img" {
if hasCssClass(a, "icon-sm") && buildRowCellDepth > -1 {
if hasCSSClass(a, "icon-sm") && buildRowCellDepth > -1 {
if alt, found := a["alt"]; found {
curBuild.BuildStatus = strings.Fields(alt)[0]
}
Expand All @@ -44,15 +44,15 @@ func parseBuildHistory(d io.ReadCloser) []*History {
a := attr(z)
// <td class="build-row-cell">
if string(tn) == "td" {
if hasCssClass(a, "build-row-cell") {
if hasCSSClass(a, "build-row-cell") {
buildRowCellDepth = depth
curBuild = &History{}
builds = append(builds, curBuild)
}
}
// <a update-parent-class=".build-row" href="/job/appscode/job/43/job/build-binary/227/" class="tip model-link inside build-link display-name">#227</a>
if string(tn) == "a" {
if hasCssClass(a, "build-link") && buildRowCellDepth > -1 {
if hasCSSClass(a, "build-link") && buildRowCellDepth > -1 {
if href, found := a["href"]; found {
parts := strings.Split(href, "/")
if num, err := strconv.Atoi(parts[len(parts)-2]); err == nil {
Expand All @@ -63,7 +63,7 @@ func parseBuildHistory(d io.ReadCloser) []*History {
}
// <div time="1469024602546" class="pane build-details"> ... </div>
if string(tn) == "div" {
if hasCssClass(a, "build-details") && buildRowCellDepth > -1 {
if hasCSSClass(a, "build-details") && buildRowCellDepth > -1 {
if t, found := a["time"]; found {
if msec, err := strconv.ParseInt(t, 10, 0); err == nil {
curBuild.BuildTimestamp = msec / 1000
Expand Down Expand Up @@ -97,7 +97,7 @@ func attr(z *html.Tokenizer) map[string]string {
return a
}

func hasCssClass(a map[string]string, className string) bool {
func hasCSSClass(a map[string]string, className string) bool {
if classes, found := a["class"]; found {
for _, class := range strings.Fields(classes) {
if class == className {
Expand Down
14 changes: 7 additions & 7 deletions fingerprint.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@ import (
"fmt"
)

type Fingerprint struct {
type FingerPrint struct {
Jenkins *Jenkins
Base string
Id string
Raw *fingerPrintResponse
Raw *FingerPrintResponse
}

type fingerPrintResponse struct {
type FingerPrintResponse struct {
FileName string `json:"fileName"`
Hash string `json:"hash"`
Original struct {
Expand All @@ -45,7 +45,7 @@ type fingerPrintResponse struct {
} `json:"usage"`
}

func (f Fingerprint) Valid() (bool, error) {
func (f FingerPrint) Valid() (bool, error) {
status, err := f.Poll()

if err != nil {
Expand All @@ -58,7 +58,7 @@ func (f Fingerprint) Valid() (bool, error) {
return true, nil
}

func (f Fingerprint) ValidateForBuild(filename string, build *Build) (bool, error) {
func (f FingerPrint) ValidateForBuild(filename string, build *Build) (bool, error) {
valid, err := f.Valid()
if err != nil {
return false, err
Expand All @@ -78,15 +78,15 @@ func (f Fingerprint) ValidateForBuild(filename string, build *Build) (bool, erro
return false, nil
}

func (f Fingerprint) GetInfo() (*fingerPrintResponse, error) {
func (f FingerPrint) GetInfo() (*FingerPrintResponse, error) {
_, err := f.Poll()
if err != nil {
return nil, err
}
return f.Raw, nil
}

func (f Fingerprint) Poll() (int, error) {
func (f FingerPrint) Poll() (int, error) {
response, err := f.Jenkins.Requester.GetJSON(f.Base+f.Id, f.Raw, nil)
if err != nil {
return 0, err
Expand Down
8 changes: 4 additions & 4 deletions jenkins.go
Original file line number Diff line number Diff line change
Expand Up @@ -441,8 +441,8 @@ func (j *Jenkins) GetQueueUrl() string {
}

// Get Artifact data by Hash
func (j *Jenkins) GetArtifactData(id string) (*fingerPrintResponse, error) {
fp := Fingerprint{Jenkins: j, Base: "/fingerprint/", Id: id, Raw: new(fingerPrintResponse)}
func (j *Jenkins) GetArtifactData(id string) (*FingerPrintResponse, error) {
fp := FingerPrint{Jenkins: j, Base: "/fingerprint/", Id: id, Raw: new(FingerPrintResponse)}
return fp.GetInfo()
}

Expand All @@ -468,9 +468,9 @@ func (j *Jenkins) HasPlugin(name string) (*Plugin, error) {
return p.Contains(name), nil
}

// Verify Fingerprint
// Verify FingerPrint
func (j *Jenkins) ValidateFingerPrint(id string) (bool, error) {
fp := Fingerprint{Jenkins: j, Base: "/fingerprint/", Id: id, Raw: new(fingerPrintResponse)}
fp := FingerPrint{Jenkins: j, Base: "/fingerprint/", Id: id, Raw: new(FingerPrintResponse)}
valid, err := fp.Valid()
if err != nil {
return false, err
Expand Down
8 changes: 4 additions & 4 deletions request.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,18 +109,18 @@ func (r *Requester) PostXML(endpoint string, xml string, responseStruct interfac
return r.Do(ar, &responseStruct, querystring)
}

func (r *Requester) GetJSON(endpoint string, responseStruct interface{}, querystring map[string]string) (*http.Response, error) {
func (r *Requester) GetJSON(endpoint string, responseStruct interface{}, query map[string]string) (*http.Response, error) {
ar := NewAPIRequest("GET", endpoint, nil)
ar.SetHeader("Content-Type", "application/json")
ar.Suffix = "api/json"
return r.Do(ar, &responseStruct, querystring)
return r.Do(ar, &responseStruct, query)
}

func (r *Requester) GetXML(endpoint string, responseStruct interface{}, querystring map[string]string) (*http.Response, error) {
func (r *Requester) GetXML(endpoint string, responseStruct interface{}, query map[string]string) (*http.Response, error) {
ar := NewAPIRequest("GET", endpoint, nil)
ar.SetHeader("Content-Type", "application/xml")
ar.Suffix = ""
return r.Do(ar, responseStruct, querystring)
return r.Do(ar, responseStruct, query)
}

func (r *Requester) Get(endpoint string, responseStruct interface{}, querystring map[string]string) (*http.Response, error) {
Expand Down

0 comments on commit 2ac3573

Please sign in to comment.