-
Notifications
You must be signed in to change notification settings - Fork 70
Expand file tree
/
Copy pathcodeowners_delete.go
More file actions
74 lines (64 loc) · 1.84 KB
/
Copy pathcodeowners_delete.go
File metadata and controls
74 lines (64 loc) · 1.84 KB
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
package main
import (
"context"
"strings"
"github.com/sourcegraph/sourcegraph/lib/errors"
"github.com/sourcegraph/src-cli/internal/api"
"github.com/sourcegraph/src-cli/internal/clicompat"
"github.com/sourcegraph/src-cli/internal/cmderrors"
"github.com/urfave/cli/v3"
)
const codeownersDeleteExamples = `
Delete a codeowners file for a repository.
Examples:
$ src codeowners delete -repo='github.com/sourcegraph/sourcegraph'
`
var codeownersDeleteCommand = clicompat.Wrap(&cli.Command{
Name: "delete",
Usage: "delete a codeowners file",
UsageText: "src codeowners delete [options]",
Description: codeownersDeleteExamples,
HideVersion: true,
Flags: clicompat.WithAPIFlags(
&cli.StringFlag{
Name: "repo",
Usage: "The repository to delete the data for",
Required: true,
Validator: requiresNotEmpty("provide a repo name using -repo"),
},
),
Action: func(ctx context.Context, cmd *cli.Command) error {
repoName := cmd.String("repo")
client := cfg.apiClient(clicompat.APIFlagsFromCmd(cmd), cmd.Writer)
query := `mutation DeleteCodeownersFile(
$repoName: String!,
) {
deleteCodeownersFiles(repositories: [{
repoName: $repoName,
}]) {
alwaysNil
}
}
`
var result struct {
DeleteCodeownersFile CodeownersIngestedFile
}
if ok, err := client.NewRequest(query, map[string]any{
"repoName": repoName,
}).Do(ctx, &result); err != nil || !ok {
var gqlErr api.GraphQlErrors
if errors.As(err, &gqlErr) {
for _, e := range gqlErr {
if strings.Contains(e.Error(), "repo not found:") {
return cmderrors.ExitCode(2, errors.Newf("repository %q not found", repoName))
}
if strings.Contains(e.Error(), "codeowners file not found:") {
return cmderrors.ExitCode(2, errors.Newf("no data found for repository %q", repoName))
}
}
}
return err
}
return nil
},
})