Skip to content

Commit

Permalink
Sort sponsors and wrap them in a Sponsor type
Browse files Browse the repository at this point in the history
  • Loading branch information
muesli committed Jul 23, 2020
1 parent 2b391a1 commit e683e18
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 13 deletions.
9 changes: 7 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ This function requires GitHub authentication!
```
{{range followers 5}}
Username: {{.Login}}
Name: {{.Name}}
Avatar: {{.AvatarURL}}
URL: {{.URL}}
{{end}}
```
Expand All @@ -92,8 +94,11 @@ This function requires GitHub authentication!

```
{{range sponsors 5}}
Username: {{.Login}}
URL: {{.URL}}
Username: {{.User.Login}}
Name: {{.User.Name}}
Avatar: {{.User.AvatarURL}}
URL: {{.User.URL}}
Created: {{humanize .CreatedAt}}
{{end}}
```

Expand Down
29 changes: 19 additions & 10 deletions sponsors.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,16 @@ package main

import (
"context"
"time"

"github.com/shurcooL/githubv4"
)

type Sponsor struct {
User User
CreatedAt time.Time
}

var sponsorsQuery struct {
User struct {
Login githubv4.String
Expand All @@ -25,14 +31,14 @@ var sponsorsQuery struct {
}
}
}
} `graphql:"sponsorshipsAsMaintainer(first: $count)"`
} `graphql:"sponsorshipsAsMaintainer(first: $count, orderBy: {field: CREATED_AT, direction: DESC})"`
} `graphql:"user(login:$username)"`
}

func sponsors(count int) []User {
func sponsors(count int) []Sponsor {
// fmt.Printf("Finding sponsors...\n")

var users []User
var sponsors []Sponsor
variables := map[string]interface{}{
"username": githubv4.String(username),
"count": githubv4.Int(count),
Expand All @@ -45,17 +51,20 @@ func sponsors(count int) []User {
// fmt.Printf("%+v\n", query)

for _, v := range sponsorsQuery.User.SponsorshipsAsMaintainer.Edges {
u := User{
Login: string(v.Node.SponsorEntity.SponsorUser.Login),
Name: string(v.Node.SponsorEntity.SponsorUser.Name),
AvatarURL: string(v.Node.SponsorEntity.SponsorUser.AvatarURL),
URL: string(v.Node.SponsorEntity.SponsorUser.URL),
s := Sponsor{
User: User{
Login: string(v.Node.SponsorEntity.SponsorUser.Login),
Name: string(v.Node.SponsorEntity.SponsorUser.Name),
AvatarURL: string(v.Node.SponsorEntity.SponsorUser.AvatarURL),
URL: string(v.Node.SponsorEntity.SponsorUser.URL),
},
CreatedAt: v.Node.CreatedAt.Time,
}
users = append(users, u)
sponsors = append(sponsors, s)
}

// fmt.Printf("Found %d sponsors!\n", len(users))
return users
return sponsors
}

/*
Expand Down
2 changes: 1 addition & 1 deletion templates/github-profile.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

#### ❤️ These awesome people sponsor me (thank you!)
{{range sponsors 5}}
- [{{.Login}}]({{.URL}})
- [{{.User.Login}}]({{.User.URL}}) ({{humanize .CreatedAt}})
{{- end}}

#### 👯 Check out some of my recent followers
Expand Down

0 comments on commit e683e18

Please sign in to comment.