Skip to content

Commit

Permalink
Add recentStars (#25)
Browse files Browse the repository at this point in the history
  • Loading branch information
wtait1 authored May 31, 2021
1 parent 106a6ba commit f735091
Show file tree
Hide file tree
Showing 6 changed files with 85 additions and 1 deletion.
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,17 @@ Repository URL: {{.Repo.URL}}
{{end}}
```

### Repositories you recently starred

```
{{range recentStars 10}}
Name: {{.Name}}
Description: {{.Description}}
URL: {{.URL}})
Stars: {{.Stargazers}}
{{end}}
```

This function requires GitHub authentication!

### Repositories you recently created
Expand Down
1 change: 1 addition & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ func main() {
"recentRepos": recentRepos,
"recentReleases": recentReleases,
"followers": recentFollowers,
"recentStars": recentStars,
"gists": gists,
"sponsors": sponsors,
/* RSS */
Expand Down
2 changes: 1 addition & 1 deletion repos.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ var recentContributionsQuery struct {

var recentPullRequestsQuery struct {
User struct {
Login githubv4.String
Login githubv4.String
PullRequests struct {
TotalCount githubv4.Int
Edges []struct {
Expand Down
62 changes: 62 additions & 0 deletions stars.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package main

import (
"context"

"github.com/shurcooL/githubv4"
)

var recentStarsQuery struct {
User struct {
Login githubv4.String
Stars struct {
TotalCount githubv4.Int
Edges []struct {
Cursor githubv4.String
StarredAt githubv4.DateTime
Node QLRepository
}
} `graphql:"starredRepositories(first: $count, orderBy: {field: STARRED_AT, direction: DESC})"`
} `graphql:"user(login:$username)"`
}

func recentStars(count int) []Star {
var starredRepos []Star
variables := map[string]interface{}{
"username": githubv4.String(username),
"count": githubv4.Int(count),
}
err := gitHubClient.Query(context.Background(), &recentStarsQuery, variables)
if err != nil {
panic(err)
}

for _, v := range recentStarsQuery.User.Stars.Edges {
starredRepos = append(starredRepos, Star{
StarredAt: v.StarredAt.Time,
Repo: RepoFromQL(v.Node),
})
}

return starredRepos
}

/*
{
viewer {
login
starredRepositories(first: 3, orderBy: {field: STARRED_AT, direction: DESC}) {
totalCount
edges {
cursor
starredAt
node {
nameWithOwner
url
description
}
}
}
}
}
*/
5 changes: 5 additions & 0 deletions templates/github-profile.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@
- [{{.Description}}]({{.URL}}) ({{humanize .CreatedAt}})
{{- end}}

#### ⭐ Recent Stars
{{range recentStars 10}}
- [{{.Repo.Name}}]({{.Repo.URL}}) - {{.Repo.Description}} ({{humanize .StarredAt}})
{{- end}}

#### ❤️ These awesome people sponsor me (thank you!)
{{range sponsors 5}}
- [{{.User.Login}}]({{.User.URL}}) ({{humanize .CreatedAt}})
Expand Down
5 changes: 5 additions & 0 deletions types.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ type Gist struct {
CreatedAt time.Time
}

type Star struct {
StarredAt time.Time
Repo Repo
}

type PullRequest struct {
Title string
URL string
Expand Down

0 comments on commit f735091

Please sign in to comment.