Skip to content
This repository was archived by the owner on May 30, 2024. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion internal/pkg/store/repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -220,11 +220,12 @@ func (s *Store) Activate(ctx context.Context, r *ent.Repo) (*ent.Repo, error) {
}

func (s *Store) Deactivate(ctx context.Context, r *ent.Repo) (*ent.Repo, error) {
// NOTE: Do not set the 'owner_id' zero value.
// It could make the constraint error.
ret, err := s.c.Repo.
UpdateOne(r).
SetActive(false).
SetWebhookID(0).
SetOwnerID(0).
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Setting the undefined user occurs the constraint validation error because the owner_id is the foreign key.

Save(ctx)
if ent.IsValidationError(err) {
return nil, e.NewErrorWithMessage(
Expand Down
5 changes: 1 addition & 4 deletions internal/server/global/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,11 @@ import (
"github.com/gitploy-io/gitploy/pkg/e"
)

// GetZapLogLevel return the warning level if the error is managed in the system.
func GetZapLogLevel(err error) zapcore.Level {
if !e.IsError(err) {
return zapcore.ErrorLevel
}

if err.(*e.Error).Code == e.ErrorCodeInternalError {
return zapcore.ErrorLevel
}

Comment on lines -14 to -17
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The type conversion occurs when the error has a wrapping error which type is e.Error.

return zapcore.WarnLevel
}
12 changes: 11 additions & 1 deletion pkg/e/code_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package e

import "testing"
import (
"fmt"
"testing"
)

func Test_IsError(t *testing.T) {
t.Run("Return true when the type of error is Error.", func(t *testing.T) {
Expand All @@ -9,6 +12,13 @@ func Test_IsError(t *testing.T) {
t.Fatalf("IsError = %v, wanted %v", ok, true)
}
})

t.Run("Return false when the type of error is not Error.", func(t *testing.T) {
err := fmt.Errorf("fmt.Error")
if ok := IsError(err); ok {
t.Fatalf("IsError = %v, wanted %v", ok, false)
}
})
}

func Test_HasErrorCode(t *testing.T) {
Expand Down