summaryrefslogtreecommitdiffstats
path: root/routers/api
diff options
context:
space:
mode:
authorEthan Koenig <ethantkoenig@gmail.com>2018-02-20 04:50:42 -0800
committerBo-Yi Wu <appleboy.tw@gmail.com>2018-02-20 20:50:42 +0800
commit7b104f0cd03cf3df2b10f6f447857fe389654df1 (patch)
treecb8517fa34a6a7e18bc275f97f6541aa0783ba13 /routers/api
parent7b297808cee599f5ff58b9f6afa64d3ee980998e (diff)
downloadgitea-7b104f0cd03cf3df2b10f6f447857fe389654df1.tar.gz
gitea-7b104f0cd03cf3df2b10f6f447857fe389654df1.zip
Populate URL field of API commits (#3546)
* Populate URL field of API commits * fix orgmode_test
Diffstat (limited to 'routers/api')
-rw-r--r--routers/api/v1/convert/convert.go23
-rw-r--r--routers/api/v1/misc/markdown.go4
-rw-r--r--routers/api/v1/misc/markdown_test.go8
-rw-r--r--routers/api/v1/repo/branch.go4
4 files changed, 23 insertions, 16 deletions
diff --git a/routers/api/v1/convert/convert.go b/routers/api/v1/convert/convert.go
index e24ac0518c..19b966971a 100644
--- a/routers/api/v1/convert/convert.go
+++ b/routers/api/v1/convert/convert.go
@@ -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,
diff --git a/routers/api/v1/misc/markdown.go b/routers/api/v1/misc/markdown.go
index ed50c1c05b..fd7d1489b3 100644
--- a/routers/api/v1/misc/markdown.go
+++ b/routers/api/v1/misc/markdown.go
@@ -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 {
diff --git a/routers/api/v1/misc/markdown_test.go b/routers/api/v1/misc/markdown_test.go
index 8c3051ea8e..c1449589a3 100644
--- a/routers/api/v1/misc/markdown_test.go
+++ b/routers/api/v1/misc/markdown_test.go
@@ -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,
diff --git a/routers/api/v1/repo/branch.go b/routers/api/v1/repo/branch.go
index a82527e6a7..8e44f42368 100644
--- a/routers/api/v1/repo/branch.go
+++ b/routers/api/v1/repo/branch.go
@@ -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)