-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
58 lines (51 loc) · 1.77 KB
/
main.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
package main
import (
"context"
config "github.com/prodyna/invite-to-org/config"
"github.com/prodyna/invite-to-org/organization"
"log/slog"
"os"
)
func main() {
c, err := config.New()
if err != nil {
slog.Error("Unable to create config", "error", err)
os.Exit(1)
}
ctx := context.Background()
slog.InfoContext(ctx, "Configuration",
"enterprise", c.Enterprise,
"sourceOrganization", c.SourceOrganization,
"targetOrganization", c.TargetOrganization,
"dryRun", c.DryRun,
"team", c.Team,
"githubToken", "***")
sourceOrganization := organization.New(organization.OrganizationConfig{
GithubToken: c.GithubToken,
DryRun: c.DryRun,
Organization: c.SourceOrganization,
Team: c.Team,
})
sourceMembers, err := sourceOrganization.Members(ctx)
if err != nil {
slog.ErrorContext(ctx, "Unable to load members", "error", err, "organization", c.SourceOrganization)
os.Exit(1)
}
slog.InfoContext(ctx, "Loaded members", "organization", c.SourceOrganization, "members", len(*sourceMembers))
targetOrganization := organization.New(organization.OrganizationConfig{
GithubToken: c.GithubToken,
DryRun: c.DryRun,
Organization: c.TargetOrganization,
Team: c.Team,
})
targetMembers, err := targetOrganization.Members(ctx)
if err != nil {
slog.ErrorContext(ctx, "Unable to load members", "error", err, "organization", c.TargetOrganization)
os.Exit(1)
}
slog.InfoContext(ctx, "Loaded members", "organization", c.TargetOrganization, "members", len(*targetMembers))
missingMembers := targetOrganization.MissingMembers(*sourceMembers)
slog.InfoContext(ctx, "Missing members", "members", len(missingMembers))
err = targetOrganization.Invite(ctx, c.Enterprise, &missingMembers)
slog.InfoContext(ctx, "Done", "membersAdded", len(missingMembers))
}