當前位置: 首頁>>代碼示例>>Golang>>正文


Golang model.Build類代碼示例

本文整理匯總了Golang中github.com/drone/drone/model.Build的典型用法代碼示例。如果您正苦於以下問題:Golang Build類的具體用法?Golang Build怎麽用?Golang Build使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了Build類的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: CreateBuild

func (db *datastore) CreateBuild(build *model.Build, jobs ...*model.Job) error {
	var number int
	db.QueryRow(rebind(buildNumberLast), build.RepoID).Scan(&number)
	build.Number = number + 1
	build.Created = time.Now().UTC().Unix()
	build.Enqueued = build.Created
	err := meddler.Insert(db, buildTable, build)
	if err != nil {
		return err
	}
	for i, job := range jobs {
		job.BuildID = build.ID
		job.Number = i + 1
		job.Enqueued = build.Created
		err = meddler.Insert(db, jobTable, job)
		if err != nil {
			return err
		}
	}
	return nil
}
開發者ID:Ablu,項目名稱:drone,代碼行數:21,代碼來源:builds.go

示例2: UpdateBuildJob

func UpdateBuildJob(c context.Context, build *model.Build, job *model.Job) (bool, error) {
	if err := UpdateJob(c, job); err != nil {
		return false, err
	}

	// if the job is running or started we don't need to update the build
	// status since.
	if job.Status == model.StatusRunning || job.Status == model.StatusPending {
		return false, nil
	}

	jobs, err := GetJobList(c, build)
	if err != nil {
		return false, err
	}
	// check to see if all jobs are finished for this build. If yes, we need to
	// calcualte the overall build status and finish time.
	status := model.StatusSuccess
	finish := job.Finished
	for _, job := range jobs {
		if job.Finished > finish {
			finish = job.Finished
		}
		switch job.Status {
		case model.StatusSuccess:
			// no-op
		case model.StatusRunning, model.StatusPending:
			return false, nil
		default:
			status = job.Status
		}
	}

	build.Status = status
	build.Finished = finish
	if err := FromContext(c).UpdateBuild(build); err != nil {
		return false, err
	}
	return true, nil
}
開發者ID:tnaoto,項目名稱:drone,代碼行數:40,代碼來源:store.go

示例3: Test_buildstore

func Test_buildstore(t *testing.T) {
	db := openTest()
	defer db.Close()

	s := From(db)
	g := goblin.Goblin(t)
	g.Describe("Builds", func() {

		// before each test be sure to purge the package
		// table data from the database.
		g.BeforeEach(func() {
			db.Exec("DELETE FROM builds")
			db.Exec("DELETE FROM jobs")
		})

		g.It("Should Post a Build", func() {
			build := model.Build{
				RepoID: 1,
				Status: model.StatusSuccess,
				Commit: "85f8c029b902ed9400bc600bac301a0aadb144ac",
			}
			err := s.Builds().Create(&build, []*model.Job{}...)
			g.Assert(err == nil).IsTrue()
			g.Assert(build.ID != 0).IsTrue()
			g.Assert(build.Number).Equal(1)
			g.Assert(build.Commit).Equal("85f8c029b902ed9400bc600bac301a0aadb144ac")
		})

		g.It("Should Put a Build", func() {
			build := model.Build{
				RepoID: 1,
				Number: 5,
				Status: model.StatusSuccess,
				Commit: "85f8c029b902ed9400bc600bac301a0aadb144ac",
			}
			s.Builds().Create(&build, []*model.Job{}...)
			build.Status = model.StatusRunning
			err1 := s.Builds().Update(&build)
			getbuild, err2 := s.Builds().Get(build.ID)
			g.Assert(err1 == nil).IsTrue()
			g.Assert(err2 == nil).IsTrue()
			g.Assert(build.ID).Equal(getbuild.ID)
			g.Assert(build.RepoID).Equal(getbuild.RepoID)
			g.Assert(build.Status).Equal(getbuild.Status)
			g.Assert(build.Number).Equal(getbuild.Number)
		})

		g.It("Should Get a Build", func() {
			build := model.Build{
				RepoID: 1,
				Status: model.StatusSuccess,
			}
			s.Builds().Create(&build, []*model.Job{}...)
			getbuild, err := s.Builds().Get(build.ID)
			g.Assert(err == nil).IsTrue()
			g.Assert(build.ID).Equal(getbuild.ID)
			g.Assert(build.RepoID).Equal(getbuild.RepoID)
			g.Assert(build.Status).Equal(getbuild.Status)
		})

		g.It("Should Get a Build by Number", func() {
			build1 := &model.Build{
				RepoID: 1,
				Status: model.StatusPending,
			}
			build2 := &model.Build{
				RepoID: 1,
				Status: model.StatusPending,
			}
			err1 := s.Builds().Create(build1, []*model.Job{}...)
			err2 := s.Builds().Create(build2, []*model.Job{}...)
			getbuild, err3 := s.Builds().GetNumber(&model.Repo{ID: 1}, build2.Number)
			g.Assert(err1 == nil).IsTrue()
			g.Assert(err2 == nil).IsTrue()
			g.Assert(err3 == nil).IsTrue()
			g.Assert(build2.ID).Equal(getbuild.ID)
			g.Assert(build2.RepoID).Equal(getbuild.RepoID)
			g.Assert(build2.Number).Equal(getbuild.Number)
		})

		g.It("Should Get a Build by Ref", func() {
			build1 := &model.Build{
				RepoID: 1,
				Status: model.StatusPending,
				Ref:    "refs/pull/5",
			}
			build2 := &model.Build{
				RepoID: 1,
				Status: model.StatusPending,
				Ref:    "refs/pull/6",
			}
			err1 := s.Builds().Create(build1, []*model.Job{}...)
			err2 := s.Builds().Create(build2, []*model.Job{}...)
			getbuild, err3 := s.Builds().GetRef(&model.Repo{ID: 1}, "refs/pull/6")
			g.Assert(err1 == nil).IsTrue()
			g.Assert(err2 == nil).IsTrue()
			g.Assert(err3 == nil).IsTrue()
			g.Assert(build2.ID).Equal(getbuild.ID)
			g.Assert(build2.RepoID).Equal(getbuild.RepoID)
			g.Assert(build2.Number).Equal(getbuild.Number)
//.........這裏部分代碼省略.........
開發者ID:elia,項目名稱:drone,代碼行數:101,代碼來源:builds_test.go


注:本文中的github.com/drone/drone/model.Build類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。