本文整理汇总了Golang中github.com/evergreen-ci/evergreen/model/version.ById函数的典型用法代码示例。如果您正苦于以下问题:Golang ById函数的具体用法?Golang ById怎么用?Golang ById使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了ById函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: populatePatch
// populatePatch loads a patch into the project context, using patchId if provided.
// If patchId is blank, will try to infer the patch ID from the version already loaded
// into context, if available.
func (pc *projectContext) populatePatch(patchId string) error {
var err error
if len(patchId) > 0 {
// The patch is explicitly identified in the URL, so fetch it
if !patch.IsValidId(patchId) {
return fmt.Errorf("patch id '%v' is not an object id", patchId)
}
pc.Patch, err = patch.FindOne(patch.ById(patch.NewId(patchId)).Project(patch.ExcludePatchDiff))
} else if pc.Version != nil {
// patch isn't in URL but the version in context has one, get it
pc.Patch, err = patch.FindOne(patch.ByVersion(pc.Version.Id).Project(patch.ExcludePatchDiff))
}
if err != nil {
return err
}
// If there's a finalized patch loaded into context but not a version, load the version
// associated with the patch as the context's version.
if pc.Version == nil && pc.Patch != nil && pc.Patch.Version != "" {
pc.Version, err = version.FindOne(version.ById(pc.Patch.Version))
if err != nil {
return err
}
}
return nil
}
示例2: getVersionInfo
// Returns a JSON response with the marshalled output of the version
// specified in the request.
func (restapi restAPI) getVersionInfo(w http.ResponseWriter, r *http.Request) {
versionId := mux.Vars(r)["version_id"]
srcVersion, err := version.FindOne(version.ById(versionId))
if err != nil || srcVersion == nil {
msg := fmt.Sprintf("Error finding version '%v'", versionId)
statusCode := http.StatusNotFound
if err != nil {
evergreen.Logger.Logf(slogger.ERROR, "%v: %v", msg, err)
statusCode = http.StatusInternalServerError
}
restapi.WriteJSON(w, statusCode, responseError{Message: msg})
return
}
destVersion := &restVersion{}
// Copy the contents from the database into our local version type
err = angier.TransferByFieldNames(srcVersion, destVersion)
if err != nil {
msg := fmt.Sprintf("Error finding version '%v'", versionId)
evergreen.Logger.Logf(slogger.ERROR, "%v: %v", msg, err)
restapi.WriteJSON(w, http.StatusInternalServerError, responseError{Message: msg})
return
}
for _, buildStatus := range srcVersion.BuildVariants {
destVersion.BuildVariants = append(destVersion.BuildVariants, buildStatus.BuildVariant)
evergreen.Logger.Logf(slogger.ERROR, "adding BuildVariant %v", buildStatus.BuildVariant)
}
restapi.WriteJSON(w, http.StatusOK, destVersion)
return
}
示例3: TryMarkPatchBuildFinished
// TryMarkPatchBuildFinished attempts to mark a patch as finished if all
// the builds for the patch are finished as well
func TryMarkPatchBuildFinished(b *build.Build, finishTime time.Time) error {
v, err := version.FindOne(version.ById(b.Version))
if err != nil {
return err
}
if v == nil {
return fmt.Errorf("Cannot find version for build %v with version %v", b.Id, b.Version)
}
// ensure all builds for this patch are finished as well
builds, err := build.Find(build.ByIds(v.BuildIds).WithFields(build.StatusKey))
if err != nil {
return err
}
patchCompleted := true
status := evergreen.PatchSucceeded
for _, build := range builds {
if !build.IsFinished() {
patchCompleted = false
}
if build.Status != evergreen.BuildSucceeded {
status = evergreen.PatchFailed
}
}
// nothing to do if the patch isn't completed
if !patchCompleted {
return nil
}
return patch.TryMarkFinished(v.Id, finishTime, status)
}
示例4: getTasksForLatestVersion
// getTasksForLatestVersion sends back the TaskJSON data associated with the latest version.
func getTasksForLatestVersion(w http.ResponseWriter, r *http.Request) {
name := mux.Vars(r)["name"]
var jsonTask TaskJSON
projects := []string{}
err := util.ReadJSONInto(r.Body, &projects)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
versionData := []VersionData{}
for _, project := range projects {
err := db.FindOneQ(collection, db.Query(bson.M{NameKey: name,
ProjectIdKey: project}).Sort([]string{"-" + RevisionOrderNumberKey}).WithFields(VersionIdKey), &jsonTask)
if err != nil {
if err != mgo.ErrNotFound {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
http.Error(w, "{}", http.StatusNotFound)
return
}
if jsonTask.VersionId == "" {
http.Error(w, "{}", http.StatusNotFound)
}
jsonTasks, err := findTasksForVersion(jsonTask.VersionId, name)
if jsonTasks == nil {
http.Error(w, "{}", http.StatusNotFound)
return
}
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
// get the version commit info
v, err := version.FindOne(version.ById(jsonTask.VersionId))
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
if v == nil {
http.Error(w, "{}", http.StatusNotFound)
return
}
commitInfo := CommitInfo{
Author: v.Author,
Message: v.Message,
CreateTime: v.CreateTime,
Revision: v.Revision,
VersionId: jsonTask.VersionId,
}
versionData = append(versionData, VersionData{jsonTasks, commitInfo})
}
plugin.WriteJSON(w, http.StatusOK, versionData)
}
示例5: TestUpdateBuildStatusForTask
func TestUpdateBuildStatusForTask(t *testing.T) {
Convey("With two tasks and a build", t, func() {
testutil.HandleTestingErr(db.ClearCollections(task.Collection, build.Collection, version.Collection), t,
"Error clearing task and build collections")
displayName := "testName"
b := &build.Build{
Id: "buildtest",
Status: evergreen.BuildStarted,
Version: "abc",
}
v := &version.Version{
Id: b.Version,
Status: evergreen.VersionStarted,
}
testTask := task.Task{
Id: "testone",
DisplayName: displayName,
Activated: false,
BuildId: b.Id,
Project: "sample",
Status: evergreen.TaskFailed,
}
anotherTask := task.Task{
Id: "two",
DisplayName: displayName,
Activated: true,
BuildId: b.Id,
Project: "sample",
Status: evergreen.TaskFailed,
}
b.Tasks = []build.TaskCache{
{
Id: testTask.Id,
Status: evergreen.TaskSucceeded,
},
{
Id: anotherTask.Id,
Status: evergreen.TaskFailed,
},
}
So(b.Insert(), ShouldBeNil)
So(testTask.Insert(), ShouldBeNil)
So(anotherTask.Insert(), ShouldBeNil)
So(v.Insert(), ShouldBeNil)
Convey("updating the build for a task should update the build's status and the version's status", func() {
So(UpdateBuildAndVersionStatusForTask(testTask.Id), ShouldBeNil)
b, err := build.FindOne(build.ById(b.Id))
So(err, ShouldBeNil)
So(b.Status, ShouldEqual, evergreen.BuildFailed)
v, err := version.FindOne(version.ById(v.Id))
So(v.Status, ShouldEqual, evergreen.VersionFailed)
})
})
}
示例6: prependConfigToVersion
// prependConfigToVersion modifies the project config with the given id
func prependConfigToVersion(t *testing.T, versionId, configData string) {
v, err := version.FindOne(version.ById(versionId))
testutil.HandleTestingErr(err, t, "failed to load version")
if v == nil {
err = fmt.Errorf("could not find version to update")
testutil.HandleTestingErr(err, t, "failed to find version")
}
v.Config = configData + v.Config
testutil.HandleTestingErr(dbutil.ClearCollections(version.Collection), t, "couldnt reset version")
testutil.HandleTestingErr(v.Insert(), t, "failed to insert version")
}
示例7: TestMarkStart
func TestMarkStart(t *testing.T) {
Convey("With a task, build and version", t, func() {
testutil.HandleTestingErr(db.ClearCollections(task.Collection, build.Collection, version.Collection), t,
"Error clearing task and build collections")
displayName := "testName"
b := &build.Build{
Id: "buildtest",
Status: evergreen.BuildCreated,
Version: "abc",
}
v := &version.Version{
Id: b.Version,
Status: evergreen.VersionCreated,
}
testTask := task.Task{
Id: "testTask",
DisplayName: displayName,
Activated: true,
BuildId: b.Id,
Project: "sample",
Status: evergreen.TaskUndispatched,
Version: b.Version,
}
b.Tasks = []build.TaskCache{
{
Id: testTask.Id,
Status: evergreen.TaskUndispatched,
},
}
So(b.Insert(), ShouldBeNil)
So(testTask.Insert(), ShouldBeNil)
So(v.Insert(), ShouldBeNil)
Convey("when calling MarkStart, the task, version and build should be updated", func() {
So(MarkStart(testTask.Id), ShouldBeNil)
testTask, err := task.FindOne(task.ById(testTask.Id))
So(err, ShouldBeNil)
So(testTask.Status, ShouldEqual, evergreen.TaskStarted)
b, err := build.FindOne(build.ById(b.Id))
So(err, ShouldBeNil)
So(b.Status, ShouldEqual, evergreen.BuildStarted)
So(b.Tasks, ShouldNotBeNil)
So(len(b.Tasks), ShouldEqual, 1)
So(b.Tasks[0].Status, ShouldEqual, evergreen.TaskStarted)
v, err := version.FindOne(version.ById(v.Id))
So(err, ShouldBeNil)
So(v.Status, ShouldEqual, evergreen.VersionStarted)
})
})
}
示例8: GetVersion
func (as *APIServer) GetVersion(w http.ResponseWriter, r *http.Request) {
task := MustHaveTask(r)
// Get the version for this task, so we can get its config data
v, err := version.FindOne(version.ById(task.Version))
if err != nil {
as.LoggedError(w, r, http.StatusInternalServerError, err)
return
}
if v == nil {
http.Error(w, "version not found", http.StatusNotFound)
return
}
as.WriteJSON(w, http.StatusOK, v)
}
示例9: populateTaskBuildVersion
// populateTaskBuildVersion takes a task, build, and version ID and populates a projectContext
// with as many of the task, build, and version documents as possible.
// If any of the provided IDs is blank, they will be inferred from the more selective ones.
// Returns the project ID of the data found, which may be blank if the IDs are empty.
func (pc *projectContext) populateTaskBuildVersion(taskId, buildId, versionId string) (string, error) {
projectId := ""
var err error
// Fetch task if there's a task ID present; if we find one, populate build/version IDs from it
if len(taskId) > 0 {
pc.Task, err = task.FindOne(task.ById(taskId))
if err != nil {
return "", err
}
if pc.Task != nil {
// override build and version ID with the ones this task belongs to
buildId = pc.Task.BuildId
versionId = pc.Task.Version
projectId = pc.Task.Project
}
}
// Fetch build if there's a build ID present; if we find one, populate version ID from it
if len(buildId) > 0 {
pc.Build, err = build.FindOne(build.ById(buildId))
if err != nil {
return "", err
}
if pc.Build != nil {
versionId = pc.Build.Version
projectId = pc.Build.Project
}
}
if len(versionId) > 0 {
pc.Version, err = version.FindOne(version.ById(versionId))
if err != nil {
return "", err
}
if pc.Version != nil {
projectId = pc.Version.Identifier
}
}
return projectId, nil
}
示例10: constructChangeInfo
func (self *TaskNotificationHandler) constructChangeInfo(allTasks []task.Task,
key *NotificationKey) ([]ChangeInfo, error) {
changeInfoSlice := make([]ChangeInfo, 0)
for _, task := range allTasks {
// add blamelist information for each task
v, err := version.FindOne(version.ById(task.Version))
if err != nil {
return changeInfoSlice, err
}
if v == nil {
return changeInfoSlice, fmt.Errorf("No version found for task %v with version id %v",
task.Id, task.Version)
}
changeInfo := constructChangeInfo(v, key)
changeInfo.Pushtime = task.PushTime.Format(time.RFC850)
changeInfoSlice = append(changeInfoSlice, *changeInfo)
}
return changeInfoSlice, nil
}
示例11: constructChangeInfo
func (self *BuildNotificationHandler) constructChangeInfo(allBuilds []build.Build,
key *NotificationKey) ([]ChangeInfo, error) {
changeInfoSlice := make([]ChangeInfo, 0)
for _, build := range allBuilds {
// add blamelist information for each build
v, err := version.FindOne(version.ById(build.Version))
if err != nil {
return changeInfoSlice, err
}
if v == nil {
err = fmt.Errorf("No version found for build %v with version id %v",
build.Id, build.Version)
return changeInfoSlice, err
}
changeInfo := constructChangeInfo(v, key)
changeInfo.Pushtime = build.PushTime.Format(time.RFC850)
changeInfoSlice = append(changeInfoSlice, *changeInfo)
}
return changeInfoSlice, nil
}
示例12: modifyVersionInfo
// Modifies part of the version specified in the request, and returns a
// JSON response with the marshalled output of its new state.
func (restapi restAPI) modifyVersionInfo(w http.ResponseWriter, r *http.Request) {
versionId := mux.Vars(r)["version_id"]
var input struct {
Activated *bool `json:"activated"`
}
json.NewDecoder(r.Body).Decode(&input)
v, err := version.FindOne(version.ById(versionId))
if err != nil || v == nil {
msg := fmt.Sprintf("Error finding version '%v'", versionId)
statusCode := http.StatusNotFound
if err != nil {
evergreen.Logger.Logf(slogger.ERROR, "%v: %v", msg, err)
statusCode = http.StatusInternalServerError
}
restapi.WriteJSON(w, statusCode, responseError{Message: msg})
return
}
if input.Activated != nil {
if err = model.SetVersionActivation(v.Id, *input.Activated); err != nil {
state := "inactive"
if *input.Activated {
state = "active"
}
msg := fmt.Sprintf("Error marking version '%v' as %v", versionId, state)
restapi.WriteJSON(w, http.StatusInternalServerError, responseError{Message: msg})
return
}
}
restapi.getVersionInfo(w, r)
}
示例13: updateVersionBuildVarMap
// Takes in a version id and a map of "key -> buildvariant" (where "key" is of
// type "versionBuildVariant") and updates the map with an entry for the
// buildvariants associated with "versionStr"
func (self *Scheduler) updateVersionBuildVarMap(versionStr string,
versionBuildVarMap map[versionBuildVariant]model.BuildVariant) (err error) {
version, err := version.FindOne(version.ById(versionStr))
if err != nil {
return
}
if version == nil {
return fmt.Errorf("nil version returned for version id '%v'", versionStr)
}
project := &model.Project{}
err = model.LoadProjectInto([]byte(version.Config), version.Identifier, project)
if err != nil {
return fmt.Errorf("unable to load project config for version %v: "+
"%v", versionStr, err)
}
// create buildvariant map (for accessing purposes)
for _, buildVariant := range project.BuildVariants {
key := versionBuildVariant{versionStr, buildVariant.Name}
versionBuildVarMap[key] = buildVariant
}
return
}
示例14: buildHistory
func (uis *UIServer) buildHistory(w http.ResponseWriter, r *http.Request) {
buildId := mux.Vars(r)["build_id"]
before, err := getIntValue(r, "before", 3)
if err != nil {
http.Error(w, fmt.Sprintf("invalid param 'before': %v", r.FormValue("before")), http.StatusBadRequest)
return
}
after, err := getIntValue(r, "after", 3)
if err != nil {
http.Error(w, fmt.Sprintf("invalid param 'after': %v", r.FormValue("after")), http.StatusBadRequest)
return
}
builds, err := getBuildVariantHistory(buildId, before, after)
if err != nil {
http.Error(w, fmt.Sprintf("error getting build history: %v", err), http.StatusInternalServerError)
return
}
history := &struct {
Builds []*uiBuild `json:"builds"`
LastSuccess *uiBuild `json:"lastSuccess"`
}{}
history.Builds = make([]*uiBuild, len(builds))
for i := 0; i < len(builds); i++ {
v, err := version.FindOne(version.ById(builds[i].Version))
if err != nil {
http.Error(w, fmt.Sprintf("error getting version for build %v: %v", builds[i].Id, err), http.StatusInternalServerError)
return
}
if v == nil {
http.Error(w, fmt.Sprintf("no version found for build %v", builds[i].Id), http.StatusNotFound)
return
}
history.Builds[i] = &uiBuild{
Build: builds[i],
CurrentTime: time.Now().UnixNano(),
Elapsed: time.Now().Sub(builds[i].StartTime),
RepoOwner: v.Owner,
Repo: v.Repo,
Version: *v,
}
}
lastSuccess, err := getBuildVariantHistoryLastSuccess(buildId)
if err == nil && lastSuccess != nil {
v, err := version.FindOne(version.ById(lastSuccess.Version))
if err != nil {
http.Error(
w, fmt.Sprintf("error getting last successful build version: %v", err),
http.StatusInternalServerError)
return
}
if v == nil {
http.Error(w, fmt.Sprintf("no version '%v' found", lastSuccess.Version), http.StatusNotFound)
return
}
history.LastSuccess = &uiBuild{
Build: *lastSuccess,
CurrentTime: time.Now().UnixNano(),
Elapsed: time.Now().Sub(lastSuccess.StartTime),
RepoOwner: v.Owner,
Repo: v.Repo,
Version: *v,
}
}
uis.WriteJSON(w, http.StatusOK, history)
}
示例15: loadAlertContext
// loadAlertContext fetches details from the database for all documents that are associated with the
// AlertRequest. For example, it populates the task/build/version/project using the
// task/build/version/project ids in the alert request document.
func (qp *QueueProcessor) loadAlertContext(a *alert.AlertRequest) (*AlertContext, error) {
aCtx := &AlertContext{AlertRequest: a}
aCtx.Settings = qp.config
taskId, projectId, buildId, versionId := a.TaskId, a.ProjectId, a.BuildId, a.VersionId
patchId := a.PatchId
var err error
if len(a.HostId) > 0 {
aCtx.Host, err = host.FindOne(host.ById(a.HostId))
if err != nil {
return nil, err
}
}
// Fetch task if there's a task ID present; if we find one, populate build/version IDs from it
if len(taskId) > 0 {
aCtx.Task, err = model.FindTask(taskId)
if err != nil {
return nil, err
}
if aCtx.Task != nil && aCtx.Task.Execution != a.Execution {
oldTaskId := fmt.Sprintf("%s_%v", taskId, a.Execution)
aCtx.Task, err = model.FindOneOldTask(bson.M{"_id": oldTaskId}, db.NoProjection, db.NoSort)
if err != nil {
return nil, err
}
}
if aCtx.Task != nil {
// override build and version ID with the ones this task belongs to
buildId = aCtx.Task.BuildId
versionId = aCtx.Task.Version
projectId = aCtx.Task.Project
aCtx.FailedTests = []model.TestResult{}
for _, test := range aCtx.Task.TestResults {
if test.Status == "fail" {
aCtx.FailedTests = append(aCtx.FailedTests, test)
}
}
}
}
// Fetch build if there's a build ID present; if we find one, populate version ID from it
if len(buildId) > 0 {
aCtx.Build, err = build.FindOne(build.ById(buildId))
if err != nil {
return nil, err
}
if aCtx.Build != nil {
versionId = aCtx.Build.Version
projectId = aCtx.Build.Project
}
}
if len(versionId) > 0 {
aCtx.Version, err = version.FindOne(version.ById(versionId))
if err != nil {
return nil, err
}
if aCtx.Version != nil {
projectId = aCtx.Version.Identifier
}
}
if len(patchId) > 0 {
if !patch.IsValidId(patchId) {
return nil, fmt.Errorf("patch id '%v' is not an object id", patchId)
}
aCtx.Patch, err = patch.FindOne(patch.ById(patch.NewId(patchId)).Project(patch.ExcludePatchDiff))
} else if aCtx.Version != nil {
// patch isn't in URL but the version in context has one, get it
aCtx.Patch, err = patch.FindOne(patch.ByVersion(aCtx.Version.Id).Project(patch.ExcludePatchDiff))
}
// If there's a finalized patch loaded into context but not a version, load the version
// associated with the patch as the context's version.
if aCtx.Version == nil && aCtx.Patch != nil && aCtx.Patch.Version != "" {
aCtx.Version, err = version.FindOne(version.ById(aCtx.Patch.Version).WithoutFields(version.ConfigKey))
if err != nil {
return nil, err
}
}
if len(projectId) > 0 {
aCtx.ProjectRef, err = qp.findProject(projectId)
if err != nil {
return nil, err
}
}
return aCtx, nil
}