Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 202bb5f

Browse filesBrowse files
authored
api: seperate internal client into internalapi (sourcegraph#28151)
Users of just the API types no longer need to import httpcli and a whole bunch of other things.
1 parent 8794abe commit 202bb5f
Copy full SHA for 202bb5f

24 files changed

+147-134Lines changed: 147 additions & 134 deletions

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎cmd/gitserver/server/gitolite_phabricator_test.go‎

Copy file name to clipboardExpand all lines: cmd/gitserver/server/gitolite_phabricator_test.go
+5-5Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import (
66
"strings"
77
"testing"
88

9-
"github.com/sourcegraph/sourcegraph/internal/api"
9+
"github.com/sourcegraph/sourcegraph/internal/api/internalapi"
1010
"github.com/sourcegraph/sourcegraph/schema"
1111
)
1212

@@ -19,14 +19,14 @@ func TestServer_handleGet(t *testing.T) {
1919
Url: "https://phab.mycompany.com",
2020
},
2121
}}
22-
api.MockExternalServiceConfigs = func(kind string, result interface{}) error {
22+
internalapi.MockExternalServiceConfigs = func(kind string, result interface{}) error {
2323
buf, err := json.Marshal(conn)
2424
if err != nil {
2525
return err
2626
}
2727
return json.Unmarshal(buf, result)
2828
}
29-
t.Cleanup(func() { api.MockExternalServiceConfigs = nil })
29+
t.Cleanup(func() { internalapi.MockExternalServiceConfigs = nil })
3030

3131
s := &Server{ReposDir: "/testroot"}
3232
h := s.Handler()
@@ -62,14 +62,14 @@ func TestServer_handleGet_invalid(t *testing.T) {
6262
CallsignCommand: `echo "Something went wrong this is not a valid callsign"`,
6363
},
6464
}}
65-
api.MockExternalServiceConfigs = func(kind string, result interface{}) error {
65+
internalapi.MockExternalServiceConfigs = func(kind string, result interface{}) error {
6666
buf, err := json.Marshal(conn)
6767
if err != nil {
6868
return err
6969
}
7070
return json.Unmarshal(buf, result)
7171
}
72-
t.Cleanup(func() { api.MockExternalServiceConfigs = nil })
72+
t.Cleanup(func() { internalapi.MockExternalServiceConfigs = nil })
7373

7474
s := &Server{ReposDir: "/testroot"}
7575
h := s.Handler()
Collapse file

‎cmd/query-runner/email.go‎

Copy file name to clipboardExpand all lines: cmd/query-runner/email.go
+7-6Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,15 @@ import (
99
"github.com/inconshreveable/log15"
1010

1111
"github.com/sourcegraph/sourcegraph/internal/api"
12+
"github.com/sourcegraph/sourcegraph/internal/api/internalapi"
1213
"github.com/sourcegraph/sourcegraph/internal/txemail"
1314
"github.com/sourcegraph/sourcegraph/internal/txemail/txtypes"
1415
)
1516

1617
func canSendEmail(ctx context.Context) error {
17-
canSendEmail, err := api.InternalClient.CanSendEmail(ctx)
18+
canSendEmail, err := internalapi.Client.CanSendEmail(ctx)
1819
if err != nil {
19-
return errors.Wrap(err, "InternalClient.CanSendEmail")
20+
return errors.Wrap(err, "internalapi.Client.CanSendEmail")
2021
}
2122
if !canSendEmail {
2223
return errors.New("SMTP server not set in site configuration")
@@ -131,20 +132,20 @@ func emailNotifySubscribeUnsubscribe(ctx context.Context, recipient *recipient,
131132
}
132133

133134
func sendEmail(ctx context.Context, userID int32, eventType string, template txtypes.Templates, data interface{}) error {
134-
email, err := api.InternalClient.UserEmailsGetEmail(ctx, userID)
135+
email, err := internalapi.Client.UserEmailsGetEmail(ctx, userID)
135136
if err != nil {
136-
return errors.Wrap(err, fmt.Sprintf("InternalClient.UserEmailsGetEmail for userID=%d", userID))
137+
return errors.Wrap(err, fmt.Sprintf("internalapi.Client.UserEmailsGetEmail for userID=%d", userID))
137138
}
138139
if email == nil {
139140
return errors.Errorf("unable to send email to user ID %d with unknown email address", userID)
140141
}
141142

142-
if err := api.InternalClient.SendEmail(ctx, txtypes.Message{
143+
if err := internalapi.Client.SendEmail(ctx, txtypes.Message{
143144
To: []string{*email},
144145
Template: template,
145146
Data: data,
146147
}); err != nil {
147-
return errors.Wrap(err, fmt.Sprintf("InternalClient.SendEmail to email=%q userID=%d", *email, userID))
148+
return errors.Wrap(err, fmt.Sprintf("internalapi.Client.SendEmail to email=%q userID=%d", *email, userID))
148149
}
149150
logEvent(userID, "SavedSearchEmailNotificationSent", eventType)
150151
return nil
Collapse file

‎cmd/query-runner/graphql.go‎

Copy file name to clipboardExpand all lines: cmd/query-runner/graphql.go
+2-1Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"time"
1212

1313
"github.com/sourcegraph/sourcegraph/internal/api"
14+
"github.com/sourcegraph/sourcegraph/internal/api/internalapi"
1415
"github.com/sourcegraph/sourcegraph/internal/httpcli"
1516

1617
"github.com/cockroachdb/errors"
@@ -160,7 +161,7 @@ func search(ctx context.Context, query string) (*gqlSearchResponse, error) {
160161
}
161162

162163
func gqlURL(queryName string) (string, error) {
163-
u, err := url.Parse(api.InternalClient.URL)
164+
u, err := url.Parse(internalapi.Client.URL)
164165
if err != nil {
165166
return "", err
166167
}
Collapse file

‎cmd/query-runner/main.go‎

Copy file name to clipboardExpand all lines: cmd/query-runner/main.go
+5-4Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020

2121
"github.com/sourcegraph/sourcegraph/cmd/query-runner/queryrunnerapi"
2222
"github.com/sourcegraph/sourcegraph/internal/api"
23+
"github.com/sourcegraph/sourcegraph/internal/api/internalapi"
2324
"github.com/sourcegraph/sourcegraph/internal/conf"
2425
"github.com/sourcegraph/sourcegraph/internal/debugserver"
2526
"github.com/sourcegraph/sourcegraph/internal/env"
@@ -118,7 +119,7 @@ func (e *executorT) run(ctx context.Context) error {
118119
// (impossible for new results to exist).
119120
var oldList map[api.SavedQueryIDSpec]api.ConfigSavedQuery
120121
for {
121-
allSavedQueries, err := api.InternalClient.SavedQueriesListAll(context.Background())
122+
allSavedQueries, err := internalapi.Client.SavedQueriesListAll(context.Background())
122123
if err != nil {
123124
log15.Error("executor: error fetching saved queries list (trying again in 5s", "error", err)
124125
time.Sleep(5 * time.Second)
@@ -161,7 +162,7 @@ func (e *executorT) runQuery(ctx context.Context, spec api.SavedQueryIDSpec, que
161162
return nil
162163
}
163164

164-
info, err := api.InternalClient.SavedQueriesGetInfo(ctx, query.Query)
165+
info, err := internalapi.Client.SavedQueriesGetInfo(ctx, query.Query)
165166
if err != nil {
166167
return errors.Wrap(err, "SavedQueriesGetInfo")
167168
}
@@ -211,7 +212,7 @@ func (e *executorT) runQuery(ctx context.Context, spec api.SavedQueryIDSpec, que
211212
// constantly and potentially causing harm to the system. We'll retry at
212213
// our normal interval, regardless of errors.
213214
v, execDuration, searchErr := performSearch(ctx, newQuery)
214-
if err := api.InternalClient.SavedQueriesSetInfo(ctx, &api.SavedQueryInfo{
215+
if err := internalapi.Client.SavedQueriesSetInfo(ctx, &api.SavedQueryInfo{
215216
Query: query.Query,
216217
LastExecuted: time.Now(),
217218
LatestResult: latestResultTime(info, v, searchErr),
@@ -340,7 +341,7 @@ func savedSearchListPageURL(utmSource string) string {
340341
func sourcegraphURL(path, query, utmSource string) string {
341342
if externalURL == nil {
342343
// Determine the external URL.
343-
externalURLStr, err := api.InternalClient.ExternalURL(context.Background())
344+
externalURLStr, err := internalapi.Client.ExternalURL(context.Background())
344345
if err != nil {
345346
log15.Error("failed to get ExternalURL", err)
346347
return ""
Collapse file

‎cmd/query-runner/notif.go‎

Copy file name to clipboardExpand all lines: cmd/query-runner/notif.go
+2-1Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"fmt"
66

77
"github.com/sourcegraph/sourcegraph/internal/api"
8+
"github.com/sourcegraph/sourcegraph/internal/api/internalapi"
89
)
910

1011
// recipientSpec identifies a recipient of a saved search notification. Exactly one of its fields is
@@ -49,7 +50,7 @@ func getNotificationRecipients(ctx context.Context, spec api.SavedQueryIDSpec, q
4950
case spec.Subject.Org != nil:
5051
if query.Notify {
5152
// Email all org members.
52-
orgMembers, err := api.InternalClient.OrgsListUsers(ctx, *spec.Subject.Org)
53+
orgMembers, err := internalapi.Client.OrgsListUsers(ctx, *spec.Subject.Org)
5354
if err != nil {
5455
return nil, err
5556
}
Collapse file

‎doc/admin/observability/alert_solutions.md‎

Copy file name to clipboardExpand all lines: doc/admin/observability/alert_solutions.md
+3-3Lines changed: 3 additions & 3 deletions
  • Display the source diff
  • Display the rich diff
Original file line numberDiff line numberDiff line change
@@ -534,7 +534,7 @@ To learn more about Sourcegraph's alerting and how to set up alerts, see [our al
534534

535535
<br />
536536

537-
## frontend: internal_api_error_responses
537+
## frontend: internalapi_error_responses
538538

539539
<p class="subtitle">internal API error responses every 5m by route</p>
540540

@@ -545,12 +545,12 @@ To learn more about Sourcegraph's alerting and how to set up alerts, see [our al
545545
**Possible solutions**
546546

547547
- May not be a substantial issue, check the `frontend` logs for potential causes.
548-
- Learn more about the related dashboard panel in the [dashboards reference](./dashboards.md#frontend-internal-api-error-responses).
548+
- Learn more about the related dashboard panel in the [dashboards reference](./dashboards.md#frontend-internalapi-error-responses).
549549
- **Silence this alert:** If you are aware of this alert and want to silence notifications for it, add the following to your site configuration and set a reminder to re-evaluate the alert:
550550

551551
```json
552552
"observability.silenceAlerts": [
553-
"warning_frontend_internal_api_error_responses"
553+
"warning_frontend_internalapi_error_responses"
554554
]
555555
```
556556

Collapse file

‎doc/admin/observability/dashboards.md‎

Copy file name to clipboardExpand all lines: doc/admin/observability/dashboards.md
+2-2Lines changed: 2 additions & 2 deletions
  • Display the source diff
  • Display the rich diff
Original file line numberDiff line numberDiff line change
@@ -2039,11 +2039,11 @@ Query: `sum by(code) (increase(searcher_service_request_total{code!~"2.."}[5m]))
20392039

20402040
<br />
20412041

2042-
#### frontend: internal_api_error_responses
2042+
#### frontend: internalapi_error_responses
20432043

20442044
<p class="subtitle">Internal API error responses every 5m by route</p>
20452045

2046-
Refer to the [alert solutions reference](./alert_solutions.md#frontend-internal-api-error-responses) for 1 alert related to this panel.
2046+
Refer to the [alert solutions reference](./alert_solutions.md#frontend-internalapi-error-responses) for 1 alert related to this panel.
20472047

20482048
To see this panel, visit `/-/debug/grafana/d/frontend/frontend?viewPanel=101502` on your Sourcegraph instance.
20492049

Collapse file

‎enterprise/internal/batches/reconciler/executor.go‎

Copy file name to clipboardExpand all lines: enterprise/internal/batches/reconciler/executor.go
+2-1Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import (
1616
"github.com/sourcegraph/sourcegraph/enterprise/internal/batches/store"
1717
btypes "github.com/sourcegraph/sourcegraph/enterprise/internal/batches/types"
1818
"github.com/sourcegraph/sourcegraph/internal/api"
19+
"github.com/sourcegraph/sourcegraph/internal/api/internalapi"
1920
"github.com/sourcegraph/sourcegraph/internal/database"
2021
"github.com/sourcegraph/sourcegraph/internal/errcode"
2122
"github.com/sourcegraph/sourcegraph/internal/gitserver/protocol"
@@ -550,7 +551,7 @@ func decorateChangesetBody(ctx context.Context, tx getBatchChanger, nsStore getN
550551
// internalClient is here for mocking reasons.
551552
var internalClient interface {
552553
ExternalURL(context.Context) (string, error)
553-
} = api.InternalClient
554+
} = internalapi.Client
554555

555556
func batchChangeURL(ctx context.Context, ns *database.Namespace, c *btypes.BatchChange) (string, error) {
556557
// To build the absolute URL, we need to know where Sourcegraph is!
Collapse file

‎enterprise/internal/batches/reconciler/executor_test.go‎

Copy file name to clipboardExpand all lines: enterprise/internal/batches/reconciler/executor_test.go
+5-5Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import (
1515
ct "github.com/sourcegraph/sourcegraph/enterprise/internal/batches/testing"
1616
btypes "github.com/sourcegraph/sourcegraph/enterprise/internal/batches/types"
1717
"github.com/sourcegraph/sourcegraph/internal/actor"
18-
"github.com/sourcegraph/sourcegraph/internal/api"
18+
"github.com/sourcegraph/sourcegraph/internal/api/internalapi"
1919
"github.com/sourcegraph/sourcegraph/internal/database"
2020
"github.com/sourcegraph/sourcegraph/internal/database/dbmock"
2121
"github.com/sourcegraph/sourcegraph/internal/database/dbtest"
@@ -54,7 +54,7 @@ func TestExecutor_ExecutePlan(t *testing.T) {
5454
defer state.Unmock()
5555

5656
internalClient = &mockInternalClient{externalURL: "https://sourcegraph.test"}
57-
defer func() { internalClient = api.InternalClient }()
57+
defer func() { internalClient = internalapi.Client }()
5858

5959
githubPR := buildGithubPR(clock(), btypes.ChangesetExternalStateOpen)
6060
githubHeadRef := git.EnsureRefPrefix(githubPR.HeadRefName)
@@ -1047,7 +1047,7 @@ func TestDecorateChangesetBody(t *testing.T) {
10471047
})
10481048

10491049
internalClient = &mockInternalClient{externalURL: "https://sourcegraph.test"}
1050-
defer func() { internalClient = api.InternalClient }()
1050+
defer func() { internalClient = internalapi.Client }()
10511051

10521052
fs := &FakeStore{
10531053
GetBatchChangeMock: func(ctx context.Context, opts store.GetBatchChangeOpts) (*btypes.BatchChange, error) {
@@ -1077,7 +1077,7 @@ func TestBatchChangeURL(t *testing.T) {
10771077
} {
10781078
t.Run(name, func(t *testing.T) {
10791079
internalClient = tc
1080-
defer func() { internalClient = api.InternalClient }()
1080+
defer func() { internalClient = internalapi.Client }()
10811081

10821082
if _, err := batchChangeURL(ctx, nil, nil); err == nil {
10831083
t.Error("unexpected nil error")
@@ -1088,7 +1088,7 @@ func TestBatchChangeURL(t *testing.T) {
10881088

10891089
t.Run("success", func(t *testing.T) {
10901090
internalClient = &mockInternalClient{externalURL: "https://sourcegraph.test"}
1091-
defer func() { internalClient = api.InternalClient }()
1091+
defer func() { internalClient = internalapi.Client }()
10921092

10931093
url, err := batchChangeURL(
10941094
ctx,
Collapse file

‎enterprise/internal/batches/reconciler/reconciler_test.go‎

Copy file name to clipboardExpand all lines: enterprise/internal/batches/reconciler/reconciler_test.go
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import (
1010
ct "github.com/sourcegraph/sourcegraph/enterprise/internal/batches/testing"
1111
btypes "github.com/sourcegraph/sourcegraph/enterprise/internal/batches/types"
1212
"github.com/sourcegraph/sourcegraph/internal/actor"
13-
"github.com/sourcegraph/sourcegraph/internal/api"
13+
"github.com/sourcegraph/sourcegraph/internal/api/internalapi"
1414
"github.com/sourcegraph/sourcegraph/internal/database/dbtest"
1515
"github.com/sourcegraph/sourcegraph/internal/observation"
1616
"github.com/sourcegraph/sourcegraph/internal/repoupdater/protocol"
@@ -39,7 +39,7 @@ func TestReconcilerProcess_IntegrationTest(t *testing.T) {
3939
defer state.Unmock()
4040

4141
internalClient = &mockInternalClient{externalURL: "https://sourcegraph.test"}
42-
defer func() { internalClient = api.InternalClient }()
42+
defer func() { internalClient = internalapi.Client }()
4343

4444
githubPR := buildGithubPR(time.Now(), btypes.ChangesetExternalStateOpen)
4545
githubHeadRef := git.EnsureRefPrefix(githubPR.HeadRefName)

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.