Beispiel #1
0
func slackStatus(c *gin.Context, args []string) {
	var (
		owner  string
		name   string
		branch string
	)
	if len(args) > 0 {
		owner, name, branch = parseRepoBranch(args[0])
	}

	repo, err := store.GetRepoOwnerName(c, owner, name)
	if err != nil {
		c.String(200, "cannot find repository %s/%s", owner, name)
		return
	}
	if branch == "" {
		branch = repo.Branch
	}
	build, err := store.GetBuildLast(c, repo, branch)
	if err != nil {
		c.String(200, "cannot find status for %s/%s@%s", owner, name, branch)
		return
	}
	c.String(200, "%s@%s build number %d finished with status %s",
		repo.FullName,
		build.Branch,
		build.Number,
		build.Status,
	)
}
Beispiel #2
0
func GetBuildLast(c *gin.Context) {
	repo := session.Repo(c)
	branch := c.DefaultQuery("branch", repo.Branch)

	build, err := store.GetBuildLast(c, repo, branch)
	if err != nil {
		c.String(http.StatusInternalServerError, err.Error())
		return
	}
	jobs, _ := store.GetJobList(c, build)

	out := struct {
		*model.Build
		Jobs []*model.Job `json:"jobs"`
	}{build, jobs}

	c.IndentedJSON(http.StatusOK, &out)
}
Beispiel #3
0
func GetBadge(c *gin.Context) {
	repo, err := store.GetRepoOwnerName(c,
		c.Param("owner"),
		c.Param("name"),
	)
	if err != nil {
		c.AbortWithStatus(404)
		return
	}

	// an SVG response is always served, even when error, so
	// we can go ahead and set the content type appropriately.
	c.Writer.Header().Set("Content-Type", "image/svg+xml")

	// if no commit was found then display
	// the 'none' badge, instead of throwing
	// an error response
	branch := c.Query("branch")
	if len(branch) == 0 {
		branch = repo.Branch
	}

	build, err := store.GetBuildLast(c, repo, branch)
	if err != nil {
		log.Warning(err)
		c.String(200, badgeNone)
		return
	}

	switch build.Status {
	case model.StatusSuccess:
		c.String(200, badgeSuccess)
	case model.StatusFailure:
		c.String(200, badgeFailure)
	case model.StatusError, model.StatusKilled:
		c.String(200, badgeError)
	case model.StatusPending, model.StatusRunning:
		c.String(200, badgeStarted)
	default:
		c.String(200, badgeNone)
	}
}