Пример #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")
}
Пример #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")
}
Пример #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")
}
Пример #4
0
func Download(ctx *middleware.Context) {
	rid, _ := strconv.Atoi(ctx.Request.FormValue("rid"))
	os := ctx.Request.FormValue("os")
	arch := ctx.Request.FormValue("arch")
	task, err := models.GetOneDownloadableTask(int64(rid), os, arch)
	if err != nil {
		log.Errorf("get download task: %v", err)
		http.Error(ctx.ResponseWriter, err.Error(), http.StatusNotFound)
		return
	}
	models.RefreshPageView("/d/" + ctx.Query("rid"))
	ctx.Redirect(302, task.ZipBallUrl)
}
Пример #5
0
func PkgList(ctx *middleware.Context) {
	rs, err := models.GetAllLastRepoByOsArch(ctx.Query("os"), ctx.Query("arch"))
	if err != nil {
		ctx.JSON(400, nil)
		return
	}
	var result []*PackageItem
	var lastRid int64 = 0
	for _, lr := range rs {
		if lr.Rid == lastRid {
			if pos := len(result) - 1; pos >= 0 {
				r := result[pos]
				r.Branches = append(r.Branches,
					Branch{lr.TagBranch, lr.PushURI, fmtTime(lr.Updated), lr.Os, lr.Arch, lr.ZipBallUrl})
			}
			continue
		}
		lastRid = lr.Rid
		repo, err := models.GetRepositoryById(lr.Rid)
		if err != nil {
			log.Errorf("a missing repo in last_repo_update: %v", lr)
			continue
		}
		br := Branch{lr.TagBranch, lr.PushURI, fmtTime(lr.Updated), lr.Os, lr.Arch, lr.ZipBallUrl}
		result = append(result, &PackageItem{
			Name:        repo.Uri,   // "github.com/nsf/gocode",
			Description: repo.Brief, // "golang code complete",
			Branches:    []Branch{br},
		})

	}
	ctx.JSON(200, result)
}
Пример #6
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")
}
Пример #7
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")
}
Пример #8
0
func NotFound(ctx *middleware.Context) {
	ctx.Handle(404, "Where you got this page", nil)
}
Пример #9
0
func NewRepo(rf RepoInfoForm, ctx *middleware.Context) {
	ci, _ := base.ParseCvsURI(rf.Name)
	ctx.Redirect(302, "/"+ci.FullPath)
}
Пример #10
0
func ForceRebuild(tf TaskForm, ctx *middleware.Context) {
	if err := models.ResetTask(tf.Tid); err != nil {
		log.Errorf("reset task failed: %v", err)
	}
	ctx.Redirect(302, "/history?id="+strconv.Itoa(int(tf.Tid))+"&auto_refresh=true")
}
Пример #11
0
func NewBuild(rf RepositoryForm, ctx *middleware.Context) {
	defer ctx.Redirect(302, "/repo?id="+strconv.Itoa(int(rf.Rid)))
	TriggerBuildRepositoryById(rf.Rid)
}