Skip to content
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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 36 additions & 1 deletion clients/gitlabrepo/contributors.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Copy link
Contributor

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.

Copy link
Author

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.

// 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 {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider slices.Index.

Copy link
Author

Choose a reason for hiding this comment

The 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.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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",
Expand Down Expand Up @@ -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,
Expand Down