github.com/billybanfield/evergreen@v0.0.0-20170525200750-eeee692790f7/plugin/builtin/taskdata/commit.go (about) 1 package taskdata 2 3 import ( 4 "net/http" 5 "regexp" 6 7 "github.com/evergreen-ci/evergreen/db" 8 "github.com/evergreen-ci/evergreen/plugin" 9 "github.com/gorilla/mux" 10 "gopkg.in/mgo.v2" 11 "gopkg.in/mgo.v2/bson" 12 ) 13 14 func uiGetCommit(w http.ResponseWriter, r *http.Request) { 15 projectId := mux.Vars(r)["project_id"] 16 revision := mux.Vars(r)["revision"] 17 variant := mux.Vars(r)["variant"] 18 taskName := mux.Vars(r)["task_name"] 19 name := mux.Vars(r)["name"] 20 jsonForTask, err := GetCommit(projectId, revision, variant, taskName, name) 21 if err != nil { 22 if err != mgo.ErrNotFound { 23 http.Error(w, err.Error(), http.StatusInternalServerError) 24 return 25 } 26 http.Error(w, "{}", http.StatusNotFound) 27 return 28 } 29 if len(r.FormValue("full")) != 0 { // if specified, include the json data's container as well 30 plugin.WriteJSON(w, http.StatusOK, jsonForTask) 31 return 32 } 33 plugin.WriteJSON(w, http.StatusOK, jsonForTask) 34 } 35 36 // GetCommit gets the task data associated with a particular task by using 37 // the commit hash to find the data. 38 func GetCommit(projectId, revision, variant, taskName, name string) (TaskJSON, error) { 39 var jsonForTask TaskJSON 40 err := db.FindOneQ(collection, 41 db.Query(bson.M{ProjectIdKey: projectId, 42 RevisionKey: bson.RegEx{"^" + regexp.QuoteMeta(revision), "i"}, // make it case insensitive 43 VariantKey: variant, 44 TaskNameKey: taskName, 45 NameKey: name, 46 IsPatchKey: false, 47 }), &jsonForTask) 48 if err != nil { 49 return TaskJSON{}, err 50 } 51 return jsonForTask, nil 52 }