fixed creating prs and returning early
This commit is contained in:
parent
f4290d8300
commit
be40a497ca
@ -1,6 +1,9 @@
|
||||
package commands
|
||||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
|
||||
"git.front.kjuulh.io/kjuulh/octopush/internal/cli"
|
||||
"git.front.kjuulh.io/kjuulh/octopush/internal/commands"
|
||||
"github.com/spf13/cobra"
|
||||
@ -23,11 +26,18 @@ func CreateOctopushProcessCmd(logger *zap.Logger) *cobra.Command {
|
||||
|
||||
ctx := cmd.Context()
|
||||
|
||||
deps, err := cli.Start(ctx, logger)
|
||||
deps, cleanupFunc, err := cli.Start(ctx, logger)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
defer func() {
|
||||
ctx, _ = context.WithTimeout(ctx, time.Second*5)
|
||||
if err := cleanupFunc(ctx); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}()
|
||||
|
||||
err = commands.
|
||||
NewProcessRepos(logger, deps).
|
||||
Process(ctx, actionsRepo, branch, path)
|
||||
|
2
go.mod
2
go.mod
@ -4,7 +4,7 @@ go 1.19
|
||||
|
||||
require (
|
||||
code.gitea.io/sdk/gitea v0.15.1
|
||||
git.front.kjuulh.io/kjuulh/curre v1.3.1
|
||||
git.front.kjuulh.io/kjuulh/curre v1.3.5
|
||||
github.com/ProtonMail/go-crypto v0.0.0-20220822140716-1678d6eb0cbe
|
||||
github.com/gin-contrib/zap v0.0.2
|
||||
github.com/gin-gonic/gin v1.8.1
|
||||
|
4
go.sum
4
go.sum
@ -1,8 +1,8 @@
|
||||
code.gitea.io/gitea-vet v0.2.1/go.mod h1:zcNbT/aJEmivCAhfmkHOlT645KNOf9W2KnkLgFjGGfE=
|
||||
code.gitea.io/sdk/gitea v0.15.1 h1:WJreC7YYuxbn0UDaPuWIe/mtiNKTvLN8MLkaw71yx/M=
|
||||
code.gitea.io/sdk/gitea v0.15.1/go.mod h1:klY2LVI3s3NChzIk/MzMn7G1FHrfU7qd63iSMVoHRBA=
|
||||
git.front.kjuulh.io/kjuulh/curre v1.3.1 h1:fPVEAZgf6qST51IEOrrEiKNASvU0aaf8kKS/zqQ3z18=
|
||||
git.front.kjuulh.io/kjuulh/curre v1.3.1/go.mod h1:m7WpSehONLqPh/XF3F0BI0UOpLOfGuDmDEFI1XsM6fE=
|
||||
git.front.kjuulh.io/kjuulh/curre v1.3.5 h1:oKYh5Z0vInjViLnS4ppzK0G2Mnj7vXq8mA5i/rsWId4=
|
||||
git.front.kjuulh.io/kjuulh/curre v1.3.5/go.mod h1:m7WpSehONLqPh/XF3F0BI0UOpLOfGuDmDEFI1XsM6fE=
|
||||
github.com/Microsoft/go-winio v0.4.14/go.mod h1:qXqCSQ3Xa7+6tgxaGTIe4Kpcdsi+P8jBhyzoq1bpyYA=
|
||||
github.com/Microsoft/go-winio v0.4.16/go.mod h1:XB6nPKklQyQ7GC9LdcBEcBl8PF76WugXOPRXwdLnMv0=
|
||||
github.com/Microsoft/go-winio v0.5.2 h1:a9IhgEQBCUEk6QCdml9CiJGhAws+YwffDHEMp1VMrpA=
|
||||
|
@ -10,12 +10,12 @@ import (
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
func Start(ctx context.Context, logger *zap.Logger) (*serverdeps.ServerDeps, error) {
|
||||
func Start(ctx context.Context, logger *zap.Logger) (*serverdeps.ServerDeps, curre.CleanupFunc, error) {
|
||||
deps := serverdeps.NewServerDeps(logger)
|
||||
|
||||
readyChan := make(chan curre.ComponentsAreReady, 1)
|
||||
|
||||
err := curre.NewManager().
|
||||
cleanupFunc, err := curre.NewManager().
|
||||
Register(
|
||||
server.NewStorageServer(logger.With(zap.Namespace("storage")), deps),
|
||||
).
|
||||
@ -26,5 +26,5 @@ func Start(ctx context.Context, logger *zap.Logger) (*serverdeps.ServerDeps, err
|
||||
|
||||
<-readyChan
|
||||
|
||||
return deps, err
|
||||
return deps, cleanupFunc, err
|
||||
}
|
||||
|
@ -189,8 +189,9 @@ func (pr *ProcessRepos) commit(ctx context.Context, area *storage.Area, repo *pr
|
||||
}
|
||||
|
||||
if status.IsClean() {
|
||||
// TODO: check for pr
|
||||
pr.logger.Info("Returning early, as no modifications are detected")
|
||||
return nil
|
||||
//return nil
|
||||
}
|
||||
|
||||
err = pr.git.Commit(ctx, repo)
|
||||
|
@ -84,7 +84,7 @@ func (g *GoGit) GetOriginHEADForRepo(ctx context.Context, gitRepo *GoGitRepo) (s
|
||||
headRef := ""
|
||||
for _, ref := range refs {
|
||||
//g.logger.Debug(ref.String())
|
||||
if !ref.Name().IsBranch() {
|
||||
if ref.Target().IsBranch() {
|
||||
headRef = ref.Target().Short()
|
||||
}
|
||||
}
|
||||
@ -149,7 +149,7 @@ func (g *GoGit) Clone(ctx context.Context, storageArea *storage.Area, repoUrl st
|
||||
URL: repoUrl,
|
||||
Auth: auth,
|
||||
RemoteName: "origin",
|
||||
ReferenceName: "refs/heads/main",
|
||||
ReferenceName: "",
|
||||
SingleBranch: false,
|
||||
NoCheckout: false,
|
||||
Depth: 1,
|
||||
@ -227,12 +227,12 @@ func (g *GoGit) CreateBranch(ctx context.Context, gitRepo *GoGitRepo) error {
|
||||
return fmt.Errorf("could not checkout branch: %w", err)
|
||||
}
|
||||
|
||||
remoteRef := plumbing.NewRemoteReferenceName("origin", "octopush-apply")
|
||||
ref := plumbing.NewSymbolicReference(refSpec, remoteRef)
|
||||
err = gitRepo.repo.Storer.SetReference(ref)
|
||||
if err != nil {
|
||||
return fmt.Errorf("could not set reference: %w", err)
|
||||
}
|
||||
//remoteRef := plumbing.NewRemoteReferenceName("origin", "octopush-apply")
|
||||
//ref := plumbing.NewSymbolicReference(refSpec, remoteRef)
|
||||
//err = gitRepo.repo.Storer.SetReference(ref)
|
||||
//if err != nil {
|
||||
// return fmt.Errorf("could not set reference: %w", err)
|
||||
//}
|
||||
|
||||
auth, err := g.GetAuth()
|
||||
if err != nil {
|
||||
@ -241,7 +241,7 @@ func (g *GoGit) CreateBranch(ctx context.Context, gitRepo *GoGitRepo) error {
|
||||
|
||||
err = worktree.PullContext(ctx, &git.PullOptions{
|
||||
RemoteName: "origin",
|
||||
ReferenceName: "refs/heads/main",
|
||||
ReferenceName: "",
|
||||
SingleBranch: false,
|
||||
Depth: 1,
|
||||
Auth: auth,
|
||||
|
Loading…
Reference in New Issue
Block a user