Add bundle download for repository (#14538)
* Add bundle download Signed-off-by: jolheiser <john.olheiser@gmail.com> * Fix fmt Signed-off-by: jolheiser <john.olheiser@gmail.com> * Fix build tags Signed-off-by: jolheiser <john.olheiser@gmail.com> * Download specific commit Signed-off-by: jolheiser <john.olheiser@gmail.com>
This commit is contained in:
parent
d22cb600ed
commit
648464b504
83 changed files with 167 additions and 41 deletions
|
@ -13,6 +13,7 @@ import (
|
|||
"net/url"
|
||||
"os"
|
||||
"path"
|
||||
"path/filepath"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
@ -415,3 +416,33 @@ func GetDivergingCommits(repoPath string, baseBranch string, targetBranch string
|
|||
|
||||
return DivergeObject{ahead, behind}, nil
|
||||
}
|
||||
|
||||
// CreateBundle create bundle content to the target path
|
||||
func (repo *Repository) CreateBundle(ctx context.Context, commit string, out io.Writer) error {
|
||||
tmp, err := os.MkdirTemp(os.TempDir(), "gitea-bundle")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer os.RemoveAll(tmp)
|
||||
|
||||
tmpFile := filepath.Join(tmp, "bundle")
|
||||
args := []string{
|
||||
"bundle",
|
||||
"create",
|
||||
tmpFile,
|
||||
commit,
|
||||
}
|
||||
_, err = NewCommandContext(ctx, args...).RunInDir(repo.Path)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
fi, err := os.Open(tmpFile)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer fi.Close()
|
||||
|
||||
_, err = io.Copy(out, fi)
|
||||
return err
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue