• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Golang database.GetSettings函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Golang中github.com/drone/drone/pkg/database.GetSettings函数的典型用法代码示例。如果您正苦于以下问题:Golang GetSettings函数的具体用法?Golang GetSettings怎么用?Golang GetSettings使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了GetSettings函数的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。

示例1: TestGetSettings

func TestGetSettings(t *testing.T) {
	Setup()
	defer Teardown()

	// even though no settings exist yet, we should
	// not see an error since we supress the msg
	settings, err := database.GetSettings()
	//if err != nil {
	//	t.Error(err)
	//}

	// add some settings
	//settings := &modelSettings{}
	settings.Scheme = "https"
	settings.Domain = "foo.com"
	settings.BitbucketKey = "bitbucketkey"
	settings.BitbucketSecret = "bitbucketsecret"
	settings.GitHubKey = "githubkey"
	settings.GitHubSecret = "githubsecret"
	settings.SmtpAddress = "[email protected]"
	settings.SmtpServer = "0.0.0.0"
	settings.SmtpUsername = "username"
	settings.SmtpPassword = "password"

	// save the updated settings
	if err := database.SaveSettings(settings); err != nil {
		t.Error(err)
	}

	// re-retrieve the settings post-save
	settings, err = database.GetSettings()
	if err != nil {
		t.Error(err)
	}

	if settings.ID != 1 {
		t.Errorf("Exepected ID %d, got %d", 1, settings.ID)
	}

	if settings.Scheme != "https" {
		t.Errorf("Exepected Scheme %s, got %s", "https", settings.Scheme)
	}

	if settings.Domain != "foo.com" {
		t.Errorf("Exepected Domain %s, got %s", "foo.com", settings.Domain)
	}

	// Verify caching works and is threadsafe
	settingsA, _ := database.GetSettings()
	settingsB, _ := database.GetSettings()
	settingsA.Domain = "foo.bar.baz"
	if settingsA.Domain == settingsB.Domain {
		t.Errorf("Exepected Domain ThreadSafe and unchanged")
	}
}
开发者ID:Jyggafey,项目名称:drone,代码行数:55,代码来源:settings_test.go


示例2: updateGitHubStatus

// updateGitHubStatus is a helper function that will send
// the build status to GitHub using the Status API.
// see https://github.com/blog/1227-commit-status-api
func updateGitHubStatus(repo *Repo, commit *Commit) error {

	// convert from drone status to github status
	var message, status string
	switch commit.Status {
	case "Success":
		status = "success"
		message = "The build succeeded on drone.io"
	case "Failure":
		status = "failure"
		message = "The build failed on drone.io"
	case "Pending":
		status = "pending"
		message = "The build is pending on drone.io"
	default:
		status = "error"
		message = "The build errored on drone.io"
	}

	// get the system settings
	settings, _ := database.GetSettings()

	// get the user from the database
	// since we need his / her GitHub token
	user, err := database.GetUser(repo.UserID)
	if err != nil {
		return err
	}

	client := github.New(user.GithubToken)
	return client.Repos.CreateStatus(repo.Owner, repo.Name, status, settings.URL().String(), message, commit.Hash)
}
开发者ID:remotesyssupport,项目名称:drone,代码行数:35,代码来源:queue.go


示例3: Send

// Send sends an email message.
func Send(msg *Message) error {
	// retieve the system settings from the database
	// so that we can get the SMTP details.
	s, err := database.GetSettings()
	if err != nil {
		log.Print(err)
		return err
	}

	// set the FROM address
	msg.Sender = s.SmtpAddress

	// format the raw email message body
	body := fmt.Sprintf(emailTemplate, msg.Sender, msg.To, msg.Subject, msg.Body)

	var auth smtp.Auth
	if len(s.SmtpUsername) > 0 {
		auth = smtp.PlainAuth("", s.SmtpUsername, s.SmtpPassword, s.SmtpServer)
	}
	addr := fmt.Sprintf("%s:%s", s.SmtpServer, s.SmtpPort)

	err = smtp.SendMail(addr, auth, msg.Sender, []string{msg.To}, []byte(body))
	if err != nil {
		log.Print(err)
		return err
	}

	return nil
}
开发者ID:vito,项目名称:drone,代码行数:30,代码来源:mail.go


示例4: Login

// Return an HTML form for the User to login.
func Login(w http.ResponseWriter, r *http.Request) error {
	var settings, _ = database.GetSettings()

	data := struct {
		Settings *Settings
	}{settings}

	return RenderTemplate(w, "login.html", &data)
}
开发者ID:Jyggafey,项目名称:drone,代码行数:10,代码来源:app.go


示例5: SignUp

// Return an HTML form for the User to signup.
func SignUp(w http.ResponseWriter, r *http.Request) error {
	var settings, _ = database.GetSettings()

	if settings == nil || !settings.OpenInvitations {
		http.Redirect(w, r, "/login", http.StatusSeeOther)
		return nil
	}

	return RenderTemplate(w, "signup.html", nil)
}
开发者ID:Jyggafey,项目名称:drone,代码行数:11,代码来源:app.go


示例6: execute

// execute will execute the build task and persist
// the results to the datastore.
func (w *worker) execute(task *BuildTask) error {
	// we need to be sure that we can recover
	// from any sort panic that could occur
	// to avoid brining down the entire application
	defer func() {
		if e := recover(); e != nil {
			task.Build.Finished = time.Now().UTC()
			task.Commit.Finished = time.Now().UTC()
			task.Build.Duration = task.Build.Finished.Unix() - task.Build.Started.Unix()
			task.Commit.Duration = task.Build.Finished.Unix() - task.Build.Started.Unix()
			task.Commit.Status = "Error"
			task.Build.Status = "Error"
			database.SaveBuild(task.Build)
			database.SaveCommit(task.Commit)
		}
	}()

	// update commit and build status
	task.Commit.Status = "Started"
	task.Build.Status = "Started"
	task.Build.Started = time.Now().UTC()
	task.Commit.Started = time.Now().UTC()

	// persist the commit to the database
	if err := database.SaveCommit(task.Commit); err != nil {
		return err
	}

	// persist the build to the database
	if err := database.SaveBuild(task.Build); err != nil {
		return err
	}

	// get settings
	settings, _ := database.GetSettings()

	// notification context
	context := &notify.Context{
		Repo:   task.Repo,
		Commit: task.Commit,
		Host:   settings.URL().String(),
	}

	// send all "started" notifications
	if task.Script.Notifications != nil {
		task.Script.Notifications.Send(context)
	}

	// Send "started" notification to Github
	if err := updateGitHubStatus(task.Repo, task.Commit); err != nil {
		log.Printf("error updating github status: %s\n", err.Error())
	}

	// make sure a channel exists for the repository,
	// the commit, and the commit output (TODO)
	reposlug := fmt.Sprintf("%s/%s/%s", task.Repo.Host, task.Repo.Owner, task.Repo.Name)
	commitslug := fmt.Sprintf("%s/%s/%s/commit/%s", task.Repo.Host, task.Repo.Owner, task.Repo.Name, task.Commit.Hash)
	consoleslug := fmt.Sprintf("%s/%s/%s/commit/%s/builds/%s", task.Repo.Host, task.Repo.Owner, task.Repo.Name, task.Commit.Hash, task.Build.Slug)
	channel.Create(reposlug)
	channel.Create(commitslug)
	channel.CreateStream(consoleslug)

	// notify the channels that the commit and build started
	channel.SendJSON(reposlug, task.Commit)
	channel.SendJSON(commitslug, task.Build)

	var buf = &bufferWrapper{channel: consoleslug}

	// append private parameters to the environment
	// variable section of the .drone.yml file, iff
	// this is not a pull request (for security purposes)
	if task.Repo.Params != nil && len(task.Commit.PullRequest) == 0 {
		for k, v := range task.Repo.Params {
			task.Script.Env = append(task.Script.Env, k+"="+v)
		}
	}

	defer func() {
		// update the status of the commit using the
		// GitHub status API.
		if err := updateGitHubStatus(task.Repo, task.Commit); err != nil {
			log.Printf("error updating github status: %s\n", err.Error())
		}
	}()

	// execute the build
	passed, buildErr := w.runBuild(task, buf)

	task.Build.Finished = time.Now().UTC()
	task.Commit.Finished = time.Now().UTC()
	task.Build.Duration = task.Build.Finished.UnixNano() - task.Build.Started.UnixNano()
	task.Commit.Duration = task.Build.Finished.UnixNano() - task.Build.Started.UnixNano()
	task.Commit.Status = "Success"
	task.Build.Status = "Success"
	task.Build.Stdout = buf.buf.String()

	// if exit code != 0 set to failure
	if passed {
//.........这里部分代码省略.........
开发者ID:rpeterson,项目名称:drone,代码行数:101,代码来源:worker.go


示例7: execute

// execute will execute the build task and persist
// the results to the datastore.
func (b *BuildTask) execute() error {
	// we need to be sure that we can recover
	// from any sort panic that could occur
	// to avoid brining down the entire application
	defer func() {
		if e := recover(); e != nil {
			b.Build.Finished = time.Now().UTC()
			b.Commit.Finished = time.Now().UTC()
			b.Build.Duration = b.Build.Finished.Unix() - b.Build.Started.Unix()
			b.Commit.Duration = b.Build.Finished.Unix() - b.Build.Started.Unix()
			b.Commit.Status = "Error"
			b.Build.Status = "Error"
			database.SaveBuild(b.Build)
			database.SaveCommit(b.Commit)
		}
	}()

	// update commit and build status
	b.Commit.Status = "Started"
	b.Build.Status = "Started"
	b.Build.Started = time.Now().UTC()
	b.Commit.Started = time.Now().UTC()

	// persist the commit to the database
	if err := database.SaveCommit(b.Commit); err != nil {
		return err
	}

	// persist the build to the database
	if err := database.SaveBuild(b.Build); err != nil {
		return err
	}

	// get settings
	settings, _ := database.GetSettings()

	// notification context
	context := &notification.Context{
		Repo:   b.Repo,
		Commit: b.Commit,
		Host:   settings.URL().String(),
	}

	// send all "started" notifications
	if b.Script.Notifications != nil {
		b.Script.Notifications.Send(context)
	}

	// make sure a channel exists for the repository,
	// the commit, and the commit output (TODO)
	reposlug := fmt.Sprintf("%s/%s/%s", b.Repo.Host, b.Repo.Owner, b.Repo.Name)
	commitslug := fmt.Sprintf("%s/%s/%s/commit/%s", b.Repo.Host, b.Repo.Owner, b.Repo.Name, b.Commit.Hash)
	consoleslug := fmt.Sprintf("%s/%s/%s/commit/%s/builds/%s", b.Repo.Host, b.Repo.Owner, b.Repo.Name, b.Commit.Hash, b.Build.Slug)
	channel.Create(reposlug)
	channel.Create(commitslug)
	channel.CreateStream(consoleslug)

	// notify the channels that the commit and build started
	channel.SendJSON(reposlug, b.Commit)
	channel.SendJSON(commitslug, b.Build)

	var buf = &bufferWrapper{channel: consoleslug}

	// append private parameters to the environment
	// variable section of the .drone.yml file
	if b.Repo.Params != nil {
		for k, v := range b.Repo.Params {
			b.Script.Env = append(b.Script.Env, k+"="+v)
		}
	}

	// execute the build
	builder := bldr.Builder{}
	builder.Build = b.Script
	builder.Repo = &r.Repo{Path: b.Repo.URL, Branch: b.Commit.Branch, Commit: b.Commit.Hash, PR: b.Commit.PullRequest, Dir: filepath.Join("/var/cache/drone/src", b.Repo.Slug)}
	builder.Key = []byte(b.Repo.PrivateKey)
	builder.Stdout = buf
	builder.Timeout = 300 * time.Minute

	defer func() {
		// update the status of the commit using the
		// GitHub status API.
		if err := updateGitHubStatus(b.Repo, b.Commit); err != nil {
			log.Printf("error updating github status: %s\n", err.Error())
		}
	}()

	buildErr := builder.Run()

	b.Build.Finished = time.Now().UTC()
	b.Commit.Finished = time.Now().UTC()
	b.Build.Duration = b.Build.Finished.UnixNano() - b.Build.Started.UnixNano()
	b.Commit.Duration = b.Build.Finished.UnixNano() - b.Build.Started.UnixNano()
	b.Commit.Status = "Success"
	b.Build.Status = "Success"
	b.Build.Stdout = buf.buf.String()

	// if exit code != 0 set to failure
//.........这里部分代码省略.........
开发者ID:remotesyssupport,项目名称:drone,代码行数:101,代码来源:queue.go



注:本文中的github.com/drone/drone/pkg/database.GetSettings函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang database.GetTeamSlug函数代码示例发布时间:2022-05-23
下一篇:
Golang database.GetRepoSlug函数代码示例发布时间:2022-05-23
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap