当前位置: 首页>>代码示例>>Golang>>正文


Golang Request.Commits方法代码示例

本文整理汇总了Golang中net/http.Request.Commits方法的典型用法代码示例。如果您正苦于以下问题:Golang Request.Commits方法的具体用法?Golang Request.Commits怎么用?Golang Request.Commits使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在net/http.Request的用法示例。


在下文中一共展示了Request.Commits方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: getReport

func getReport(w http.ResponseWriter, r *http.Request) {
	res := &Reports{}

	limit := 20
	if r.FormValue("count") != "" {
		limit, _ = strconv.Atoi(r.FormValue("count"))
	}

	dh := db.GetHandler()
	defer dh.Close()

	order := dh.OrderBy("start", genmai.DESC).Limit(limit + 1)

	var cond [][]interface{}

	re := regexp.MustCompile(`^/api/v1/reports/(\d+)$`)

	reportId := ""
	if m := re.FindStringSubmatch(r.URL.Path); m != nil {
		reportId = m[1]
	}

	if reportId != "" {
		cond = append(cond, []interface{}{"id", "=", reportId})
	}

	if projectId := r.FormValue("projectId"); projectId != "" {
		cond = append(cond, []interface{}{"project_id", "=", projectId})
	}

	if until := r.FormValue("until"); until != "" {
		u, _ := strconv.ParseInt(until, 10, 64)
		cond = append(cond, []interface{}{"start", "<=", time.Unix(u, 0)})
	}

	if since := r.FormValue("since"); since != "" {
		s, _ := strconv.ParseInt(since, 10, 64)
		cond = append(cond, []interface{}{"start", ">=", time.Unix(s, 0)})
	}

	if status := r.FormValue("status"); status != "" {
		cond = append(cond, []interface{}{"status", "=", status})
	}

	where := &genmai.Condition{}
	for i, c := range cond {
		if i < 1 {
			where = dh.Where(c[0], c[1], c[2])
		} else {
			where = where.And(dh.Where(c[0], c[1], c[2]))
		}
	}

	var reports []db.Report

	dh.Select(&reports, where, order)

	if len(reports) > limit {
		res.NextStart = reports[limit].Start.Unix()
		reports = reports[:len(reports)-1]
	}

	for _, report := range reports {
		r := &Report{
			Id:         report.Id,
			Status:     report.Status,
			Branch:     report.Branch,
			CompareUrl: report.CompareUrl,
			Start:      report.Start.Unix(),
			End:        report.End.Unix(),
		}

		var projects []db.Project
		dh.Select(&projects, dh.Where("id", "=", report.ProjectId))
		project := projects[0]

		r.Project = &Project{
			Id:   project.Id,
			Name: project.Name,
			Repo: project.Repo,
		}

		var commits []db.Commit
		dh.Select(&commits, dh.Where("report_id", "=", report.Id))
		for _, commit := range commits {
			r.Commits = append(r.Commits, &Commit{
				Revision: commit.Revision,
				Author:   commit.Author,
				Message:  commit.Message,
				Url:      commit.Url,
			})
		}

		var users []db.User
		dh.Select(&users, dh.Where("id", "=", report.TriggeredBy))
		user := users[0]
		r.TriggeredBy.Name = user.Name
		r.TriggeredBy.Url = user.Url
		r.TriggeredBy.AvatarUrl = user.AvatarUrl

//.........这里部分代码省略.........
开发者ID:walter-cd,项目名称:walter-server,代码行数:101,代码来源:reports.go


注:本文中的net/http.Request.Commits方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。