This repository has been archived by the owner on May 24, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9 from PRODYNA/8-actually-delete-persons
8 actually delete persons
- Loading branch information
Showing
7 changed files
with
67 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
FROM golang:1.22.2-alpine3.19 as build | ||
FROM golang:1.22.3-alpine3.19 as build | ||
|
||
WORKDIR /app | ||
COPY . . | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package github | ||
|
||
import ( | ||
"context" | ||
"github.com/shurcooL/githubv4" | ||
"golang.org/x/oauth2" | ||
"log/slog" | ||
) | ||
|
||
func (g GitHub) DeleteUser(ctx context.Context, login string) error { | ||
slog.Info("Deleting user", "login", login, "enterprise", g.config.Enterprise) | ||
|
||
var mutation struct { | ||
RemoveEnterpriseMember struct { | ||
Input struct { | ||
ClientMutationId string | ||
EnterpriseId string | ||
userId string | ||
} | ||
} `graphql:"removeEnterpriseMember(input: $input)"` | ||
} | ||
|
||
input := map[string]interface{}{ | ||
"input": map[string]interface{}{ | ||
"clientMutationId": "delete-user", | ||
"enterpriseId": g.config.Enterprise, | ||
"userId": login, | ||
}, | ||
} | ||
|
||
src := oauth2.StaticTokenSource( | ||
&oauth2.Token{AccessToken: g.config.Token}, | ||
) | ||
httpClient := oauth2.NewClient(ctx, src) | ||
client := githubv4.NewClient(httpClient) | ||
|
||
err := client.Mutate(ctx, &mutation, input, nil) | ||
if err != nil { | ||
slog.Warn("Unable to delete user", "login", login, "enterprise", g.config.Enterprise, "error", err) | ||
return err | ||
} | ||
slog.Info("User deleted", "login", login, "enterprise", g.config.Enterprise) | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters