-
Notifications
You must be signed in to change notification settings - Fork 173
/
github.go
648 lines (558 loc) · 19.9 KB
/
github.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
package github
import (
"archive/tar"
"archive/zip"
"compress/gzip"
"context"
"encoding/json"
"errors"
"fmt"
"io"
"log"
"net/http"
"os"
"path/filepath"
"regexp"
"runtime"
"strings"
"github.com/Azure/azure-sdk-for-go/sdk/azcore/policy"
"github.com/azure/azure-dev/cli/azd/internal/tracing"
"github.com/azure/azure-dev/cli/azd/internal/tracing/events"
"github.com/azure/azure-dev/cli/azd/pkg/config"
"github.com/azure/azure-dev/cli/azd/pkg/exec"
"github.com/azure/azure-dev/cli/azd/pkg/input"
"github.com/azure/azure-dev/cli/azd/pkg/osutil"
"github.com/azure/azure-dev/cli/azd/pkg/tools"
"github.com/blang/semver/v4"
)
type GitHubCli interface {
tools.ExternalTool
GetAuthStatus(ctx context.Context, hostname string) (AuthStatus, error)
ListSecrets(ctx context.Context, repo string) ([]string, error)
ListVariables(ctx context.Context, repo string) ([]string, error)
SetSecret(ctx context.Context, repo string, name string, value string) error
DeleteSecret(ctx context.Context, repo string, name string) error
SetVariable(ctx context.Context, repoSlug string, name string, value string) error
DeleteVariable(ctx context.Context, repoSlug string, name string) error
Login(ctx context.Context, hostname string) error
ListRepositories(ctx context.Context) ([]GhCliRepository, error)
ViewRepository(ctx context.Context, name string) (GhCliRepository, error)
CreatePrivateRepository(ctx context.Context, name string) error
GetGitProtocolType(ctx context.Context) (string, error)
GitHubActionsExists(ctx context.Context, repoSlug string) (bool, error)
BinaryPath() string
}
func NewGitHubCli(ctx context.Context, console input.Console, commandRunner exec.CommandRunner) (GitHubCli, error) {
return newGitHubCliImplementation(ctx, console, commandRunner, http.DefaultClient, downloadGh, extractGhCli)
}
// GitHubCliVersion is the minimum version of GitHub cli that we require (and the one we fetch when we fetch bicep on
// behalf of a user).
var GitHubCliVersion semver.Version = semver.MustParse("2.28.0")
// newGitHubCliImplementation is like NewGitHubCli but allows providing a custom transport to use when downloading the
// GitHub CLI, for testing purposes.
func newGitHubCliImplementation(
ctx context.Context,
console input.Console,
commandRunner exec.CommandRunner,
transporter policy.Transporter,
acquireGitHubCliImpl getGitHubCliImplementation,
extractImplementation extractGitHubCliFromFileImplementation,
) (GitHubCli, error) {
if override := os.Getenv("AZD_GH_CLI_TOOL_PATH"); override != "" {
log.Printf("using external github cli tool: %s", override)
cli := &ghCli{
path: override,
commandRunner: commandRunner,
}
cli.logVersion(ctx)
return cli, nil
}
githubCliPath, err := azdGithubCliPath()
if err != nil {
return nil, fmt.Errorf("getting github cli default path: %w", err)
}
if _, err = os.Stat(githubCliPath); err != nil && !errors.Is(err, os.ErrNotExist) {
return nil, fmt.Errorf("getting file information from github cli default path: %w", err)
}
var installGhCli bool
if errors.Is(err, os.ErrNotExist) || !expectedVersionInstalled(ctx, commandRunner, githubCliPath) {
installGhCli = true
}
if installGhCli {
if err := os.MkdirAll(filepath.Dir(githubCliPath), osutil.PermissionDirectory); err != nil {
return nil, fmt.Errorf("creating github cli default path: %w", err)
}
msg := "setting up github connection"
console.ShowSpinner(ctx, msg, input.Step)
err = acquireGitHubCliImpl(ctx, transporter, GitHubCliVersion, extractImplementation, githubCliPath)
console.StopSpinner(ctx, "", input.Step)
if err != nil {
return nil, fmt.Errorf("setting up github connection: %w", err)
}
}
cli := &ghCli{
path: githubCliPath,
commandRunner: commandRunner,
}
cli.logVersion(ctx)
return cli, nil
}
// azdGithubCliPath returns the path where we store our local copy of github cli ($AZD_CONFIG_DIR/bin).
func azdGithubCliPath() (string, error) {
configDir, err := config.GetUserConfigDir()
if err != nil {
return "", err
}
return filepath.Join(configDir, "bin", ghCliName()), nil
}
func ghCliName() string {
if runtime.GOOS == "windows" {
return "gh.exe"
}
return "gh"
}
var (
ErrGitHubCliNotLoggedIn = errors.New("gh cli is not logged in")
ErrUserNotAuthorized = errors.New("user is not authorized. " +
"Try running gh auth refresh with the required scopes to request additional authorization")
ErrRepositoryNameInUse = errors.New("repository name already in use")
// The hostname of the public GitHub service.
GitHubHostName = "github.com"
// Environment variable that gh cli uses for auth token overrides
TokenEnvVars = []string{"GITHUB_TOKEN", "GH_TOKEN"}
)
type ghCli struct {
commandRunner exec.CommandRunner
path string
}
func (cli *ghCli) CheckInstalled(ctx context.Context) error {
return nil
}
func expectedVersionInstalled(ctx context.Context, commandRunner exec.CommandRunner, binaryPath string) bool {
ghVersion, err := tools.ExecuteCommand(ctx, commandRunner, binaryPath, "--version")
if err != nil {
log.Printf("checking %s version: %s", cGhToolName, err.Error())
return false
}
ghSemver, err := tools.ExtractVersion(ghVersion)
if err != nil {
log.Printf("converting to semver version fails: %s", err.Error())
return false
}
if ghSemver.LT(GitHubCliVersion) {
log.Printf("Found gh cli version %s. Expected version: %s.", ghSemver.String(), GitHubCliVersion.String())
return false
}
return true
}
const cGhToolName = "GitHub CLI"
func (cli *ghCli) Name() string {
return cGhToolName
}
func (cli *ghCli) BinaryPath() string {
return cli.path
}
func (cli *ghCli) InstallUrl() string {
return "https://aka.ms/azure-dev/github-cli-install"
}
// The result from calling GetAuthStatus
type AuthStatus struct {
LoggedIn bool
}
func (cli *ghCli) GetAuthStatus(ctx context.Context, hostname string) (AuthStatus, error) {
runArgs := cli.newRunArgs("auth", "status", "--hostname", hostname)
res, err := cli.commandRunner.Run(ctx, runArgs)
if err == nil {
authResult := AuthStatus{LoggedIn: true}
return authResult, nil
}
if isGhCliNotLoggedInMessageRegex.MatchString(res.Stderr) {
return AuthStatus{}, nil
} else if notLoggedIntoAnyGitHubHostsMessageRegex.MatchString(res.Stderr) {
return AuthStatus{}, nil
}
return AuthStatus{}, fmt.Errorf("failed running gh auth status: %w", err)
}
func (cli *ghCli) Login(ctx context.Context, hostname string) error {
runArgs := cli.newRunArgs("auth", "login", "--hostname", hostname, "--scopes", "repo,workflow").
WithInteractive(true)
_, err := cli.commandRunner.Run(ctx, runArgs)
if err != nil {
return fmt.Errorf("failed running gh auth login: %w", err)
}
return nil
}
func ghOutputToList(output string) []string {
lines := strings.Split(output, "\n")
result := make([]string, len(lines)-1)
for i, line := range lines {
if line == "" {
continue
}
valueParts := strings.Split(line, "\t")
result[i] = valueParts[0]
}
return result
}
func (cli *ghCli) ListSecrets(ctx context.Context, repoSlug string) ([]string, error) {
runArgs := cli.newRunArgs("-R", repoSlug, "secret", "list")
output, err := cli.run(ctx, runArgs)
if err != nil {
return nil, fmt.Errorf("failed running gh secret list: %w", err)
}
return ghOutputToList(output.Stdout), nil
}
func (cli *ghCli) ListVariables(ctx context.Context, repoSlug string) ([]string, error) {
runArgs := cli.newRunArgs("-R", repoSlug, "variable", "list")
output, err := cli.run(ctx, runArgs)
if err != nil {
return nil, fmt.Errorf("failed running gh secret list: %w", err)
}
return ghOutputToList(output.Stdout), nil
}
func (cli *ghCli) SetSecret(ctx context.Context, repoSlug string, name string, value string) error {
runArgs := cli.newRunArgs("-R", repoSlug, "secret", "set", name).WithStdIn(strings.NewReader(value))
_, err := cli.run(ctx, runArgs)
if err != nil {
return fmt.Errorf("failed running gh secret set: %w", err)
}
return nil
}
func (cli *ghCli) SetVariable(ctx context.Context, repoSlug string, name string, value string) error {
runArgs := cli.newRunArgs("-R", repoSlug, "variable", "set", name).WithStdIn(strings.NewReader(value))
_, err := cli.run(ctx, runArgs)
if err != nil {
return fmt.Errorf("failed running gh variable set: %w", err)
}
return nil
}
func (cli *ghCli) DeleteSecret(ctx context.Context, repoSlug string, name string) error {
runArgs := cli.newRunArgs("-R", repoSlug, "secret", "delete", name)
_, err := cli.run(ctx, runArgs)
if err != nil {
return fmt.Errorf("failed running gh secret delete: %w", err)
}
return nil
}
func (cli *ghCli) DeleteVariable(ctx context.Context, repoSlug string, name string) error {
runArgs := cli.newRunArgs("-R", repoSlug, "variable", "delete", name)
_, err := cli.run(ctx, runArgs)
if err != nil {
return fmt.Errorf("failed running gh variable delete: %w", err)
}
return nil
}
// cGhCliVersionRegexp fetches the version number from the output of gh --version, which looks like this:
//
// gh version 2.6.0 (2022-03-15)
// https://github.com/cli/cli/releases/tag/v2.6.0
var cGhCliVersionRegexp = regexp.MustCompile(`gh version ([0-9]+\.[0-9]+\.[0-9]+)`)
// logVersion writes the version of the GitHub CLI to the debug log for diagnostics purposes, or an error if
// it could not be determined
func (cli *ghCli) logVersion(ctx context.Context) {
if ver, err := cli.extractVersion(ctx); err == nil {
log.Printf("github cli version: %s", ver)
} else {
log.Printf("could not determine github cli version: %s", err)
}
}
// extractVersion gets the version of the GitHub CLI, from the output of `gh --version`
func (cli *ghCli) extractVersion(ctx context.Context) (string, error) {
runArgs := cli.newRunArgs("--version")
res, err := cli.run(ctx, runArgs)
if err != nil {
return "", fmt.Errorf("error running gh --version: %w", err)
}
matches := cGhCliVersionRegexp.FindStringSubmatch(res.Stdout)
if len(matches) != 2 {
return "", fmt.Errorf("could not extract version from output: %s", res.Stdout)
}
return matches[1], nil
}
type GhCliRepository struct {
// The slug for a repository (formatted as "<owner>/<name>")
NameWithOwner string
// The Url for the HTTPS endpoint for the repository
HttpsUrl string `json:"url"`
// The Url for the SSH endpoint for the repository
SshUrl string
}
func (cli *ghCli) ListRepositories(ctx context.Context) ([]GhCliRepository, error) {
runArgs := cli.newRunArgs("repo", "list", "--no-archived", "--json", "nameWithOwner,url,sshUrl")
res, err := cli.run(ctx, runArgs)
if err != nil {
return nil, fmt.Errorf("failed running gh repo list: %w", err)
}
var repos []GhCliRepository
if err := json.Unmarshal([]byte(res.Stdout), &repos); err != nil {
return nil, fmt.Errorf("could not unmarshal output as a []GhCliRepository: %w, output: %s", err, res.Stdout)
}
return repos, nil
}
func (cli *ghCli) ViewRepository(ctx context.Context, name string) (GhCliRepository, error) {
runArgs := cli.newRunArgs("repo", "view", name, "--json", "nameWithOwner,url,sshUrl")
res, err := cli.run(ctx, runArgs)
if err != nil {
return GhCliRepository{}, fmt.Errorf("failed running gh repo list: %w", err)
}
var repo GhCliRepository
if err := json.Unmarshal([]byte(res.Stdout), &repo); err != nil {
return GhCliRepository{},
fmt.Errorf("could not unmarshal output as a GhCliRepository: %w, output: %s", err, res.Stdout)
}
return repo, nil
}
func (cli *ghCli) CreatePrivateRepository(ctx context.Context, name string) error {
runArgs := cli.newRunArgs("repo", "create", name, "--private")
res, err := cli.run(ctx, runArgs)
if repositoryNameInUseRegex.MatchString(res.Stderr) {
return ErrRepositoryNameInUse
} else if err != nil {
return fmt.Errorf("failed running gh repo create: %w", err)
}
return nil
}
const (
GitSshProtocolType = "ssh"
GitHttpsProtocolType = "https"
)
func (cli *ghCli) GetGitProtocolType(ctx context.Context) (string, error) {
runArgs := cli.newRunArgs("config", "get", "git_protocol")
res, err := cli.run(ctx, runArgs)
if err != nil {
return "", fmt.Errorf("failed running gh config get git_protocol: %w", err)
}
return strings.TrimSpace(res.Stdout), nil
}
type GitHubActionsResponse struct {
TotalCount int `json:"total_count"`
}
// GitHubActionsExists gets the information from upstream about the workflows and
// return true if there is at least one workflow in the repo.
func (cli *ghCli) GitHubActionsExists(ctx context.Context, repoSlug string) (bool, error) {
runArgs := cli.newRunArgs("api", "/repos/"+repoSlug+"/actions/workflows")
res, err := cli.run(ctx, runArgs)
if err != nil {
return false, fmt.Errorf("getting github actions: %w", err)
}
var jsonResponse GitHubActionsResponse
if err := json.Unmarshal([]byte(res.Stdout), &jsonResponse); err != nil {
return false, fmt.Errorf("could not unmarshal output as a GhActionsResponse: %w, output: %s", err, res.Stdout)
}
if jsonResponse.TotalCount == 0 {
return false, nil
}
return true, nil
}
func (cli *ghCli) newRunArgs(args ...string) exec.RunArgs {
runArgs := exec.NewRunArgs(cli.path, args...)
if RunningOnCodespaces() {
runArgs = runArgs.WithEnv([]string{"GITHUB_TOKEN=", "GH_TOKEN="})
}
return runArgs
}
func (cli *ghCli) run(ctx context.Context, runArgs exec.RunArgs) (exec.RunResult, error) {
res, err := cli.commandRunner.Run(ctx, runArgs)
if isGhCliNotLoggedInMessageRegex.MatchString(res.Stderr) {
return res, ErrGitHubCliNotLoggedIn
}
if isUserNotAuthorizedMessageRegex.MatchString(res.Stderr) {
return res, ErrUserNotAuthorized
}
return res, err
}
//nolint:lll
var isGhCliNotLoggedInMessageRegex = regexp.MustCompile(
"(To authenticate, please run `gh auth login`\\.)|(Try authenticating with: gh auth login)|(To re-authenticate, run: gh auth login)|(To get started with GitHub CLI, please run: gh auth login)",
)
var repositoryNameInUseRegex = regexp.MustCompile(`GraphQL: Name already exists on this account \(createRepository\)`)
var notLoggedIntoAnyGitHubHostsMessageRegex = regexp.MustCompile(
"You are not logged into any GitHub hosts. Run gh auth login to authenticate.",
)
var isUserNotAuthorizedMessageRegex = regexp.MustCompile(
"HTTP 403: Resource not accessible by integration",
)
func extractFromZip(src, dst string) (string, error) {
zipReader, err := zip.OpenReader(src)
if err != nil {
return "", err
}
log.Printf("extract from zip %s", src)
defer zipReader.Close()
var extractedAt string
for _, file := range zipReader.File {
fileName := file.FileInfo().Name()
if !file.FileInfo().IsDir() && fileName == ghCliName() {
log.Printf("found cli at: %s", file.Name)
fileReader, err := file.Open()
if err != nil {
return extractedAt, err
}
filePath := filepath.Join(dst, fileName)
ghCliFile, err := os.OpenFile(filePath, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, file.Mode())
if err != nil {
return extractedAt, err
}
defer ghCliFile.Close()
/* #nosec G110 - decompression bomb false positive */
_, err = io.Copy(ghCliFile, fileReader)
if err != nil {
return extractedAt, err
}
extractedAt = filePath
break
}
}
if extractedAt != "" {
log.Printf("extracted to: %s", extractedAt)
return extractedAt, nil
}
return extractedAt, fmt.Errorf("github cli binary was not found within the zip file")
}
func extractFromTar(src, dst string) (string, error) {
gzFile, err := os.Open(src)
if err != nil {
return "", err
}
defer gzFile.Close()
gzReader, err := gzip.NewReader(gzFile)
if err != nil {
return "", err
}
defer gzReader.Close()
var extractedAt string
// tarReader doesn't need to be closed as it is closed by the gz reader
tarReader := tar.NewReader(gzReader)
for {
fileHeader, err := tarReader.Next()
if errors.Is(err, io.EOF) {
return extractedAt, fmt.Errorf("did not find gh cli within tar file")
}
if fileHeader == nil {
continue
}
if err != nil {
return extractedAt, err
}
// Tha name contains the path, remove it
fileNameParts := strings.Split(fileHeader.Name, "/")
fileName := fileNameParts[len(fileNameParts)-1]
// cspell: disable-next-line `Typeflag` is comming fron *tar.Header
if fileHeader.Typeflag == tar.TypeReg && fileName == "gh" {
filePath := filepath.Join(dst, fileName)
ghCliFile, err := os.OpenFile(filePath, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, os.FileMode(fileHeader.Mode))
if err != nil {
return extractedAt, err
}
defer ghCliFile.Close()
/* #nosec G110 - decompression bomb false positive */
_, err = io.Copy(ghCliFile, tarReader)
if err != nil {
return extractedAt, err
}
extractedAt = filePath
break
}
}
if extractedAt != "" {
return extractedAt, nil
}
return extractedAt, fmt.Errorf("extract from tar error. Extraction ended in unexpected state.")
}
// extractGhCli gets the Github cli from either a zip or a tar.gz
func extractGhCli(src, dst string) (string, error) {
if strings.HasSuffix(src, ".zip") {
return extractFromZip(src, dst)
} else if strings.HasSuffix(src, ".tar.gz") {
return extractFromTar(src, dst)
}
return "", fmt.Errorf("Unknown format while trying to extract")
}
// getGitHubCliImplementation defines the contract function to acquire the GitHub cli.
// The `outputPath` is the destination where the github cli is place it.
type getGitHubCliImplementation func(
ctx context.Context,
transporter policy.Transporter,
ghVersion semver.Version,
extractImplementation extractGitHubCliFromFileImplementation,
outputPath string) error
// extractGitHubCliFromFileImplementation defines how the cli is extracted
type extractGitHubCliFromFileImplementation func(src, dst string) (string, error)
// downloadGh downloads a given version of GitHub cli from the release site.
func downloadGh(
ctx context.Context,
transporter policy.Transporter,
ghVersion semver.Version,
extractImplementation extractGitHubCliFromFileImplementation,
path string) error {
binaryName := func(platform string) string {
return fmt.Sprintf("gh_%s_%s", ghVersion, platform)
}
systemArch := runtime.GOARCH
// arm and x86 not supported (similar to bicep)
var releaseName string
switch runtime.GOOS {
case "windows":
releaseName = binaryName(fmt.Sprintf("windows_%s.zip", systemArch))
case "darwin":
releaseName = binaryName(fmt.Sprintf("macOS_%s.zip", systemArch))
case "linux":
releaseName = binaryName(fmt.Sprintf("linux_%s.tar.gz", systemArch))
default:
return fmt.Errorf("unsupported platform")
}
// example: https://github.com/cli/cli/releases/download/v2.28.0/gh_2.28.0_linux_arm64.rpm
ghReleaseUrl := fmt.Sprintf("https://github.com/cli/cli/releases/download/v%s/%s", ghVersion, releaseName)
log.Printf("downloading github cli release %s -> %s", ghReleaseUrl, releaseName)
spanCtx, span := tracing.Start(ctx, events.GitHubCliInstallEvent)
defer span.End()
req, err := http.NewRequestWithContext(spanCtx, "GET", ghReleaseUrl, nil)
if err != nil {
return err
}
resp, err := transporter.Do(req)
if err != nil {
return err
}
defer resp.Body.Close()
if resp.StatusCode != http.StatusOK {
return fmt.Errorf("http error %d", resp.StatusCode)
}
tmpPath := filepath.Dir(path)
compressedRelease, err := os.CreateTemp(tmpPath, releaseName)
if err != nil {
return err
}
defer func() {
_ = compressedRelease.Close()
_ = os.Remove(compressedRelease.Name())
}()
if _, err := io.Copy(compressedRelease, resp.Body); err != nil {
return err
}
if err := compressedRelease.Close(); err != nil {
return err
}
// change file name from temporal name to the final name, as the download has completed
compressedFileName := filepath.Join(tmpPath, releaseName)
if err := osutil.Rename(ctx, compressedRelease.Name(), compressedFileName); err != nil {
return err
}
defer func() {
log.Printf("delete %s", compressedFileName)
_ = os.Remove(compressedFileName)
}()
// unzip downloaded file
log.Printf("extracting file %s", compressedFileName)
_, err = extractImplementation(compressedFileName, tmpPath)
if err != nil {
return err
}
return nil
}
// RunningOnCodespaces check if the application is running on codespaces.
func RunningOnCodespaces() bool {
return os.Getenv("CODESPACES") == "true"
}