Skip to content

Commit effb989

Browse files
committed
now
1 parent b7b1f60 commit effb989

File tree

2 files changed

+18
-39
lines changed

2 files changed

+18
-39
lines changed

pkg/connector/connector.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,14 @@ var (
5656
},
5757
Annotations: v1AnnotationsForResourceType("user"),
5858
}
59+
resourceTypeInvitation = &v2.ResourceType{
60+
Id: "invitation",
61+
DisplayName: "Invitation",
62+
Traits: []v2.ResourceType_Trait{
63+
v2.ResourceType_TRAIT_USER,
64+
},
65+
Annotations: v1AnnotationsForResourceType("invitation"),
66+
}
5967
resourceTypeApiToken = &v2.ResourceType{
6068
Id: "api-key",
6169
DisplayName: "API Key",
@@ -104,6 +112,7 @@ func (gh *GitHub) Metadata(ctx context.Context) (*v2.ConnectorMetadata, error) {
104112
FieldMap: map[string]*v2.ConnectorAccountCreationSchema_Field{
105113
"email": {
106114
DisplayName: "Email",
115+
Required: true,
107116
Description: "This email will be used as the login for the user.",
108117
Field: &v2.ConnectorAccountCreationSchema_Field_StringField{
109118
StringField: &v2.ConnectorAccountCreationSchema_StringField{},
@@ -121,15 +130,6 @@ func (gh *GitHub) Metadata(ctx context.Context) (*v2.ConnectorMetadata, error) {
121130
Placeholder: "organization name",
122131
Order: 2,
123132
},
124-
"userID": {
125-
DisplayName: "github user ID",
126-
Description: "Github User ID",
127-
Field: &v2.ConnectorAccountCreationSchema_Field_StringField{
128-
StringField: &v2.ConnectorAccountCreationSchema_StringField{},
129-
},
130-
Placeholder: "UserID",
131-
Order: 3,
132-
},
133133
},
134134
},
135135
}, nil

pkg/connector/user.go

Lines changed: 9 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ func invitationToUserResource(invitation *github.Invitation) (*v2.Resource, erro
2828

2929
ret, err := resource.NewUserResource(
3030
login,
31-
resourceTypeUser,
31+
resourceTypeInvitation,
3232
invitation.GetID(),
3333
[]resource.UserTraitOption{
3434
resource.WithEmail(invitation.GetEmail(), true),
@@ -263,8 +263,7 @@ func (o *userResourceType) CreateAccount(
263263
}
264264

265265
invitation, resp, err := o.client.Organizations.CreateOrgInvitation(ctx, params.org, &github.CreateOrgInvitationOptions{
266-
InviteeID: params.userID,
267-
Email: params.email,
266+
Email: params.email,
268267
})
269268
if err != nil {
270269
return nil, nil, nil, fmt.Errorf("github-connectorv2: failed to invite user to org: %w", err)
@@ -288,45 +287,25 @@ func (o *userResourceType) CreateAccount(
288287
}
289288

290289
type createUserParams struct {
291-
org string
292-
email *string
293-
userID *int64
290+
org string
291+
email *string
294292
}
295293

296294
func getCreateUserParams(accountInfo *v2.AccountInfo) (*createUserParams, error) {
297-
var (
298-
pMap = accountInfo.Profile.AsMap()
299-
uID *int64
300-
email *string
301-
)
302-
295+
pMap := accountInfo.Profile.AsMap()
303296
org, ok := pMap["org"].(string)
304297
if !ok || org == "" {
305298
return nil, fmt.Errorf("org is required")
306299
}
307300

308301
e, emailExisted := pMap["email"].(string)
309-
if e != "" {
310-
email = &e
311-
}
312-
313-
userID, userIDExisted := pMap["userID"].(string)
314-
if !emailExisted && !userIDExisted {
315-
return nil, fmt.Errorf("either email or userID should be provided")
316-
}
317-
318-
if userIDExisted {
319-
i, err := strconv.ParseInt(userID, 10, 64)
320-
if err != nil {
321-
return nil, err
322-
}
323-
uID = &i
302+
if !emailExisted || e == "" {
303+
return nil, fmt.Errorf("email is required")
324304
}
325305

326306
return &createUserParams{
327-
org: org,
328-
email: email,
329-
userID: uID,
307+
org: org,
308+
email: &e,
330309
}, nil
331310
}
332311

0 commit comments

Comments
 (0)