Skip to content

Commit

Permalink
Add custom repositories function (#48)
Browse files Browse the repository at this point in the history
  • Loading branch information
aymanbagabas committed Nov 16, 2022
1 parent 1e6dbd4 commit b6f3325
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 1 deletion.
18 changes: 17 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,23 @@ Stars: {{.Stargazers}}
This function requires GitHub authentication with the following API scopes:
`repo:status`, `public_repo`, `read:user`.

### Custom GitHub repository

```
{{with repo "muesli" "markscribe"}}
Name: {{.Name}}
Description: {{.Description}}
URL: {{.URL}}
Stars: {{.Stargazers}}
Is Private: {{.IsPrivate}}
Last Git Tag: {{.LastRelease.TagName}}
Last Release: {{humanize .LastRelease.PublishedAt}}
{{end}}
```

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

### Forks you recently created

```
Expand Down Expand Up @@ -211,7 +228,6 @@ This function requires GoodReads API key!

This function requires GoodReads API key!


### Your Literal.club currently reading books

```
Expand Down
1 change: 1 addition & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ func main() {
"recentStars": recentStars,
"gists": gists,
"sponsors": sponsors,
"repo": repo,
/* RSS */
"rss": rssFeed,
/* GoodReads */
Expand Down
33 changes: 33 additions & 0 deletions repos.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,19 @@ var recentReleasesQuery struct {
} `graphql:"user(login:$username)"`
}

var repoQuery struct {
Repository struct {
Description githubv4.String
NameWithOwner githubv4.String
IsPrivate githubv4.Boolean
URL githubv4.String
Stargazers struct {
TotalCount githubv4.Int
}
Releases qlRelease `graphql:"releases(last: 1)"`
} `graphql:"repository(owner:$owner, name:$name)"`
}

func recentContributions(count int) []Contribution {
// fmt.Printf("Finding recent contributions...\n")

Expand Down Expand Up @@ -259,6 +272,26 @@ func recentReleases(count int) []Repo {
return repos
}

func repo(owner, name string) Repo {
variables := map[string]interface{}{
"owner": githubv4.String(owner),
"name": githubv4.String(name),
}
err := gitHubClient.Query(context.Background(), &repoQuery, variables)
if err != nil {
panic(err)
}
repo := repoQuery.Repository
return Repo{
Name: string(repo.NameWithOwner),
URL: string(repo.URL),
Description: string(repo.Description),
Stargazers: int(repo.Stargazers.TotalCount),
IsPrivate: bool(repo.IsPrivate),
LastRelease: releaseFromQL(repo.Releases),
}
}

/*
{
user(login: "muesli") {
Expand Down
2 changes: 2 additions & 0 deletions types.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ type Repo struct {
Name string
URL string
Description string
IsPrivate bool
Stargazers int
LastRelease Release
}
Expand Down Expand Up @@ -143,6 +144,7 @@ func repoFromQL(repo qlRepository) Repo {
URL: string(repo.URL),
Description: string(repo.Description),
Stargazers: int(repo.Stargazers.TotalCount),
IsPrivate: bool(repo.IsPrivate),
}
}

Expand Down

0 comments on commit b6f3325

Please sign in to comment.