Ejemplo n.º 1
0
func install(ctx *gin.Context) {
	owner, name := ctx.Param("owner"), ctx.Param("name")
	u := ghauth.User(ctx)

	hookName := "web"
	hook := &github.Hook{}
	hook.Name = &hookName
	hookPath := randString(20)
	hookSecret := randString(20)
	hook.Config = map[string]interface{}{
		"url":          fmt.Sprintf("%s/hooks/%s", appConfig.UrlBase, hookPath),
		"content_type": "json",
		"secret":       hookSecret,
	}
	hook.Events = []string{"issue_comment", "issues", "pull_request_review_comment", "pull_request", "push", "status"}
	hook, _, err := u.Client().Repositories.CreateHook(owner, name, hook)
	if err != nil {
		ctx.Error(err)
		return
	}
	if err = registerHook(owner, name, hookPath, hookSecret, *hook.ID, u.Token); err != nil {
		ctx.Error(err)
		return
	}
	ctx.Redirect(302, fmt.Sprintf("/repo/%s/%s", owner, name))
}
Ejemplo n.º 2
0
func renderError(c *gin.Context) {
	c.Next()
	errs := c.Errors.Errors()
	if len(errs) > 0 {
		u := ghauth.User(c)
		render(c, "error", gin.H{"User": u, "Errors": errs})
	}
}
Ejemplo n.º 3
0
func repo(ctx *gin.Context) {
	owner, name := ctx.Param("owner"), ctx.Param("name")
	ri, err := getRepoInfo(owner, name)
	if err != nil {
		ctx.Error(err)
		return
	}
	u := ghauth.User(ctx)
	data := gin.H{"User": u, "Owner": owner, "Name": name, "Info": ri}
	render(ctx, "repo", data)
}
Ejemplo n.º 4
0
func repo(ctx *gin.Context) {
	u := ghauth.User(ctx)
	owner, repo := ctx.Param("owner"), ctx.Param("repo")
	data := gin.H{"User": u, "Owner": owner, "Repo": repo}
	opts := &github.PullRequestListOptions{}
	opts.PerPage = 20
	opts.Page = getIntQuery(ctx, "page", 0)
	pulls, res, err := u.Client().PullRequests.List(owner, repo, opts)
	if err != nil {
		ctx.Error(err)
		return
	}
	data["Pulls"] = pulls
	data["Result"] = res
	render(ctx, "repo", data)
}
Ejemplo n.º 5
0
func repo(ctx *gin.Context) {
	user := ghauth.User(ctx)
	owner, repo := ctx.Param("owner"), ctx.Param("repo")
	opts := &github.PullRequestListOptions{}

	pulls, _, err := user.Client().PullRequests.List(owner, repo, opts)
	if err != nil {
		ctx.Error(err)
		return
	}
	ctx.HTML(200, "repo.tpl", gin.H{
		"User":     user,
		"Pulls":    pulls,
		"FullName": owner + "/" + repo,
	})
}
Ejemplo n.º 6
0
func pull(ctx *gin.Context) {
	owner, repo, num := ctx.Param("owner"), ctx.Param("repo"), ctx.Param("pr")
	number, _ := strconv.Atoi(num)
	u := ghauth.User(ctx)
	data := gin.H{"User": u, "Owner": owner, "Repo": repo, "Number": number}

	pr, res, err := u.Client().PullRequests.Get(owner, repo, number)
	if err != nil {
		ctx.Error(err)
		return
	}
	data["Pull"] = pr
	data["Result"] = res
	data["Merged"] = *pr.Merged
	data["Conflicts"] = !*pr.Mergeable
	render(ctx, "pr", data)
}
Ejemplo n.º 7
0
func home(ctx *gin.Context) {
	u := ghauth.User(ctx)
	data := gin.H{"User": u}
	if u != nil {
		opts := &github.RepositoryListOptions{}
		opts.PerPage = 20
		opts.Page = getIntQuery(ctx, "page", 0)
		opts.Sort = "pushed"
		repos, res, err := u.Client().Repositories.List("", opts)
		if err != nil {
			ctx.Error(err)
			return
		}
		data["Result"] = res
		data["Repos"] = repos
	}
	render(ctx, "home", data)
}
Ejemplo n.º 8
0
func home(ctx *gin.Context) {
	user := ghauth.User(ctx)
	var repos = []github.Repository{}
	if user != nil {
		var err error
		opts := &github.RepositoryListOptions{}
		opts.PerPage = 100
		opts.Sort = "pushed"
		opts.Direction = "desc"
		repos, _, err = user.Client().Repositories.List("", opts) //may need to loop through pagination, but whatever.
		if err != nil {
			ctx.Error(err)
			return
		}
	}
	ctx.HTML(200, "main.tpl", gin.H{
		"User":  user,
		"Repos": repos,
	})
}