aboutsummaryrefslogtreecommitdiffstats
path: root/integrations/api_repo_git_commits_test.go
diff options
context:
space:
mode:
authorqwerty287 <80460567+qwerty287@users.noreply.github.com>2021-12-22 07:17:33 +0100
committerGitHub <noreply@github.com>2021-12-22 06:17:33 +0000
commita9ed1c5c7c6c85ae280e6a13ca0d4e665945efb4 (patch)
tree71334ceee5297ae364184df9f5c671264b558214 /integrations/api_repo_git_commits_test.go
parentd155ffc610403819b772b3eac2a88d26d364d048 (diff)
downloadgitea-a9ed1c5c7c6c85ae280e6a13ca0d4e665945efb4.tar.gz
gitea-a9ed1c5c7c6c85ae280e6a13ca0d4e665945efb4.zip
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
Diffstat (limited to 'integrations/api_repo_git_commits_test.go')
-rw-r--r--integrations/api_repo_git_commits_test.go18
1 files changed, 18 insertions, 0 deletions
diff --git a/integrations/api_repo_git_commits_test.go b/integrations/api_repo_git_commits_test.go
index 1e138eb915..2099d568f7 100644
--- a/integrations/api_repo_git_commits_test.go
+++ b/integrations/api_repo_git_commits_test.go
@@ -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)
+}