Exemplo n.º 1
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)
}
Exemplo n.º 2
0
func TriggerBuildRepositoryById(rid int64) (err error) {
	repo, err := models.GetRepositoryById(rid)
	if err != nil {
		log.Errorf("get repo by id error: %v", err)
		return
	}
	cvsinfo, _ := base.ParseCvsURI(repo.Uri)
	defaultBranch := "master"
	if cvsinfo.Provider == base.PVD_GOOGLE {
		defaultBranch = ""
	}
	models.CreateNewBuilding(rid, defaultBranch, "", "", models.AC_SRCPKG)
	if !repo.IsCmd {
		return nil
	}
	oas := map[string][]string{
		"windows": []string{"386", "amd64"},
		"linux":   []string{"386", "amd64"},
		"darwin":  []string{"amd64"},
	}
	if repo.IsCgo {
		delete(oas, "windows")
		oas["linux"] = []string{"amd64"}
	}
	for os, archs := range oas {
		for _, arch := range archs {
			err := models.CreateNewBuilding(rid, defaultBranch, os, arch, models.AC_BUILD)
			if err != nil {
				log.Errorf("create module error: %v", err)
			}
		}
	}
	return nil
}
Exemplo n.º 3
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")
}