Skip to content

Commit 3247ee3

Browse files
committed
chore(ci): align API and tests with repository conventions
1 parent 9a5a896 commit 3247ee3

File tree

2 files changed

+21
-15
lines changed

2 files changed

+21
-15
lines changed

pkg/api/ci.go

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,16 +30,31 @@ func ciRequest[T any](ctx context.Context, token, orgID, path string, payload in
3030
}
3131

3232
req.Header.Add("Content-Type", "application/json")
33-
req.Header.Add("Authorization", fmt.Sprintf("Bearer %s", token))
34-
req.Header.Add("x-depot-org", orgID)
33+
if token != "" {
34+
req.Header.Add("Authorization", fmt.Sprintf("Bearer %s", token))
35+
}
36+
if orgID != "" {
37+
req.Header.Add("x-depot-org", orgID)
38+
}
3539
req.Header.Add("User-Agent", Agent())
40+
req.Header.Add("Depot-User-Agent", Agent())
3641

3742
resp, err := client.Do(req)
3843
if err != nil {
3944
return nil, err
4045
}
4146
defer resp.Body.Close()
4247

48+
infoMessage := resp.Header.Get("X-Depot-Info-Message")
49+
if infoMessage != "" {
50+
fmt.Println(infoStyle.Render(infoMessage))
51+
}
52+
53+
warnMessage := resp.Header.Get("X-Depot-Warn-Message")
54+
if warnMessage != "" {
55+
fmt.Println(warnStyle.Render(warnMessage))
56+
}
57+
4358
body, err := io.ReadAll(resp.Body)
4459
if err != nil {
4560
return nil, err

pkg/ci/migrate/copy_test.go

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package migrate
33
import (
44
"os"
55
"path/filepath"
6+
"strings"
67
"testing"
78
)
89

@@ -124,7 +125,7 @@ func TestCopyMissingGitHub(t *testing.T) {
124125
}
125126
}
126127
// Check that ".github" is mentioned in error
127-
if errMsg := err.Error(); !contains(errMsg, ".github") {
128+
if errMsg := err.Error(); !strings.Contains(errMsg, ".github") {
128129
t.Errorf("error message should mention '.github', got: %s", errMsg)
129130
}
130131
}
@@ -247,7 +248,7 @@ func TestCopySkipSymlinks(t *testing.T) {
247248
// Verify warning mentions symlink
248249
hasSymlinkWarning := false
249250
for _, w := range result.Warnings {
250-
if contains(w, "symlink") {
251+
if strings.Contains(w, "symlink") {
251252
hasSymlinkWarning = true
252253
break
253254
}
@@ -323,7 +324,7 @@ func TestCopyMissingSubDir(t *testing.T) {
323324

324325
hasActionsWarning := false
325326
for _, w := range result.Warnings {
326-
if contains(w, "actions") {
327+
if strings.Contains(w, "actions") {
327328
hasActionsWarning = true
328329
break
329330
}
@@ -337,13 +338,3 @@ func TestCopyMissingSubDir(t *testing.T) {
337338
t.Errorf("workflows/ci.yml not found: %v", err)
338339
}
339340
}
340-
341-
// Helper function to check if string contains substring
342-
func contains(s, substr string) bool {
343-
for i := 0; i <= len(s)-len(substr); i++ {
344-
if s[i:i+len(substr)] == substr {
345-
return true
346-
}
347-
}
348-
return false
349-
}

0 commit comments

Comments
 (0)