-
Notifications
You must be signed in to change notification settings - Fork 512
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
🐛 Add a workaround for organisations in GitLab #4415
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -84,7 +84,34 @@ func (handler *contributorsHandler) retrieveUsers(queryName string) ([]*gitlab.U | |
return users, nil | ||
} | ||
|
||
// Orginisation is an experimental feature in GitLab. Takes a slice | ||
// pointer to maintain list of domains and email returns an anonymised | ||
// string with the slice index as a unique identifier. | ||
// Pointer is required as we are modifying the slice length. | ||
func getOrginisation(orgDomain *[]string, orgReal string) string { | ||
// Some repositories date before email was widely used. | ||
emailSplit := strings.Split(orgReal, "@") | ||
var orgName string // Orginisation name | ||
if len(emailSplit) > 1 { | ||
orgName = emailSplit[1] | ||
} else { | ||
orgName = emailSplit[0] // Not an "email" | ||
} | ||
|
||
*orgDomain = append(*orgDomain, orgName) | ||
|
||
// Search for domain and use index as unique marker | ||
for i, domain := range *orgDomain { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Consider There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not sure how to leverage that to get what I need do you have an example? Thank you. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. better example: https://goplay.tools/snippet/0CXt57McB3Z |
||
if domain == orgName { | ||
return fmt.Sprint("GitLab-", i) | ||
} | ||
} | ||
return "GitLab" | ||
} | ||
|
||
func (handler *contributorsHandler) setup() error { | ||
var orgDomain []string // Slice of email domains | ||
|
||
handler.once.Do(func() { | ||
if !strings.EqualFold(handler.repourl.commitSHA, clients.HeadSHA) { | ||
handler.errSetup = fmt.Errorf("%w: ListContributors only supported for HEAD queries", | ||
|
@@ -126,9 +153,17 @@ func (handler *contributorsHandler) setup() error { | |
user = users[0] | ||
} | ||
|
||
// In case someone is using the experimental feature. | ||
var orgName string | ||
if user.Organization == "" { | ||
orgName = getOrginisation(&orgDomain, contrib.Email) | ||
} else { | ||
orgName = user.Organization | ||
} | ||
|
||
contributor := clients.User{ | ||
Login: contrib.Email, | ||
Companies: []string{user.Organization}, | ||
Companies: []string{orgName}, | ||
NumContributions: contrib.Commits, | ||
ID: int64(user.ID), | ||
IsBot: user.Bot, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be in
clients/gitlabrepo/commits.go
since we're dealing with commit email addresses.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I did not put that there since this should only be a temporary measure and this is specific to GitLab if you want me to move it after happy to do so.