From 58df82aca23237cb6c69f16dac2cb9a7310332cc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Darko=20Kri=C5=BEi=C4=87?= Date: Wed, 13 Mar 2024 14:52:28 +0100 Subject: [PATCH 1/2] Attaching mutliple repositories work --- userlist/collaborators.go | 25 +++++++++++++++++-------- userlist/userlist.go | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 53 insertions(+), 8 deletions(-) diff --git a/userlist/collaborators.go b/userlist/collaborators.go index e6033dc..1ed24ca 100644 --- a/userlist/collaborators.go +++ b/userlist/collaborators.go @@ -143,6 +143,8 @@ 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) @@ -150,16 +152,23 @@ func (c *UserListConfig) loadCollaborators() error { } 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) } } diff --git a/userlist/userlist.go b/userlist/userlist.go index 969c9ba..19984e4 100644 --- a/userlist/userlist.go +++ b/userlist/userlist.go @@ -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 +} From e6289c6e1293756ce416cb550233d48e56140c94 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Darko=20Kri=C5=BEi=C4=87?= Date: Wed, 13 Mar 2024 15:29:05 +0100 Subject: [PATCH 2/2] Fix template and prepare for v1.2 --- action.yaml | 2 +- template/collaborators.tpl | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/action.yaml b/action.yaml index 9686f03..3bf843b 100644 --- a/action.yaml +++ b/action.yaml @@ -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 }} diff --git a/template/collaborators.tpl b/template/collaborators.tpl index f141ca3..fd20cff 100644 --- a/template/collaborators.tpl +++ b/template/collaborators.tpl @@ -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)