Example #1
0
// message returns a formatted message to send through a notification system.
// event specifies what happened - tests completed e.x.
// kind specifies the notification system.
func message(job *database.Job, service, event, kind string) string {
	logs := database.GetCommandLogsForJob(job.ID)

	ctx := map[string]interface{}{
		"TasksFinished":  job.TasksFinished,
		"DeployFinished": job.DeployFinished,
		"Repository":     job.Repository,
		"Branch":         job.Branch,
		"Commit":         job.Commit,
		"CommitURL":      job.CommitURL,
		"Name":           job.Name,
		"Email":          job.Email,
		"CommandLogs":    logs,
		"URL":            job.URL(),
	}

	tmpl, err := getTemplate(service, event, kind)

	if err != nil {
		log.Println(err)
		return ""
	}

	var buf bytes.Buffer
	tmpl.Execute(&buf, ctx)
	return buf.String()
}
Example #2
0
// NewMessage converts a job and event type to a message that can be send
// through a websocket.
func NewMessage(job *database.Job, event string) *Message {
	return &Message{
		Name:           job.Name,
		Email:          job.Email,
		Event:          event,
		RepositoryName: job.Repository.Name,
		Branch:         job.Branch,
		Status:         job.Status(),
		URL:            job.URL(),
	}
}
Example #3
0
// Convert a job to a hipchat payload.
func payloadHipchat(job *database.Job, event, channel string) hipchatPayload {
	msg := message(job, database.NotificationServiceHipchat, event, TypeText)

	return hipchatPayload{
		Color:   "green",
		Notify:  true,
		Format:  "text",
		Room:    channel,
		From:    "LeeroyCI",
		Message: msg,
		Status:  job.Passed(),
	}
}
Example #4
0
// newStatus returns a status struct with the correct URL and messages.
func newStatus(job *database.Job) *commitStatus {
	state := statusSuccess

	if !job.Passed() {
		state = statusFailed
	}

	return &commitStatus{
		State:       statusMessages[state]["state"],
		TargetURL:   job.URL(),
		Description: statusMessages[state]["description"],
		Context:     "continuous-integration/leeeroyci",
	}
}
Example #5
0
// emailSubject returns the subject for an email.
func emailSubject(job *database.Job, event string) string {
	if event == EventBuild {
		return fmt.Sprintf("%s/%s build", job.Repository.Name, job.Branch)
	}

	if event == EventTest {
		return fmt.Sprintf("%s/%s tests", job.Repository.Name, job.Branch)
	}

	if event == EventDeployStart {
		return fmt.Sprintf("%s/%s deployment started", job.Repository.Name, job.Branch)
	}

	if event == EventDeployEnd {
		return fmt.Sprintf("%s/%s deploy %s", job.Repository.Name, job.Branch, job.Status())
	}

	return "LeeroyCI is confused - not sure which message this is."
}
Example #6
0
// deploy is a wrapper around the run commnad to make running the deploy commands
// in a separate go routine more convenient.
func deploy(job *database.Job, repository *database.Repository) {
	notification.Notify(job, notification.EventDeployStart)
	run(job, repository, database.CommandKindDeploy)
	job.DeployDone()
	notification.Notify(job, notification.EventDeployEnd)
}