fix/require-two-pushes #20

Merged
kjuulh merged 2 commits from fix/require-two-pushes into v0.2 2022-09-21 22:48:49 +02:00
8 changed files with 30 additions and 19 deletions

View File

@ -3,7 +3,7 @@ name: write-a-readme
select: select:
repositories: repositories:
- git@git.front.kjuulh.io:kjuulh/octopush-test.git - git@git.front.kjuulh.io:kjuulh/octopush-test.git
- git@git.front.kjuulh.io:kjuulh/octopush.git #- git@git.front.kjuulh.io:kjuulh/octopush.git
# providers: # providers:
# - gitea: https://git.front.kjuulh.io # - gitea: https://git.front.kjuulh.io
# organisation: "cibus" # organisation: "cibus"

View File

@ -1,6 +1,9 @@
package commands package commands
import ( import (
"context"
"time"
"git.front.kjuulh.io/kjuulh/octopush/internal/cli" "git.front.kjuulh.io/kjuulh/octopush/internal/cli"
"git.front.kjuulh.io/kjuulh/octopush/internal/commands" "git.front.kjuulh.io/kjuulh/octopush/internal/commands"
"github.com/spf13/cobra" "github.com/spf13/cobra"
@ -23,11 +26,18 @@ func CreateOctopushProcessCmd(logger *zap.Logger) *cobra.Command {
ctx := cmd.Context() ctx := cmd.Context()
deps, err := cli.Start(ctx, logger) deps, cleanupFunc, err := cli.Start(ctx, logger)
if err != nil { if err != nil {
return err return err
} }
defer func() {
ctx, _ = context.WithTimeout(ctx, time.Second*5)
if err := cleanupFunc(ctx); err != nil {
panic(err)
}
}()
err = commands. err = commands.
NewProcessRepos(logger, deps). NewProcessRepos(logger, deps).
Process(ctx, actionsRepo, branch, path) Process(ctx, actionsRepo, branch, path)

2
go.mod
View File

@ -4,7 +4,7 @@ go 1.19
require ( require (
code.gitea.io/sdk/gitea v0.15.1 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/ProtonMail/go-crypto v0.0.0-20220822140716-1678d6eb0cbe
github.com/gin-contrib/zap v0.0.2 github.com/gin-contrib/zap v0.0.2
github.com/gin-gonic/gin v1.8.1 github.com/gin-gonic/gin v1.8.1

4
go.sum
View File

@ -1,8 +1,8 @@
code.gitea.io/gitea-vet v0.2.1/go.mod h1:zcNbT/aJEmivCAhfmkHOlT645KNOf9W2KnkLgFjGGfE= 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 h1:WJreC7YYuxbn0UDaPuWIe/mtiNKTvLN8MLkaw71yx/M=
code.gitea.io/sdk/gitea v0.15.1/go.mod h1:klY2LVI3s3NChzIk/MzMn7G1FHrfU7qd63iSMVoHRBA= 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.5 h1:oKYh5Z0vInjViLnS4ppzK0G2Mnj7vXq8mA5i/rsWId4=
git.front.kjuulh.io/kjuulh/curre v1.3.1/go.mod h1:m7WpSehONLqPh/XF3F0BI0UOpLOfGuDmDEFI1XsM6fE= 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.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.4.16/go.mod h1:XB6nPKklQyQ7GC9LdcBEcBl8PF76WugXOPRXwdLnMv0=
github.com/Microsoft/go-winio v0.5.2 h1:a9IhgEQBCUEk6QCdml9CiJGhAws+YwffDHEMp1VMrpA= github.com/Microsoft/go-winio v0.5.2 h1:a9IhgEQBCUEk6QCdml9CiJGhAws+YwffDHEMp1VMrpA=

View File

@ -10,12 +10,12 @@ import (
"go.uber.org/zap" "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) deps := serverdeps.NewServerDeps(logger)
readyChan := make(chan curre.ComponentsAreReady, 1) readyChan := make(chan curre.ComponentsAreReady, 1)
err := curre.NewManager(). cleanupFunc, err := curre.NewManager().
Register( Register(
server.NewStorageServer(logger.With(zap.Namespace("storage")), deps), server.NewStorageServer(logger.With(zap.Namespace("storage")), deps),
). ).
@ -26,5 +26,5 @@ func Start(ctx context.Context, logger *zap.Logger) (*serverdeps.ServerDeps, err
<-readyChan <-readyChan
return deps, err return deps, cleanupFunc, err
} }

View File

@ -189,8 +189,9 @@ func (pr *ProcessRepos) commit(ctx context.Context, area *storage.Area, repo *pr
} }
if status.IsClean() { if status.IsClean() {
// TODO: check for pr
pr.logger.Info("Returning early, as no modifications are detected") pr.logger.Info("Returning early, as no modifications are detected")
return nil //return nil
} }
err = pr.git.Commit(ctx, repo) err = pr.git.Commit(ctx, repo)

View File

@ -12,7 +12,7 @@ func New() (*zap.Logger, error) {
return lvl >= zapcore.ErrorLevel return lvl >= zapcore.ErrorLevel
}) })
lowPriority := zap.LevelEnablerFunc(func(lvl zapcore.Level) bool { lowPriority := zap.LevelEnablerFunc(func(lvl zapcore.Level) bool {
return lvl < zapcore.ErrorLevel && lvl > zapcore.DebugLevel return lvl < zapcore.ErrorLevel // && lvl > zapcore.DebugLevel
}) })
config := zap.NewDevelopmentEncoderConfig() config := zap.NewDevelopmentEncoderConfig()

View File

@ -84,7 +84,7 @@ func (g *GoGit) GetOriginHEADForRepo(ctx context.Context, gitRepo *GoGitRepo) (s
headRef := "" headRef := ""
for _, ref := range refs { for _, ref := range refs {
//g.logger.Debug(ref.String()) //g.logger.Debug(ref.String())
if !ref.Name().IsBranch() { if ref.Target().IsBranch() {
headRef = ref.Target().Short() headRef = ref.Target().Short()
} }
} }
@ -149,7 +149,7 @@ func (g *GoGit) Clone(ctx context.Context, storageArea *storage.Area, repoUrl st
URL: repoUrl, URL: repoUrl,
Auth: auth, Auth: auth,
RemoteName: "origin", RemoteName: "origin",
ReferenceName: "refs/heads/main", ReferenceName: "",
SingleBranch: false, SingleBranch: false,
NoCheckout: false, NoCheckout: false,
Depth: 1, 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) return fmt.Errorf("could not checkout branch: %w", err)
} }
remoteRef := plumbing.NewRemoteReferenceName("origin", "octopush-apply") //remoteRef := plumbing.NewRemoteReferenceName("origin", "octopush-apply")
ref := plumbing.NewSymbolicReference(refSpec, remoteRef) //ref := plumbing.NewSymbolicReference(refSpec, remoteRef)
err = gitRepo.repo.Storer.SetReference(ref) //err = gitRepo.repo.Storer.SetReference(ref)
if err != nil { //if err != nil {
return fmt.Errorf("could not set reference: %w", err) // return fmt.Errorf("could not set reference: %w", err)
} //}
auth, err := g.GetAuth() auth, err := g.GetAuth()
if err != nil { if err != nil {
@ -241,7 +241,7 @@ func (g *GoGit) CreateBranch(ctx context.Context, gitRepo *GoGitRepo) error {
err = worktree.PullContext(ctx, &git.PullOptions{ err = worktree.PullContext(ctx, &git.PullOptions{
RemoteName: "origin", RemoteName: "origin",
ReferenceName: "refs/heads/main", ReferenceName: "",
SingleBranch: false, SingleBranch: false,
Depth: 1, Depth: 1,
Auth: auth, Auth: auth,