github.com/billybanfield/evergreen@v0.0.0-20170525200750-eeee692790f7/model/version/version.go (about)

     1  package version
     2  
     3  import (
     4  	"time"
     5  
     6  	"github.com/evergreen-ci/evergreen/db"
     7  	"github.com/evergreen-ci/evergreen/db/bsonutil"
     8  	"gopkg.in/mgo.v2/bson"
     9  )
    10  
    11  type Version struct {
    12  	Id                  string        `bson:"_id" json:"id,omitempty"`
    13  	CreateTime          time.Time     `bson:"create_time" json:"create_time,omitempty"`
    14  	StartTime           time.Time     `bson:"start_time" json:"start_time,omitempty"`
    15  	FinishTime          time.Time     `bson:"finish_time" json:"finish_time,omitempty"`
    16  	Revision            string        `bson:"gitspec" json:"revision,omitempty"`
    17  	Author              string        `bson:"author" json:"author,omitempty"`
    18  	AuthorEmail         string        `bson:"author_email" json:"author_email,omitempty"`
    19  	Message             string        `bson:"message" json:"message,omitempty"`
    20  	Status              string        `bson:"status" json:"status,omitempty"`
    21  	RevisionOrderNumber int           `bson:"order,omitempty" json:"order,omitempty"`
    22  	Config              string        `bson:"config" json:"config,omitempty"`
    23  	Ignored             bool          `bson:"ignored" json:"ignored"`
    24  	Owner               string        `bson:"owner_name" json:"owner_name,omitempty"`
    25  	Repo                string        `bson:"repo_name" json:"repo_name,omitempty"`
    26  	Branch              string        `bson:"branch_name" json:"branch_name, omitempty"`
    27  	RepoKind            string        `bson:"repo_kind" json:"repo_kind,omitempty"`
    28  	BuildVariants       []BuildStatus `bson:"build_variants_status,omitempty" json:"build_variants_status,omitempty"`
    29  
    30  	// This is technically redundant, but a lot of code relies on it, so I'm going to leave it
    31  	BuildIds []string `bson:"builds" json:"builds,omitempty"`
    32  
    33  	Identifier string `bson:"identifier" json:"identifier,omitempty"`
    34  	Remote     bool   `bson:"remote" json:"remote,omitempty"`
    35  	RemotePath string `bson:"remote_path" json:"remote_path,omitempty"`
    36  	// version requester - this is used to help tell the
    37  	// reason this version was created. e.g. it could be
    38  	// because the repotracker requested it (via tracking the
    39  	// repository) or it was triggered by a developer
    40  	// patch request
    41  	Requester string `bson:"r" json:"requester,omitempty"`
    42  	// version errors - this is used to keep track of any errors that were
    43  	// encountered in the process of creating a version. If there are no errors
    44  	// this field is omitted in the database
    45  	Errors   []string `bson:"errors,omitempty" json:"errors,omitempty"`
    46  	Warnings []string `bson:"warnings,omitempty" json:"warnings,omitempty"`
    47  }
    48  
    49  func (self *Version) UpdateBuildVariants() error {
    50  	return UpdateOne(
    51  		bson.M{IdKey: self.Id},
    52  		bson.M{
    53  			"$set": bson.M{
    54  				BuildVariantsKey: self.BuildVariants,
    55  			},
    56  		},
    57  	)
    58  }
    59  
    60  func (self *Version) Insert() error {
    61  	return db.Insert(Collection, self)
    62  }
    63  
    64  // BuildStatus stores metadata relating to each build
    65  type BuildStatus struct {
    66  	BuildVariant string    `bson:"build_variant" json:"id"`
    67  	Activated    bool      `bson:"activated" json:"activated"`
    68  	ActivateAt   time.Time `bson:"activate_at,omitempty" json:"activate_at,omitempty"`
    69  	BuildId      string    `bson:"build_id,omitempty" json:"build_id,omitempty"`
    70  }
    71  
    72  var (
    73  	BuildStatusVariantKey    = bsonutil.MustHaveTag(BuildStatus{}, "BuildVariant")
    74  	BuildStatusActivatedKey  = bsonutil.MustHaveTag(BuildStatus{}, "Activated")
    75  	BuildStatusActivateAtKey = bsonutil.MustHaveTag(BuildStatus{}, "ActivateAt")
    76  	BuildStatusBuildIdKey    = bsonutil.MustHaveTag(BuildStatus{}, "BuildId")
    77  )