aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--gogs.go2
-rw-r--r--pkg/context/api.go2
-rw-r--r--routes/api/v1/api.go1
-rw-r--r--routes/api/v1/repo/commits.go47
-rw-r--r--templates/.VERSION2
5 files changed, 51 insertions, 3 deletions
diff --git a/gogs.go b/gogs.go
index a46898ec..67d741ef 100644
--- a/gogs.go
+++ b/gogs.go
@@ -16,7 +16,7 @@ import (
"github.com/gogs/gogs/pkg/setting"
)
-const APP_VER = "0.11.79.1211"
+const APP_VER = "0.11.80.1216"
func init() {
setting.AppVer = APP_VER
diff --git a/pkg/context/api.go b/pkg/context/api.go
index 7dc4472b..a8928fc0 100644
--- a/pkg/context/api.go
+++ b/pkg/context/api.go
@@ -26,7 +26,7 @@ type APIContext struct {
}
// FIXME: move to github.com/gogs/go-gogs-client
-const DOC_URL = "https://github.com/gogs/go-gogs-client/wiki"
+const DOC_URL = "https://github.com/gogs/docs-api"
// Error responses error message to client with given message.
// If status is 500, also it prints error to log.
diff --git a/routes/api/v1/api.go b/routes/api/v1/api.go
index ccecc6a7..d73f57f3 100644
--- a/routes/api/v1/api.go
+++ b/routes/api/v1/api.go
@@ -252,6 +252,7 @@ func RegisterRoutes(m *macaron.Macaron) {
m.Group("/commits", func() {
m.Get("/:sha", repo.GetSingleCommit)
+ m.Get("/*", repo.GetReferenceSHA)
})
m.Group("/keys", func() {
diff --git a/routes/api/v1/repo/commits.go b/routes/api/v1/repo/commits.go
index a856d37f..302ece1c 100644
--- a/routes/api/v1/repo/commits.go
+++ b/routes/api/v1/repo/commits.go
@@ -5,6 +5,8 @@
package repo
import (
+ "net/http"
+ "strings"
"time"
"github.com/gogs/git-module"
@@ -17,6 +19,12 @@ import (
)
func GetSingleCommit(c *context.APIContext) {
+ if strings.Contains(c.Req.Header.Get("Accept"), api.MediaApplicationSHA) {
+ c.SetParams("*", c.Params(":sha"))
+ GetReferenceSHA(c)
+ return
+ }
+
gitRepo, err := git.OpenRepository(c.Repo.Repository.RepoPath())
if err != nil {
c.ServerError("OpenRepository", err)
@@ -89,3 +97,42 @@ func GetSingleCommit(c *context.APIContext) {
Parents: apiParents,
})
}
+
+func GetReferenceSHA(c *context.APIContext) {
+ gitRepo, err := git.OpenRepository(c.Repo.Repository.RepoPath())
+ if err != nil {
+ c.ServerError("OpenRepository", err)
+ return
+ }
+
+ ref := c.Params("*")
+ refType := 0 // 0-undetermined, 1-branch, 2-tag
+ if strings.HasPrefix(ref, git.BRANCH_PREFIX) {
+ ref = strings.TrimPrefix(ref, git.BRANCH_PREFIX)
+ refType = 1
+ } else if strings.HasPrefix(ref, git.TAG_PREFIX) {
+ ref = strings.TrimPrefix(ref, git.TAG_PREFIX)
+ refType = 2
+ } else {
+ if gitRepo.IsBranchExist(ref) {
+ refType = 1
+ } else if gitRepo.IsTagExist(ref) {
+ refType = 2
+ } else {
+ c.NotFound()
+ return
+ }
+ }
+
+ var sha string
+ if refType == 1 {
+ sha, err = gitRepo.GetBranchCommitID(ref)
+ } else if refType == 2 {
+ sha, err = gitRepo.GetTagCommitID(ref)
+ }
+ if err != nil {
+ c.NotFoundOrServerError("get reference commit ID", git.IsErrNotExist, err)
+ return
+ }
+ c.PlainText(http.StatusOK, []byte(sha))
+}
diff --git a/templates/.VERSION b/templates/.VERSION
index f580b0ff..d1700091 100644
--- a/templates/.VERSION
+++ b/templates/.VERSION
@@ -1 +1 @@
-0.11.79.1211
+0.11.80.1216