Skip to content

Commit 08bf443

Browse files
lafrikstechknowlogick
authored andcommitted
Implement git refs API for listing references (branches, tags and other) (#5354)
* Inital routes to git refs api * Git refs API implementation * Update swagger * Fix copyright * Make swagger happy add basic test * Fix test * Fix test again :)
1 parent 2949043 commit 08bf443

File tree

268 files changed

+48603
-10
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

268 files changed

+48603
-10
lines changed

Gopkg.lock

+153-5
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

integrations/api_repo_git_ref_test.go

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// Copyright 2018 The Gitea Authors. All rights reserved.
2+
// Use of this source code is governed by a MIT-style
3+
// license that can be found in the LICENSE file.
4+
5+
package integrations
6+
7+
import (
8+
"net/http"
9+
"testing"
10+
11+
"code.gitea.io/gitea/models"
12+
)
13+
14+
func TestAPIReposGitRefs(t *testing.T) {
15+
prepareTestEnv(t)
16+
user := models.AssertExistsAndLoadBean(t, &models.User{ID: 2}).(*models.User)
17+
// Login as User2.
18+
session := loginUser(t, user.Name)
19+
token := getTokenForLoggedInUser(t, session)
20+
21+
for _, ref := range [...]string{
22+
"refs/heads/master", // Branch
23+
"refs/tags/v1.1", // Tag
24+
} {
25+
req := NewRequestf(t, "GET", "/api/v1/repos/%s/repo1/git/%s?token="+token, user.Name, ref)
26+
session.MakeRequest(t, req, http.StatusOK)
27+
}
28+
// Test getting all refs
29+
req := NewRequestf(t, "GET", "/api/v1/repos/%s/repo1/git/refs?token="+token, user.Name)
30+
session.MakeRequest(t, req, http.StatusOK)
31+
// Test getting non-existent refs
32+
req = NewRequestf(t, "GET", "/api/v1/repos/%s/repo1/git/refs/heads/unknown?token="+token, user.Name)
33+
session.MakeRequest(t, req, http.StatusNotFound)
34+
}

routers/api/v1/api.go

+4
Original file line numberDiff line numberDiff line change
@@ -573,6 +573,10 @@ func RegisterRoutes(m *macaron.Macaron) {
573573
m.Get("/status", repo.GetCombinedCommitStatusByRef)
574574
m.Get("/statuses", repo.GetCommitStatusesByRef)
575575
})
576+
m.Group("/git", func() {
577+
m.Get("/refs", repo.GetGitAllRefs)
578+
m.Get("/refs/*", repo.GetGitRefs)
579+
})
576580
}, repoAssignment())
577581
})
578582

0 commit comments

Comments
 (0)