mirror of
https://github.com/apricote/releaser-pleaser.git
synced 2026-02-11 04:07:05 +00:00
refactor: move git to package
This commit is contained in:
parent
44184a77f9
commit
5765b48703
10 changed files with 114 additions and 102 deletions
52
git.go
52
git.go
|
|
@ -1,52 +0,0 @@
|
|||
package rp
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"os"
|
||||
"time"
|
||||
|
||||
"github.com/go-git/go-git/v5"
|
||||
"github.com/go-git/go-git/v5/plumbing"
|
||||
"github.com/go-git/go-git/v5/plumbing/object"
|
||||
"github.com/go-git/go-git/v5/plumbing/transport"
|
||||
)
|
||||
|
||||
const (
|
||||
GitRemoteName = "origin"
|
||||
)
|
||||
|
||||
type Tag struct {
|
||||
Hash string
|
||||
Name string
|
||||
}
|
||||
|
||||
func CloneRepo(ctx context.Context, cloneURL, branch string, auth transport.AuthMethod) (*git.Repository, error) {
|
||||
dir, err := os.MkdirTemp("", "releaser-pleaser.*")
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to create temporary directory for repo clone: %w", err)
|
||||
}
|
||||
|
||||
// TODO: Log tmpdir
|
||||
fmt.Printf("Clone tmpdir: %s\n", dir)
|
||||
repo, err := git.PlainCloneContext(ctx, dir, false, &git.CloneOptions{
|
||||
URL: cloneURL,
|
||||
RemoteName: GitRemoteName,
|
||||
ReferenceName: plumbing.NewBranchReferenceName(branch),
|
||||
SingleBranch: false,
|
||||
Auth: auth,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to clone repository: %w", err)
|
||||
}
|
||||
|
||||
return repo, nil
|
||||
}
|
||||
|
||||
func GitSignature() *object.Signature {
|
||||
return &object.Signature{
|
||||
Name: "releaser-pleaser",
|
||||
Email: "",
|
||||
When: time.Now(),
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue