woodpecker/server/remote/common/status.go
Anbraten 8e8f8967c3
Improve status updates (#561)
- link to specific proc (only general build before)
- set status for all procs (before: only for the whole build on some SCMs)
- set status after restart
- set status to pending after waiting for approval
- make status of gitlab, gitea & github equal
- dedupe status update code
- dedupe `PostBuild` code

close #410, close #297, close #459, close #521
2021-12-28 17:02:49 +01:00

60 lines
1.4 KiB
Go

package common
import (
"fmt"
"github.com/woodpecker-ci/woodpecker/server"
"github.com/woodpecker-ci/woodpecker/server/model"
)
const base = "ci/woodpecker"
func GetBuildStatusContext(repo *model.Repo, build *model.Build, proc *model.Proc) string {
name := base
switch build.Event {
case model.EventPull:
name += "/pr"
default:
if len(build.Event) > 0 {
name += "/" + string(build.Event)
}
}
if proc != nil {
name += "/" + proc.Name
}
return name
}
// getBuildStatusDescription is a helper function that generates a description
// message for the current build status.
func GetBuildStatusDescription(status model.StatusValue) string {
switch status {
case model.StatusPending:
return "Pipeline is pending"
case model.StatusRunning:
return "Pipeline is running"
case model.StatusSuccess:
return "Pipeline was successful"
case model.StatusFailure, model.StatusError:
return "Pipeline failed"
case model.StatusKilled:
return "Pipeline was canceled"
case model.StatusBlocked:
return "Pipeline is pending approval"
case model.StatusDeclined:
return "Pipeline was rejected"
default:
return "unknown status"
}
}
func GetBuildStatusLink(repo *model.Repo, build *model.Build, proc *model.Proc) string {
if proc == nil {
return fmt.Sprintf("%s/%s/build/%d", server.Config.Server.Host, repo.FullName, build.Number)
}
return fmt.Sprintf("%s/%s/build/%d/%d", server.Config.Server.Host, repo.FullName, build.Number, proc.PID)
}