Add API to get file commit history (#17652)
Adds an API endpoint `api/v1/repos/{owner}/{repo}/git/history/{filepath}` to get the commits affecting the given file or directory. Closes https://github.com/go-gitea/gitea/issues/16206 and closes https://github.com/go-gitea/gitea/issues/16703
This commit is contained in:
parent
d155ffc610
commit
a9ed1c5c7c
3 changed files with 81 additions and 26 deletions
|
@ -132,3 +132,21 @@ func TestDownloadCommitDiffOrPatch(t *testing.T) {
|
|||
resp.Body.String())
|
||||
|
||||
}
|
||||
|
||||
func TestGetFileHistory(t *testing.T) {
|
||||
defer prepareTestEnv(t)()
|
||||
user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2}).(*user_model.User)
|
||||
// Login as User2.
|
||||
session := loginUser(t, user.Name)
|
||||
token := getTokenForLoggedInUser(t, session)
|
||||
|
||||
req := NewRequestf(t, "GET", "/api/v1/repos/%s/repo16/commits?path=readme.md&token="+token+"&sha=good-sign", user.Name)
|
||||
resp := session.MakeRequest(t, req, http.StatusOK)
|
||||
|
||||
var apiData []api.Commit
|
||||
DecodeJSON(t, resp, &apiData)
|
||||
|
||||
assert.Len(t, apiData, 1)
|
||||
assert.Equal(t, "f27c2b2b03dcab38beaf89b0ab4ff61f6de63441", apiData[0].CommitMeta.SHA)
|
||||
compareCommitFiles(t, []string{"readme.md"}, apiData[0].Files)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue