Exemplo n.º 1
0
// buildFromCommit builds a buildbot.Build from the commit and the info
// returned from the Apiary API.  It also returns a key that uniqely identifies
// this build.
func buildFromCommit(build *androidbuildinternal.Build, commit *vcsinfo.ShortCommit) (string, *buildbot.Build) {
	codename := util.StringToCodeName(build.Target.Name)
	key := build.Branch + ":" + build.Target.Name + ":" + build.BuildId
	b := &buildbot.Build{
		Builder:     codename,
		Master:      FAKE_MASTER,
		Number:      0,
		BuildSlave:  FAKE_BUILDSLAVE,
		Branch:      "master",
		Commits:     nil,
		GotRevision: commit.Hash,
		Properties: [][]interface{}{
			[]interface{}{"androidinternal_buildid", build.BuildId, "tradefed"},
			[]interface{}{"buildbotURL", "https://internal.skia.org/", "tradefed"},
		},
		PropertiesStr: "",
		Results:       buildbot.BUILDBOT_FAILURE,
		Steps:         nil,
		Times:         nil,
		Started:       float64(build.CreationTimestamp) / 1000.0,
		Comments:      nil,
		Repository:    "https://skia.googlesource.com/skia.git",
	}
	// Fill in PropertiesStr based on Properties.
	props, err := json.Marshal(b.Properties)
	if err == nil {
		b.PropertiesStr = string(props)
	} else {
		glog.Errorf("Failed to encode properties: %s", err)
	}
	if build.Successful {
		b.Results = buildbot.BUILDBOT_SUCCESS
	}
	// Only fill in Finished if the build has completed.
	if isFinished(build) {
		b.Finished = float64(time.Now().UTC().Unix())
	}
	return key, b
}
Exemplo n.º 2
0
// ingestBuildHandler parses the JSON body as a build and ingests it. The request must be
// authenticated via the protocol implemented in the webhook package. The client should retry this
// request several times, because some errors may be temporary.
func ingestBuildHandler(w http.ResponseWriter, r *http.Request) {
	data, err := webhook.AuthenticateRequest(r)
	if err != nil {
		glog.Errorf("Failed authentication in ingestBuildHandler: %s", err)
		util.ReportError(w, r, fmt.Errorf("Failed authentication."), "")
		return
	}
	vars := map[string]string{}
	if err := json.Unmarshal(data, &vars); err != nil {
		util.ReportError(w, r, err, "Failed to parse request.")
		return
	}
	target := vars["target"]
	commitHash := vars["commitHash"]
	status := vars["status"]
	if target == "" || commitHash == "" || status == "" {
		util.ReportError(w, r, err, "Invalid parameters.")
		return
	}
	cl := vars["changeListNumber"]
	link := vars["testResultsLink"]
	codename := ""
	if noCodenameTargets[target] {
		codename = target
	} else {
		codename = util.StringToCodeName(target)
	}
	buildbotResults, err := buildbot.ParseResultsString(status)
	if err != nil {
		util.ReportError(w, r, err, "Invalid parameters.")
		return
	}
	buildbotTime := time.Now().UTC()
	b := &buildbot.Build{
		Builder:       codename,
		Master:        FAKE_MASTER,
		Number:        0,
		BuildSlave:    FAKE_BUILDSLAVE,
		Branch:        "master",
		Commits:       nil,
		GotRevision:   commitHash,
		PropertiesStr: "",
		Results:       buildbotResults,
		Steps:         nil,
		Started:       buildbotTime,
		Finished:      buildbotTime,
		Comments:      nil,
		Repository:    "https://skia.googlesource.com/skia.git",
	}
	if cl != "" {
		if clNum, err := strconv.Atoi(cl); err == nil {
			b.Properties = append(b.Properties, []interface{}{"changeListNumber", strconv.Itoa(clNum), "datahopper_internal"})
		} else {
			util.ReportError(w, r, err, "Invalid parameters.")
			return
		}
	}
	if link != "" {
		if url, err := url.Parse(link); err == nil {
			b.Properties = append(b.Properties, []interface{}{"testResultsLink", url.String(), "datahopper_internal"})
		} else {
			util.ReportError(w, r, err, "Invalid parameters.")
			return
		}
	}
	// Fill in PropertiesStr based on Properties.
	props, err := json.Marshal(b.Properties)
	if err == nil {
		b.PropertiesStr = string(props)
	} else {
		glog.Errorf("Failed to encode properties: %s", err)
	}
	if err := repos.Update(); err != nil {
		util.ReportError(w, r, err, "Failed to update repos.")
		return
	}
	if err := ingestBuild(b, commitHash, target); err != nil {
		util.ReportError(w, r, err, "Failed to ingest build.")
		return
	}
}