Skip to content

Commit

Permalink
Merge pull request #16 from PRODYNA/feature/15-repositories-of-contri…
Browse files Browse the repository at this point in the history
…butors-are-only-listed-once

Attaching mutliple repositories work
  • Loading branch information
dkrizic authored Mar 13, 2024
2 parents 0730d90 + e6289c6 commit 6fca829
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 10 deletions.
2 changes: 1 addition & 1 deletion action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ inputs:
default: 1
runs:
using: 'docker'
image: 'docker://ghcr.io/prodyna/github-users:v1.1'
image: 'docker://ghcr.io/prodyna/github-users:v1.2'
env:
ACTION: ${{ inputs.action }}
ENTERPRISE: ${{ inputs.enterprise }}
Expand Down
1 change: 0 additions & 1 deletion template/collaborators.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,5 @@ Last updated: {{ .Updated }}
| ------ | ---- | ------------- | ------------ | ---------- |
{{ range $user := .Users }}{{ range $org := $user.Organizations }}{{ range $repo := $org.Repositories }}| {{ $user.Number }} | [{{ $user.Login }}](https://github.com/{{ $user.Login }}) | {{if $user.Contributions}}:green_square:{{else}}:red_square:{{end}} {{ $user.Contributions }} | [{{ $org.Name }}](https://github.com/{{ $org.Login }}) | [{{ $repo.Name }}](https://github.com/{{ $org.Login }}/{{ $repo.Name }}) |
{{ end }}{{ end }}{{ end }}

---
Generated with :heart: by [github-users](https://github.com/prodyna/github-users)
25 changes: 17 additions & 8 deletions userlist/collaborators.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,23 +143,32 @@ func (c *UserListConfig) loadCollaborators() error {
slog.DebugContext(ctx, "Processing repository", "repository", repo.Name, "collaborator.count", len(repo.Collaborators.Nodes))
for _, collaborator := range repo.Collaborators.Nodes {
slog.DebugContext(ctx, "Processing collaborator", "login", collaborator.Login, "name", collaborator.Name, "contributions", collaborator.ContributionsCollection.ContributionCalendar.TotalContributions)

// User
user := c.userList.findUser(collaborator.Login)
if user == nil {
user = c.userList.createUser(userNumber+1, collaborator.Login, collaborator.Name, "", collaborator.ContributionsCollection.ContributionCalendar.TotalContributions)
userNumber++
} else {
slog.Info("Found existing user", "login", user.Login)
}
organization := Organization{
Login: org.Login,
Name: org.Name,
Repositories: new([]Repository),

// Organization
organization := user.findOrganization(org.Login)
if organization == nil {
organization = user.createOrganization(org.Login, org.Name)
} else {
slog.Info("Found existing organization", "organization", organization.Name)
}
user.upsertOrganization(organization)
repository := Repository{
Name: repo.Name,

// Repository
repository := organization.findRepository(repo.Name)
if repository == nil {
repository = organization.createRepository(repo.Name)
} else {
slog.Info("Found existing repository", "repository", repository.Name)
}
organization.upsertRepository(repository)
organization.upsertRepository(*repository)
}
}

Expand Down
36 changes: 36 additions & 0 deletions userlist/userlist.go
Original file line number Diff line number Diff line change
Expand Up @@ -208,3 +208,39 @@ func (o *Organization) upsertRepository(repo Repository) {
slog.Debug("Upserting repository", "name", repo.Name, "organization", o.Name)
*o.Repositories = append(*o.Repositories, repo)
}

func (u *User) findOrganization(login string) *Organization {
for _, o := range *u.Organizations {
if o.Login == login {
return &o
}
}
return nil
}

func (u *User) createOrganization(login string, name string) *Organization {
org := &Organization{
Login: login,
Name: name,
Repositories: new([]Repository),
}
u.upsertOrganization(*org)
return org
}

func (o *Organization) findRepository(name string) *Repository {
for _, r := range *o.Repositories {
if r.Name == name {
return &r
}
}
return nil
}

func (o *Organization) createRepository(name string) *Repository {
repo := &Repository{
Name: name,
}
o.upsertRepository(*repo)
return repo
}

0 comments on commit 6fca829

Please sign in to comment.