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

Commit 9c03040

Browse files
author
noah
committed
Fix lint & test
1 parent 6798008 commit 9c03040

File tree

4 files changed

+12
-44
lines changed

4 files changed

+12
-44
lines changed

internal/interactor/global.go

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package interactor
2+
3+
// ContextKey is used for context access.
4+
type ContextKey int
5+
6+
const (
7+
KeyUser ContextKey = iota
8+
)

internal/interactor/interface.go

-2
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@ import (
99
"github.com/gitploy-io/gitploy/model/extent"
1010
)
1111

12-
const KeyUser = "gitploy.user"
13-
1412
type (
1513
Store interface {
1614
UserStore

internal/server/api/v1/repos/deployment_change.go

+2-31
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package repos
22

33
import (
44
"context"
5-
"fmt"
65
"net/http"
76
"strconv"
87

@@ -12,7 +11,6 @@ import (
1211
i "github.com/gitploy-io/gitploy/internal/interactor"
1312
gb "github.com/gitploy-io/gitploy/internal/server/global"
1413
"github.com/gitploy-io/gitploy/model/ent"
15-
"github.com/gitploy-io/gitploy/model/ent/deployment"
1614
"github.com/gitploy-io/gitploy/pkg/e"
1715
)
1816

@@ -48,7 +46,7 @@ func (s *DeploymentAPI) ListChanges(c *gin.Context) {
4846
vr, _ := c.Get(KeyRepo)
4947
re := vr.(*ent.Repo)
5048

51-
ctx := context.WithValue(c.Request.Context(), gb.KeyUser, u)
49+
ctx := context.WithValue(c.Request.Context(), i.KeyUser, u)
5250

5351
d, err := s.i.FindDeploymentOfRepoByNumber(ctx, re, number)
5452
if err != nil {
@@ -67,33 +65,6 @@ func (s *DeploymentAPI) ListChanges(c *gin.Context) {
6765
return
6866
}
6967

68+
s.log.Info("Get the changed commits for the deployment.", zap.Int("number", number))
7069
gb.Response(c, http.StatusOK, commits)
7170
}
72-
73-
func (s *DeploymentAPI) getCommitSha(ctx context.Context, u *ent.User, re *ent.Repo, typ deployment.Type, ref string) (string, error) {
74-
switch typ {
75-
case deployment.TypeCommit:
76-
c, err := s.i.GetCommit(ctx, u, re, ref)
77-
if err != nil {
78-
return "", err
79-
}
80-
81-
return c.SHA, nil
82-
case deployment.TypeBranch:
83-
b, err := s.i.GetBranch(ctx, u, re, ref)
84-
if err != nil {
85-
return "", err
86-
}
87-
88-
return b.CommitSHA, nil
89-
case deployment.TypeTag:
90-
t, err := s.i.GetTag(ctx, u, re, ref)
91-
if err != nil {
92-
return "", err
93-
}
94-
95-
return t.CommitSHA, nil
96-
default:
97-
return "", fmt.Errorf("Type must be one of commit, branch, tag.")
98-
}
99-
}

internal/server/api/v1/repos/deployment_change_test.go

+2-11
Original file line numberDiff line numberDiff line change
@@ -55,21 +55,12 @@ func TestDeploymentAPI_ListChanges(t *testing.T) {
5555

5656
m.
5757
EXPECT().
58-
FindPrevSuccessDeployment(ctx, any).
59-
Return(&ent.Deployment{
60-
ID: 5,
61-
Sha: base,
62-
Status: deployment.StatusSuccess,
63-
}, nil)
64-
65-
m.
66-
EXPECT().
67-
CompareCommits(ctx, any, any, base, head, gomock.Any()).
58+
CompareCommitsFromLastestDeployment(ctx, any, gomock.AssignableToTypeOf(&ent.Deployment{}), any).
6859
Return([]*extent.Commit{
6960
{
7061
SHA: head,
7162
},
72-
}, []*extent.CommitFile{}, nil)
63+
}, nil)
7364

7465
// Ready the router to handle it.
7566
gin.SetMode(gin.ReleaseMode)

0 commit comments

Comments
 (0)