aboutsummaryrefslogtreecommitdiffstats
path: root/integrations
diff options
context:
space:
mode:
authorqwerty287 <80460567+qwerty287@users.noreply.github.com>2021-09-20 18:14:29 +0200
committerGitHub <noreply@github.com>2021-09-20 18:14:29 +0200
commit5ac857f4d43a8452089e22c820bd1f0ddb001b7a (patch)
tree83fdf358fd8faea906fe08bc18486dfa5c12973d /integrations
parentd4bb8e0ae7aa9bdd769a935770dfe7046d519313 (diff)
downloadgitea-5ac857f4d43a8452089e22c820bd1f0ddb001b7a.tar.gz
gitea-5ac857f4d43a8452089e22c820bd1f0ddb001b7a.zip
Add API to get commit diff/patch (#17095)
* Add API to get commit diff/patch * Add Tests Co-authored-by: 6543 <6543@obermui.de>
Diffstat (limited to 'integrations')
-rw-r--r--integrations/api_repo_git_commits_test.go23
1 files changed, 23 insertions, 0 deletions
diff --git a/integrations/api_repo_git_commits_test.go b/integrations/api_repo_git_commits_test.go
index 19dab433d4..314416d264 100644
--- a/integrations/api_repo_git_commits_test.go
+++ b/integrations/api_repo_git_commits_test.go
@@ -109,3 +109,26 @@ func TestAPIReposGitCommitListDifferentBranch(t *testing.T) {
assert.Equal(t, "f27c2b2b03dcab38beaf89b0ab4ff61f6de63441", apiData[0].CommitMeta.SHA)
compareCommitFiles(t, []string{"readme.md"}, apiData[0].Files)
}
+
+func TestDownloadCommitDiffOrPatch(t *testing.T) {
+ defer prepareTestEnv(t)()
+ user := db.AssertExistsAndLoadBean(t, &models.User{ID: 2}).(*models.User)
+ // Login as User2.
+ session := loginUser(t, user.Name)
+ token := getTokenForLoggedInUser(t, session)
+
+ // Test getting diff
+ reqDiff := NewRequestf(t, "GET", "/api/v1/repos/%s/repo16/git/commits/f27c2b2b03dcab38beaf89b0ab4ff61f6de63441.diff?token="+token, user.Name)
+ resp := session.MakeRequest(t, reqDiff, http.StatusOK)
+ assert.EqualValues(t,
+ "commit f27c2b2b03dcab38beaf89b0ab4ff61f6de63441\nAuthor: User2 <user2@example.com>\nDate: Sun Aug 6 19:55:01 2017 +0200\n\n good signed commit\n\ndiff --git a/readme.md b/readme.md\nnew file mode 100644\nindex 0000000..458121c\n--- /dev/null\n+++ b/readme.md\n@@ -0,0 +1 @@\n+good sign\n",
+ resp.Body.String())
+
+ // Test getting patch
+ reqPatch := NewRequestf(t, "GET", "/api/v1/repos/%s/repo16/git/commits/f27c2b2b03dcab38beaf89b0ab4ff61f6de63441.patch?token="+token, user.Name)
+ resp = session.MakeRequest(t, reqPatch, http.StatusOK)
+ assert.EqualValues(t,
+ "From f27c2b2b03dcab38beaf89b0ab4ff61f6de63441 Mon Sep 17 00:00:00 2001\nFrom: User2 <user2@example.com>\nDate: Sun, 6 Aug 2017 19:55:01 +0200\nSubject: [PATCH] good signed commit\n\n---\n readme.md | 1 +\n 1 file changed, 1 insertion(+)\n create mode 100644 readme.md\n\ndiff --git a/readme.md b/readme.md\nnew file mode 100644\nindex 0000000..458121c\n--- /dev/null\n+++ b/readme.md\n@@ -0,0 +1 @@\n+good sign\n",
+ resp.Body.String())
+
+}