Populate URL field of API commits (#3546)
* Populate URL field of API commits * fix orgmode_test
This commit is contained in:
parent
7b297808ce
commit
7b104f0cd0
11 changed files with 126 additions and 98 deletions
|
@ -13,6 +13,8 @@ import (
|
|||
|
||||
"code.gitea.io/git"
|
||||
"code.gitea.io/gitea/models"
|
||||
"code.gitea.io/gitea/modules/log"
|
||||
"code.gitea.io/gitea/modules/util"
|
||||
)
|
||||
|
||||
// ToEmail convert models.EmailAddress to api.Email
|
||||
|
@ -25,35 +27,40 @@ func ToEmail(email *models.EmailAddress) *api.Email {
|
|||
}
|
||||
|
||||
// ToBranch convert a commit and branch to an api.Branch
|
||||
func ToBranch(b *models.Branch, c *git.Commit) *api.Branch {
|
||||
func ToBranch(repo *models.Repository, b *models.Branch, c *git.Commit) *api.Branch {
|
||||
return &api.Branch{
|
||||
Name: b.Name,
|
||||
Commit: ToCommit(c),
|
||||
Commit: ToCommit(repo, c),
|
||||
}
|
||||
}
|
||||
|
||||
// ToCommit convert a commit to api.PayloadCommit
|
||||
func ToCommit(c *git.Commit) *api.PayloadCommit {
|
||||
func ToCommit(repo *models.Repository, c *git.Commit) *api.PayloadCommit {
|
||||
authorUsername := ""
|
||||
author, err := models.GetUserByEmail(c.Author.Email)
|
||||
if err == nil {
|
||||
if author, err := models.GetUserByEmail(c.Author.Email); err == nil {
|
||||
authorUsername = author.Name
|
||||
} else if !models.IsErrUserNotExist(err) {
|
||||
log.Error(4, "GetUserByEmail: %v", err)
|
||||
}
|
||||
|
||||
committerUsername := ""
|
||||
committer, err := models.GetUserByEmail(c.Committer.Email)
|
||||
if err == nil {
|
||||
if committer, err := models.GetUserByEmail(c.Committer.Email); err == nil {
|
||||
committerUsername = committer.Name
|
||||
} else if !models.IsErrUserNotExist(err) {
|
||||
log.Error(4, "GetUserByEmail: %v", err)
|
||||
}
|
||||
|
||||
verif := models.ParseCommitWithSignature(c)
|
||||
var signature, payload string
|
||||
if c.Signature != nil {
|
||||
signature = c.Signature.Signature
|
||||
payload = c.Signature.Payload
|
||||
}
|
||||
|
||||
return &api.PayloadCommit{
|
||||
ID: c.ID.String(),
|
||||
Message: c.Message(),
|
||||
URL: "Not implemented",
|
||||
URL: util.URLJoin(repo.Link(), "commit", c.ID.String()),
|
||||
Author: &api.PayloadUser{
|
||||
Name: c.Author.Name,
|
||||
Email: c.Author.Email,
|
||||
|
|
|
@ -8,9 +8,9 @@ import (
|
|||
api "code.gitea.io/sdk/gitea"
|
||||
|
||||
"code.gitea.io/gitea/modules/context"
|
||||
"code.gitea.io/gitea/modules/markup"
|
||||
"code.gitea.io/gitea/modules/markup/markdown"
|
||||
"code.gitea.io/gitea/modules/setting"
|
||||
"code.gitea.io/gitea/modules/util"
|
||||
)
|
||||
|
||||
// Markdown render markdown document to HTML
|
||||
|
@ -45,7 +45,7 @@ func Markdown(ctx *context.APIContext, form api.MarkdownOption) {
|
|||
switch form.Mode {
|
||||
case "gfm":
|
||||
md := []byte(form.Text)
|
||||
context := markup.URLJoin(setting.AppURL, form.Context)
|
||||
context := util.URLJoin(setting.AppURL, form.Context)
|
||||
if form.Wiki {
|
||||
ctx.Write([]byte(markdown.RenderWiki(md, context, nil)))
|
||||
} else {
|
||||
|
|
|
@ -9,8 +9,8 @@ import (
|
|||
"testing"
|
||||
|
||||
"code.gitea.io/gitea/modules/context"
|
||||
"code.gitea.io/gitea/modules/markup"
|
||||
"code.gitea.io/gitea/modules/setting"
|
||||
"code.gitea.io/gitea/modules/util"
|
||||
api "code.gitea.io/sdk/gitea"
|
||||
|
||||
"github.com/go-macaron/inject"
|
||||
|
@ -53,7 +53,7 @@ func TestAPI_RenderGFM(t *testing.T) {
|
|||
Context: Repo,
|
||||
Wiki: true,
|
||||
}
|
||||
requrl, _ := url.Parse(markup.URLJoin(AppURL, "api", "v1", "markdown"))
|
||||
requrl, _ := url.Parse(util.URLJoin(AppURL, "api", "v1", "markdown"))
|
||||
req := &http.Request{
|
||||
Method: "POST",
|
||||
URL: requrl,
|
||||
|
@ -147,7 +147,7 @@ func TestAPI_RenderSimple(t *testing.T) {
|
|||
Text: "",
|
||||
Context: Repo,
|
||||
}
|
||||
requrl, _ := url.Parse(markup.URLJoin(AppURL, "api", "v1", "markdown"))
|
||||
requrl, _ := url.Parse(util.URLJoin(AppURL, "api", "v1", "markdown"))
|
||||
req := &http.Request{
|
||||
Method: "POST",
|
||||
URL: requrl,
|
||||
|
@ -166,7 +166,7 @@ func TestAPI_RenderSimple(t *testing.T) {
|
|||
func TestAPI_RenderRaw(t *testing.T) {
|
||||
setting.AppURL = AppURL
|
||||
|
||||
requrl, _ := url.Parse(markup.URLJoin(AppURL, "api", "v1", "markdown"))
|
||||
requrl, _ := url.Parse(util.URLJoin(AppURL, "api", "v1", "markdown"))
|
||||
req := &http.Request{
|
||||
Method: "POST",
|
||||
URL: requrl,
|
||||
|
|
|
@ -61,7 +61,7 @@ func GetBranch(ctx *context.APIContext) {
|
|||
return
|
||||
}
|
||||
|
||||
ctx.JSON(200, convert.ToBranch(branch, c))
|
||||
ctx.JSON(200, convert.ToBranch(ctx.Repo.Repository, branch, c))
|
||||
}
|
||||
|
||||
// ListBranches list all the branches of a repository
|
||||
|
@ -98,7 +98,7 @@ func ListBranches(ctx *context.APIContext) {
|
|||
ctx.Error(500, "GetCommit", err)
|
||||
return
|
||||
}
|
||||
apiBranches[i] = convert.ToBranch(branches[i], c)
|
||||
apiBranches[i] = convert.ToBranch(ctx.Repo.Repository, branches[i], c)
|
||||
}
|
||||
|
||||
ctx.JSON(200, &apiBranches)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue