-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add github compatible tarball download API endpoints
- Loading branch information
Showing
6 changed files
with
135 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
// Copyright 2024 The Gitea Authors. All rights reserved. | ||
// SPDX-License-Identifier: MIT | ||
|
||
package repo | ||
|
||
import ( | ||
"fmt" | ||
"net/http" | ||
|
||
"code.gitea.io/gitea/modules/git" | ||
"code.gitea.io/gitea/modules/gitrepo" | ||
"code.gitea.io/gitea/services/context" | ||
archiver_service "code.gitea.io/gitea/services/repository/archiver" | ||
) | ||
|
||
func DownloadArchive(ctx *context.APIContext) { | ||
var tp git.ArchiveType | ||
switch ballType := ctx.PathParam("ball_type"); ballType { | ||
case "tarball": | ||
tp = git.TARGZ | ||
case "zipball": | ||
tp = git.ZIP | ||
case "bundle": | ||
tp = git.BUNDLE | ||
default: | ||
ctx.Error(http.StatusBadRequest, "", fmt.Sprintf("Unknown archive type: %s", ballType)) | ||
return | ||
} | ||
|
||
if ctx.Repo.GitRepo == nil { | ||
gitRepo, err := gitrepo.OpenRepository(ctx, ctx.Repo.Repository) | ||
if err != nil { | ||
ctx.Error(http.StatusInternalServerError, "OpenRepository", err) | ||
return | ||
} | ||
ctx.Repo.GitRepo = gitRepo | ||
defer gitRepo.Close() | ||
} | ||
|
||
r, err := archiver_service.NewRequest(ctx.Repo.Repository.ID, ctx.Repo.GitRepo, ctx.PathParam("*"), tp) | ||
if err != nil { | ||
ctx.ServerError("NewRequest", err) | ||
return | ||
} | ||
|
||
archive, err := r.Await(ctx) | ||
if err != nil { | ||
ctx.ServerError("archive.Await", err) | ||
return | ||
} | ||
|
||
download(ctx, r.GetArchiveName(), archive) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters