Skip to content

Commit

Permalink
add recentForks for github
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexCuse committed May 16, 2022
1 parent a2db594 commit 9b82389
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 1 deletion.
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,20 @@ Stars: {{.Stargazers}}
This function requires GitHub authentication with the following API scopes:
`repo:status`, `public_repo`, `read:user`.

### Forks you recently created

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

This function requires GitHub authentication with the following API scopes:
`repo:status`, `public_repo`, `read:user`.

### Recent releases you contributed to

```
Expand Down
33 changes: 32 additions & 1 deletion repos.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ var recentReposQuery struct {
Cursor githubv4.String
Node QLRepository
}
} `graphql:"repositories(first: $count, privacy: PUBLIC, isFork: false, ownerAffiliations: OWNER, orderBy: {field: CREATED_AT, direction: DESC})"`
} `graphql:"repositories(first: $count, privacy: PUBLIC, isFork: $isFork, ownerAffiliations: OWNER, orderBy: {field: CREATED_AT, direction: DESC})"`
} `graphql:"user(login:$username)"`
}

Expand Down Expand Up @@ -148,6 +148,37 @@ func recentRepos(count int) []Repo {
variables := map[string]interface{}{
"username": githubv4.String(username),
"count": githubv4.Int(count + 1), // +1 in case we encounter the meta-repo itself
"isFork": githubv4.Boolean(false),
}
err := gitHubClient.Query(context.Background(), &recentReposQuery, variables)
if err != nil {
panic(err)
}

for _, v := range recentReposQuery.User.Repositories.Edges {
// ignore meta-repo
if string(v.Node.NameWithOwner) == fmt.Sprintf("%s/%s", username, username) {
continue
}

repos = append(repos, RepoFromQL(v.Node))
if len(repos) == count {
break
}
}

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

func recentForks(count int) []Repo {
// fmt.Printf("Finding recently created repos...\n")

var repos []Repo
variables := map[string]interface{}{
"username": githubv4.String(username),
"count": githubv4.Int(count + 1), // +1 in case we encounter the meta-repo itself
"isFork": githubv4.Boolean(true),
}
err := gitHubClient.Query(context.Background(), &recentReposQuery, variables)
if err != nil {
Expand Down
5 changes: 5 additions & 0 deletions templates/github-profile.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@
- [{{.Repo.Name}}]({{.Repo.URL}}) - {{.Repo.Description}} ({{humanize .OccurredAt}})
{{- end}}

#### 馃嵈 My recent forks
{{range recentForks 10}}
- [{{.Repo.Name}}]({{.Repo.URL}}) - {{.Repo.Description}} ({{humanize .OccurredAt}})
{{- end}}

#### 馃尡 My latest projects
{{range recentRepos 10}}
- [{{.Name}}]({{.URL}}) - {{.Description}}
Expand Down

0 comments on commit 9b82389

Please sign in to comment.