Skip to content

Commit d5e9ff4

Browse files
Extract initClientAndConfig from issues Run method
- Pull config loading and client creation into a separate helper - Silence unused-parameter lint warnings in test files
1 parent 824e934 commit d5e9ff4

4 files changed

Lines changed: 26 additions & 20 deletions

File tree

command/cmdutil/resolve_run_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -472,7 +472,7 @@ func TestResolveWithPR_PendingNoCompletedRuns(t *testing.T) {
472472

473473
callCount := 0
474474
mock := graphqlclient.NewMockClient()
475-
mock.QueryFunc = func(_ context.Context, query string, _ map[string]any, result any) error {
475+
mock.QueryFunc = func(_ context.Context, _ string, _ map[string]any, result any) error {
476476
callCount++
477477
if callCount == 1 {
478478
return json.Unmarshal(pendingData, result)

command/issues/issues.go

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ func flagUsageLine(f *pflag.Flag) string {
215215
return line
216216
}
217217

218-
func (opts *IssuesOptions) Run(ctx context.Context) error {
218+
func (opts *IssuesOptions) initClientAndConfig() (*deepsource.Client, *vcs.RemoteData, error) {
219219
var cfgMgr *config.Manager
220220
if opts.deps != nil && opts.deps.ConfigMgr != nil {
221221
cfgMgr = opts.deps.ConfigMgr
@@ -224,30 +224,36 @@ func (opts *IssuesOptions) Run(ctx context.Context) error {
224224
}
225225
cfg, err := cfgMgr.Load()
226226
if err != nil {
227-
return clierrors.NewCLIError(clierrors.ErrInvalidConfig, "Error reading DeepSource CLI config", err)
227+
return nil, nil, clierrors.NewCLIError(clierrors.ErrInvalidConfig, "Error reading DeepSource CLI config", err)
228228
}
229229
if err := cfg.VerifyAuthentication(); err != nil {
230-
return err
230+
return nil, nil, err
231231
}
232232

233233
remote, err := vcs.ResolveRemote(opts.RepoArg)
234234
if err != nil {
235-
return err
235+
return nil, nil, err
236236
}
237237
opts.repoSlug = remote.Owner + "/" + remote.RepoName
238238

239-
var client *deepsource.Client
240239
if opts.deps != nil && opts.deps.Client != nil {
241-
client = opts.deps.Client
242-
} else {
243-
client, err = deepsource.New(deepsource.ClientOpts{
244-
Token: cfg.Token,
245-
HostName: cfg.Host,
246-
OnTokenRefreshed: cfgMgr.TokenRefreshCallback(),
247-
})
248-
if err != nil {
249-
return err
250-
}
240+
return opts.deps.Client, remote, nil
241+
}
242+
client, err := deepsource.New(deepsource.ClientOpts{
243+
Token: cfg.Token,
244+
HostName: cfg.Host,
245+
OnTokenRefreshed: cfgMgr.TokenRefreshCallback(),
246+
})
247+
if err != nil {
248+
return nil, nil, err
249+
}
250+
return client, remote, nil
251+
}
252+
253+
func (opts *IssuesOptions) Run(ctx context.Context) error {
254+
client, remote, err := opts.initClientAndConfig()
255+
if err != nil {
256+
return err
251257
}
252258

253259
if opts.CommitOid != "" {

command/issues/tests/issues_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -806,7 +806,7 @@ func TestIssuesPaginationHardCap(t *testing.T) {
806806

807807
mock := graphqlclient.NewMockClient()
808808
callCount := 0
809-
mock.QueryFunc = func(_ context.Context, query string, _ map[string]any, result any) error {
809+
mock.QueryFunc = func(_ context.Context, _ string, _ map[string]any, result any) error {
810810
callCount++
811811
return json.Unmarshal(pageJSON, result)
812812
}
@@ -876,7 +876,7 @@ func TestIssuesPaginationHardCapWarning(t *testing.T) {
876876
}`)
877877

878878
mock := graphqlclient.NewMockClient()
879-
mock.QueryFunc = func(_ context.Context, query string, vars map[string]any, result any) error {
879+
mock.QueryFunc = func(_ context.Context, _ string, _ map[string]any, result any) error {
880880
return json.Unmarshal(pageJSON, result)
881881
}
882882
client := deepsource.NewWithGraphQLClient(mock)

deepsource/graphqlclient/transport_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ func TestSetAuthToken(t *testing.T) {
154154
func TestMockClient_QueryDelegation(t *testing.T) {
155155
called := false
156156
mock := NewMockClient()
157-
mock.QueryFunc = func(ctx context.Context, query string, vars map[string]any, result any) error {
157+
mock.QueryFunc = func(_ context.Context, query string, _ map[string]any, _ any) error {
158158
called = true
159159
if query != "{ viewer }" {
160160
t.Errorf("query = %q, want %q", query, "{ viewer }")
@@ -174,7 +174,7 @@ func TestMockClient_QueryDelegation(t *testing.T) {
174174
func TestMockClient_MutateDelegation(t *testing.T) {
175175
wantErr := errors.New("mutation failed")
176176
mock := NewMockClient()
177-
mock.MutateFunc = func(ctx context.Context, mutation string, vars map[string]any, result any) error {
177+
mock.MutateFunc = func(_ context.Context, _ string, _ map[string]any, _ any) error {
178178
return wantErr
179179
}
180180

0 commit comments

Comments
 (0)