Skip to content
This repository was archived by the owner on May 24, 2024. It is now read-only.

Commit 7acde97

Browse files
committed
Fix identity by username bug
Signed-off-by: Ikoh Obaro <obaro.ikohpgs@stu.cu.edu.ng>
1 parent af51353 commit 7acde97

2 files changed

Lines changed: 18 additions & 12 deletions

File tree

affiliation/dto.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,11 @@ type UniqueIdentityFullProfile struct {
7676
UUID string `json:"uuid,omitempty"`
7777
}
7878

79+
// ProfileByUsernameResponse ...
80+
type ProfileByUsernameResponse struct {
81+
Profile []*UniqueIdentityFullProfile `json:"profiles"`
82+
}
83+
7984
// Enrollments ...
8085
type Enrollments struct {
8186
Organization *Organization `json:"organization,omitempty"`

affiliation/identity.go

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -360,28 +360,33 @@ func (a *Affiliation) GetProfileByUsername(username string, projectSlug string)
360360
return nil, errors.New("user not found")
361361
}
362362

363-
var profile UniqueIdentityFullProfile
364-
err = json.Unmarshal(res, &profile)
363+
var response ProfileByUsernameResponse
364+
err = json.Unmarshal(res, &response)
365365
if err != nil {
366366
return nil, err
367367
}
368+
369+
profile := response.Profile[0]
368370
var identity AffIdentity
369371

370372
for _, value := range profile.Identities {
371373
if value.Source == "github" {
372374
profileIdentity := value
373375
identity.UUID = profileIdentity.UUID
374-
if profileIdentity.Name != nil {
375-
identity.Name = *profileIdentity.Name
376-
} else {
377-
identity.Name = unknown
378-
}
379-
380376
if profileIdentity.Email != nil {
381377
identity.Email = *profileIdentity.Email
382378
}
383379

384380
identity.ID = &profileIdentity.ID
381+
382+
if profile.Profile != nil {
383+
identity.IsBot = profile.Profile.IsBot
384+
identity.Name = *profile.Profile.Name
385+
} else if profileIdentity.Name != nil {
386+
identity.Name = *profileIdentity.Name
387+
} else {
388+
identity.Name = unknown
389+
}
385390
}
386391
}
387392

@@ -393,10 +398,6 @@ func (a *Affiliation) GetProfileByUsername(username string, projectSlug string)
393398

394399
identity.Username = username
395400

396-
if profile.Profile != nil {
397-
identity.IsBot = profile.Profile.IsBot
398-
}
399-
400401
if profile.Enrollments == nil {
401402
identity.OrgName = &unknown
402403
identity.MultiOrgNames = make([]string, 0)

0 commit comments

Comments
 (0)