mirror of
https://github.com/semaphoreui/semaphore.git
synced 2025-01-20 07:19:20 +01:00
feat: pass commit info from runner
This commit is contained in:
parent
48f43aec37
commit
58cbad7f0f
@ -3,12 +3,12 @@ package runners
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/gorilla/context"
|
||||
"github.com/semaphoreui/semaphore/api/helpers"
|
||||
"github.com/semaphoreui/semaphore/db"
|
||||
"github.com/semaphoreui/semaphore/pkg/task_logger"
|
||||
"github.com/semaphoreui/semaphore/services/runners"
|
||||
"github.com/semaphoreui/semaphore/util"
|
||||
"github.com/gorilla/context"
|
||||
)
|
||||
|
||||
func RunnerMiddleware(next http.Handler) http.Handler {
|
||||
@ -160,6 +160,10 @@ func UpdateRunner(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
tsk.SetStatus(job.Status)
|
||||
|
||||
if job.Commit != nil {
|
||||
tsk.SetCommit(job.Commit.Hash, job.Commit.Message)
|
||||
}
|
||||
}
|
||||
|
||||
w.WriteHeader(http.StatusNoContent)
|
||||
|
@ -57,4 +57,6 @@ type Logger interface {
|
||||
SetStatus(status TaskStatus)
|
||||
AddStatusListener(l StatusListener)
|
||||
AddLogListener(l LogListener)
|
||||
|
||||
SetCommit(hash, message string)
|
||||
}
|
||||
|
@ -250,6 +250,7 @@ func (p *JobPool) sendProgress() {
|
||||
ID: id,
|
||||
LogRecords: j.logRecords,
|
||||
Status: j.status,
|
||||
Commit: j.commit,
|
||||
})
|
||||
|
||||
j.logRecords = make([]LogRecord, 0)
|
||||
@ -387,7 +388,7 @@ func (p *JobPool) checkNewJobs() {
|
||||
resp, err := client.Do(req)
|
||||
|
||||
if err != nil {
|
||||
logger.ActionError(err, "send request", "upexpected error")
|
||||
logger.ActionError(err, "send request", "unexpected error")
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -16,6 +16,7 @@ type runningJob struct {
|
||||
status task_logger.TaskStatus
|
||||
logRecords []LogRecord
|
||||
job *tasks.LocalJob
|
||||
commit *CommitInfo
|
||||
|
||||
statusListeners []task_logger.StatusListener
|
||||
logListeners []task_logger.LogListener
|
||||
@ -62,6 +63,13 @@ func (p *runningJob) LogCmd(cmd *exec.Cmd) {
|
||||
go p.logPipe(bufio.NewReader(stdout))
|
||||
}
|
||||
|
||||
func (p *runningJob) SetCommit(hash, message string) {
|
||||
p.commit = &CommitInfo{
|
||||
Hash: hash,
|
||||
Message: message,
|
||||
}
|
||||
}
|
||||
|
||||
func (p *runningJob) SetStatus(status task_logger.TaskStatus) {
|
||||
if p.status == status {
|
||||
return
|
||||
|
@ -35,6 +35,11 @@ type LogRecord struct {
|
||||
Message string `json:"message" binding:"required"`
|
||||
}
|
||||
|
||||
type CommitInfo struct {
|
||||
Hash string `json:"hash" binding:"required"`
|
||||
Message string `json:"message" binding:"required"`
|
||||
}
|
||||
|
||||
type RunnerProgress struct {
|
||||
Jobs []JobProgress
|
||||
}
|
||||
@ -43,6 +48,7 @@ type JobProgress struct {
|
||||
ID int
|
||||
Status task_logger.TaskStatus
|
||||
LogRecords []LogRecord
|
||||
Commit *CommitInfo
|
||||
}
|
||||
|
||||
type RunnerRegistration struct {
|
||||
|
@ -53,6 +53,10 @@ func (t *LocalJob) SetStatus(status task_logger.TaskStatus) {
|
||||
t.Logger.SetStatus(status)
|
||||
}
|
||||
|
||||
func (t *LocalJob) SetCommit(hash, message string) {
|
||||
t.Logger.SetCommit(hash, message)
|
||||
}
|
||||
|
||||
func (t *LocalJob) getEnvironmentExtraVars(username string, incomingVersion *string) (extraVars map[string]interface{}, err error) {
|
||||
|
||||
extraVars = make(map[string]interface{})
|
||||
@ -611,8 +615,7 @@ func (t *LocalJob) checkoutRepository() error {
|
||||
|
||||
commitMessage, _ := repo.GetLastCommitMessage()
|
||||
|
||||
t.Log("Commit hash: " + commitHash)
|
||||
t.Log("Commit message: " + commitMessage)
|
||||
t.SetCommit(commitHash, commitMessage)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
@ -58,6 +58,16 @@ func (t *TaskRunner) LogCmd(cmd *exec.Cmd) {
|
||||
go t.logPipe(bufio.NewReader(stdout))
|
||||
}
|
||||
|
||||
func (t *TaskRunner) SetCommit(hash, message string) {
|
||||
|
||||
t.Task.CommitHash = &hash
|
||||
t.Task.CommitMessage = message
|
||||
|
||||
if err := t.pool.store.UpdateTask(t.Task); err != nil {
|
||||
t.panicOnError(err, "Failed to update task commit")
|
||||
}
|
||||
}
|
||||
|
||||
func (t *TaskRunner) SetStatus(status task_logger.TaskStatus) {
|
||||
if status == t.Task.Status {
|
||||
return
|
||||
|
Loading…
Reference in New Issue
Block a user