aboutsummaryrefslogtreecommitdiffstats
path: root/integrations
diff options
context:
space:
mode:
authora1012112796 <1012112796@qq.com>2021-07-05 23:29:08 +0800
committerGitHub <noreply@github.com>2021-07-05 17:29:08 +0200
commit5bb97a12d79309e799e9826badf3527f03815dd2 (patch)
tree35e6a708ca49a01684ea97512055c0611552e7f4 /integrations
parent64122fe105686502d4d5606425875a6b16fa6203 (diff)
downloadgitea-5bb97a12d79309e799e9826badf3527f03815dd2.tar.gz
gitea-5bb97a12d79309e799e9826badf3527f03815dd2.zip
Creating a repo from a template repo via API (#15958)
* Creating a repo from a template repo via API fix #15934 ref: https://docs.github.com/en/rest/reference/repos#create-a-repository-using-a-template Signed-off-by: a1012112796 <1012112796@qq.com>
Diffstat (limited to 'integrations')
-rw-r--r--integrations/api_repo_test.go37
1 files changed, 37 insertions, 0 deletions
diff --git a/integrations/api_repo_test.go b/integrations/api_repo_test.go
index 7052e74b01..3948489f56 100644
--- a/integrations/api_repo_test.go
+++ b/integrations/api_repo_test.go
@@ -495,6 +495,43 @@ func TestAPIRepoTransfer(t *testing.T) {
_ = models.DeleteRepository(user, repo.OwnerID, repo.ID)
}
+func TestAPIGenerateRepo(t *testing.T) {
+ defer prepareTestEnv(t)()
+
+ user := models.AssertExistsAndLoadBean(t, &models.User{ID: 1}).(*models.User)
+ session := loginUser(t, user.Name)
+ token := getTokenForLoggedInUser(t, session)
+
+ templateRepo := models.AssertExistsAndLoadBean(t, &models.Repository{ID: 44}).(*models.Repository)
+
+ // user
+ repo := new(api.Repository)
+ req := NewRequestWithJSON(t, "POST", fmt.Sprintf("/api/v1/repos/%s/%s/generate?token=%s", templateRepo.OwnerName, templateRepo.Name, token), &api.GenerateRepoOption{
+ Owner: user.Name,
+ Name: "new-repo",
+ Description: "test generate repo",
+ Private: false,
+ GitContent: true,
+ })
+ resp := session.MakeRequest(t, req, http.StatusCreated)
+ DecodeJSON(t, resp, repo)
+
+ assert.Equal(t, "new-repo", repo.Name)
+
+ // org
+ req = NewRequestWithJSON(t, "POST", fmt.Sprintf("/api/v1/repos/%s/%s/generate?token=%s", templateRepo.OwnerName, templateRepo.Name, token), &api.GenerateRepoOption{
+ Owner: "user3",
+ Name: "new-repo",
+ Description: "test generate repo",
+ Private: false,
+ GitContent: true,
+ })
+ resp = session.MakeRequest(t, req, http.StatusCreated)
+ DecodeJSON(t, resp, repo)
+
+ assert.Equal(t, "new-repo", repo.Name)
+}
+
func TestAPIRepoGetReviewers(t *testing.T) {
defer prepareTestEnv(t)()
user := models.AssertExistsAndLoadBean(t, &models.User{ID: 2}).(*models.User)