Example #1
0
func Doc(ctx *middleware.Context) {
	readme, err := ioutil.ReadFile("README.md")
	if err != nil {
		ctx.Data["Error"] = err.Error()
	}
	ctx.Data["Readme"] = template.HTML(string(blackfriday.MarkdownCommon(readme)))
	ctx.HTML(200, "doc")
}
Example #2
0
func Home(ctx *middleware.Context) {
	pv := models.RefreshPageView("/")
	repos, err := models.GetAllRepos(50, 0)
	if err != nil {
		log.Errorf("get repos from db error: %v", err)
	}
	ctx.Data["Title"] = "home"
	ctx.Data["Repos"] = repos
	ctx.Data["PV"] = pv
	ctx.HTML(200, "home")
}
Example #3
0
func Search(ctx *middleware.Context) {
	log.Info(ctx.Request.RequestURI)
	pv := models.RefreshPageView(ctx.Request.RequestURI)
	repos, err := models.GetAllRepos(50, 0)
	if err != nil {
		log.Errorf("get repos from db error: %v", err)
	}
	ctx.Data["Title"] = "home"
	ctx.Data["Repos"] = repos
	ctx.Data["PV"] = pv
	ctx.HTML(200, "search")
}
Example #4
0
func Repo(ctx *middleware.Context, params martini.Params, req *http.Request) {
	reponame := params["_1"]
	var repo *models.Repository
	var err error
	var tasks []models.Task
	var recentTask *models.Task
	if reponame != "" {
		repo, err = models.GetRepositoryByName(reponame)
		if err == models.ErrRepositoryNotExists {
			r, er := models.AddRepository(reponame)
			if er != nil {
				err = er
				ctx.Data["Error"] = err.Error()
				ctx.HTML(200, "repo")
				return
			}
			TriggerBuildRepositoryById(r.Id)
			ctx.Redirect(302, "/"+r.Uri)
			return
		}
		if err != nil {
			log.Errorf("get single repo from db error: %v", err)
		}
	} else {
		id, _ := strconv.Atoi(req.FormValue("id"))
		rid := int64(id)
		repo, err = models.GetRepositoryById(rid)
		if err != nil {
			log.Errorf("get single repo from db error: %v", err)
		}
	}
	tasks, err = models.GetTasksByRid(repo.Id)
	if err != nil {
		log.Errorf("get tasks by id, error: %v", err)
	}
	recentTask, _ = models.GetTaskById(1)
	ctx.Data["Repo"] = repo
	ctx.Data["RecentTask"] = recentTask
	ctx.Data["Tasks"] = tasks
	ctx.Data["DownCnt"] = models.RefreshPageView("/d/"+base.ToStr(repo.Id), 0)
	ctx.Data["RootUrl"] = config.Config.Server.RootUrl
	rus, err := models.GetAllLastRepoUpdate(repo.Id)
	if err != nil {
		log.Error("get last repo error: %v", err)
	}
	ctx.Data["Last"] = rus
	ctx.HTML(200, "repo")
}
Example #5
0
func History(ctx *middleware.Context, params martini.Params, req *http.Request) {
	id, _ := strconv.Atoi(req.FormValue("id"))
	tid := int64(id)
	task, err := models.GetTaskById(tid)
	if err != nil {
		log.Errorf("get task by id error: %v", err)
	}
	history, err := models.GetAllBuildHistoryByTid(tid)
	if err != nil {
		log.Errorf("get task history error: %v", err)
	}
	ctx.Data = map[string]interface{}{
		"Task":        task,
		"History":     history,
		"AutoRefresh": ctx.Query("auto_refresh") == "true",
	}
	ctx.HTML(200, "history")
}