本文整理匯總了Golang中github.com/drone/drone/pkg/channel.Create函數的典型用法代碼示例。如果您正苦於以下問題:Golang Create函數的具體用法?Golang Create怎麽用?Golang Create使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了Create函數的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: RepoDashboard
// Display a Repository dashboard.
func RepoDashboard(w http.ResponseWriter, r *http.Request, u *User, repo *Repo) error {
branch := r.FormValue(":branch")
// get a list of all branches
branches, err := database.ListBranches(repo.ID)
if err != nil {
return err
}
// if no branch is provided then we'll
// want to use a default value.
if len(branch) == 0 {
branch = repo.DefaultBranch()
}
// get a list of recent commits for the
// repository and specific branch
commits, err := database.ListCommits(repo.ID, branch)
if err != nil {
return err
}
// get a token that can be exchanged with the
// websocket handler to authorize listening
// for a stream of changes for this repository
token := channel.Create(repo.Slug)
data := struct {
User *User
Repo *Repo
Branches []*Commit
Commits []*Commit
Branch string
Token string
}{u, repo, branches, commits, branch, token}
return RenderTemplate(w, "repo_dashboard.html", &data)
}
示例2: 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 := ¬ify.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 {
//.........這裏部分代碼省略.........
示例3: 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 := ¬ification.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
//.........這裏部分代碼省略.........
示例4: setupWall
// setup the websocket channel for the wall display
func setupWall() {
channel.Create(channel.WallDisplay)
}