Skip to content
This repository was archived by the owner on May 30, 2024. It is now read-only.

Commit 63800a4

Browse files
author
Noah Hanjun Lee
authored
Fix the error of the deactivation (#245)
* Fix the bug by the nested error * Fix the bug from the constraint validation
1 parent f15c525 commit 63800a4

File tree

3 files changed

+14
-6
lines changed

3 files changed

+14
-6
lines changed

internal/pkg/store/repo.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,11 +220,12 @@ func (s *Store) Activate(ctx context.Context, r *ent.Repo) (*ent.Repo, error) {
220220
}
221221

222222
func (s *Store) Deactivate(ctx context.Context, r *ent.Repo) (*ent.Repo, error) {
223+
// NOTE: Do not set the 'owner_id' zero value.
224+
// It could make the constraint error.
223225
ret, err := s.c.Repo.
224226
UpdateOne(r).
225227
SetActive(false).
226228
SetWebhookID(0).
227-
SetOwnerID(0).
228229
Save(ctx)
229230
if ent.IsValidationError(err) {
230231
return nil, e.NewErrorWithMessage(

internal/server/global/helper.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,11 @@ import (
66
"github.com/gitploy-io/gitploy/pkg/e"
77
)
88

9+
// GetZapLogLevel return the warning level if the error is managed in the system.
910
func GetZapLogLevel(err error) zapcore.Level {
1011
if !e.IsError(err) {
1112
return zapcore.ErrorLevel
1213
}
1314

14-
if err.(*e.Error).Code == e.ErrorCodeInternalError {
15-
return zapcore.ErrorLevel
16-
}
17-
1815
return zapcore.WarnLevel
1916
}

pkg/e/code_test.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
package e
22

3-
import "testing"
3+
import (
4+
"fmt"
5+
"testing"
6+
)
47

58
func Test_IsError(t *testing.T) {
69
t.Run("Return true when the type of error is Error.", func(t *testing.T) {
@@ -9,6 +12,13 @@ func Test_IsError(t *testing.T) {
912
t.Fatalf("IsError = %v, wanted %v", ok, true)
1013
}
1114
})
15+
16+
t.Run("Return false when the type of error is not Error.", func(t *testing.T) {
17+
err := fmt.Errorf("fmt.Error")
18+
if ok := IsError(err); ok {
19+
t.Fatalf("IsError = %v, wanted %v", ok, false)
20+
}
21+
})
1222
}
1323

1424
func Test_HasErrorCode(t *testing.T) {

0 commit comments

Comments
 (0)