MCPcopy Create free account
hub / github.com/google/go-github / main

Function main

example/actionpermissions/main.go:25–80  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

23)
24
25func main() {
26 flag.Parse()
27 token := os.Getenv("GITHUB_AUTH_TOKEN")
28 if token == "" {
29 log.Fatal("Unauthorized: No token present")
30 }
31 if *name == "" {
32 log.Fatal("No name: repo name must be given")
33 }
34 if *owner == "" {
35 log.Fatal("No owner: owner of repo must be given")
36 }
37 ctx := context.Background()
38 client, err := github.NewClient(github.WithAuthToken(token))
39 if err != nil {
40 log.Fatal(err)
41 }
42
43 actionsPermissionsRepository, _, err := client.Repositories.GetActionsPermissions(ctx, *owner, *name)
44 if err != nil {
45 log.Fatal(err)
46 }
47
48 fmt.Printf("Current ActionsPermissions %v\n", actionsPermissionsRepository)
49
50 actionsPermissionsRepository = &github.ActionsPermissionsRepository{Enabled: github.Ptr(true), AllowedActions: github.Ptr("selected")}
51 _, _, err = client.Repositories.UpdateActionsPermissions(ctx, *owner, *name, *actionsPermissionsRepository)
52 if err != nil {
53 log.Fatal(err)
54 }
55
56 fmt.Printf("Current ActionsPermissions %v\n", actionsPermissionsRepository)
57
58 actionsAllowed, _, err := client.Repositories.GetActionsAllowed(ctx, *owner, *name)
59 if err != nil {
60 log.Fatal(err)
61 }
62
63 fmt.Printf("Current ActionsAllowed %v\n", actionsAllowed)
64
65 actionsAllowed = &github.ActionsAllowed{GithubOwnedAllowed: github.Ptr(true), VerifiedAllowed: github.Ptr(false), PatternsAllowed: []string{"a/b"}}
66 _, _, err = client.Repositories.EditActionsAllowed(ctx, *owner, *name, *actionsAllowed)
67 if err != nil {
68 log.Fatal(err)
69 }
70
71 fmt.Printf("Current ActionsAllowed %v\n", actionsAllowed)
72
73 actionsPermissionsRepository = &github.ActionsPermissionsRepository{Enabled: github.Ptr(true), AllowedActions: github.Ptr("all")}
74 _, _, err = client.Repositories.UpdateActionsPermissions(ctx, *owner, *name, *actionsPermissionsRepository)
75 if err != nil {
76 log.Fatal(err)
77 }
78
79 fmt.Printf("Current ActionsPermissions %v\n", actionsPermissionsRepository)
80}

Callers

nothing calls this directly

Calls 7

NewClientFunction · 0.92
WithAuthTokenFunction · 0.92
PtrFunction · 0.92
EditActionsAllowedMethod · 0.80
GetActionsPermissionsMethod · 0.45
GetActionsAllowedMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…