Skip to content

Commit

Permalink
Added README.md and added GitHub commits operation client separately
Browse files Browse the repository at this point in the history
  • Loading branch information
shahariaazam committed Dec 7, 2023
1 parent bea1b8e commit ba20eb6
Show file tree
Hide file tree
Showing 2 changed files with 118 additions and 0 deletions.
101 changes: 101 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
# coco-gh

`coco-gh` is a Go library dedicated to collecting GitHub content.

## Features

- Fetch all file paths based on the configuration.
- Fetch a list of file paths that were changed in the last `X` hours.

## Getting Started

Download the library using `go get`:

```bash
go get github.com/shaharia-lab/coco-gh
```

Import the library in your code:

```go
import "github.com/shaharia-lab/coco-gh"
```

### Usage

```go
package cocogh

import (
"context"
"log"

"github.com/shurcooL/githubv4"
"golang.org/x/oauth2"
)

func main() {
src := oauth2.StaticTokenSource(
&oauth2.Token{AccessToken: os.Getenv("GITHUB_TOKEN")},
)
httpClient := oauth2.NewClient(context.Background(), src)

ghCommitsOpsClient := NewGitHubCommitsOpsClient(httpClient)
graphQLClient := githubv4.NewClient(httpClient)
ghConfig := GitHubConfig{
Owner: "kubernetes",
Repositories: []string{"website"},
DefaultBranch: "main",
Filter: GitHubFilter{
FilePath: "content/en/blog/_posts",
FileTypes: []string{
".md",
},
},
}

ch := NewGitHubClient(ghCommitsOpsClient, graphQLClient, ghConfig)

// Get all the file paths from the repositories
allFilePaths, err := ch.GetFilePathsForRepositories()
if err != nil {
// handle errors
}

for _, path := range allFilePaths {
log.Println(path)
}

// Get the list of files that were changed in the last X hours
contentChanged, err := ch.GetChangedFilePathsSince(24)
if err != nil {
// handle errors
}

log.Println(contentChanged.Added)
log.Println(contentChanged.Modified)
log.Println(contentChanged.Removed)
}
```

## Contributing

Contributions to [coco-gh](https://github.com/shaharia-lab/coco-gh) are more than welcome! If you're looking to contribute to our project, you're in the right place. Here are some ways you can help:

1. **Report Bugs**: If you find a bug, please open an issue to report it. Describe the bug, how to reproduce it, and the environment (e.g., OS, Go version).

2. **Suggest Enhancements**: Have an idea to make this project better? Open an issue to suggest your idea. Whether it's a new feature, code improvement, or documentation updates, we'd love to hear from you.

3. **Submit Pull Requests**: Feel free to fork the repository and submit pull requests. Before submitting your pull request, please ensure the following:
- Your code follows the project's coding standards.
- All tests are passing.
- Add or update tests as necessary for your code.
- Update the documentation to reflect your changes, if applicable.
- Include a clear description in your PR about the changes you have made.

4. **Review Pull Requests**: If you're interested in contributing by reviewing pull requests, please feel free to do so. Any feedback or suggestions are highly valuable.

We appreciate your contributions and look forward to your active participation in the development of [coco-gh](https://github.com/shaharia-lab/coco-gh)!

## License
[coco-gh](https://github.com/shaharia-lab/coco-gh) is licensed under the MIT License.
17 changes: 17 additions & 0 deletions github.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ package cocogh
import (
"context"
"fmt"
"net/http"
"strings"
"time"

Expand Down Expand Up @@ -51,6 +52,22 @@ type RESTClient interface {
GetCommit(ctx context.Context, owner, repo, sha string, opts *github.ListOptions) (*github.RepositoryCommit, *github.Response, error)
}

type GitHubCommitsOpsClient struct {

Check failure on line 55 in github.go

View workflow job for this annotation

GitHub Actions / lint

exported: exported type GitHubCommitsOpsClient should have comment or be unexported (revive)
GitHubClient *github.Client
}

func NewGitHubCommitsOpsClient(httpClient *http.Client) *GitHubCommitsOpsClient {

Check failure on line 59 in github.go

View workflow job for this annotation

GitHub Actions / lint

exported: exported function NewGitHubCommitsOpsClient should have comment or be unexported (revive)
gc := github.NewClient(httpClient)
return &GitHubCommitsOpsClient{GitHubClient: gc}
}

func (gClient *GitHubCommitsOpsClient) ListCommits(ctx context.Context, owner, repo string, opts *github.CommitsListOptions) ([]*github.RepositoryCommit, *github.Response, error) {

Check failure on line 64 in github.go

View workflow job for this annotation

GitHub Actions / lint

exported: exported method GitHubCommitsOpsClient.ListCommits should have comment or be unexported (revive)
return gClient.GitHubClient.Repositories.ListCommits(ctx, owner, repo, opts)
}
func (gClient *GitHubCommitsOpsClient) GetCommit(ctx context.Context, owner, repo, sha string, opts *github.ListOptions) (*github.RepositoryCommit, *github.Response, error) {

Check failure on line 67 in github.go

View workflow job for this annotation

GitHub Actions / lint

exported: exported method GitHubCommitsOpsClient.GetCommit should have comment or be unexported (revive)
return gClient.GitHubClient.Repositories.GetCommit(ctx, owner, repo, sha, opts)
}

// GHQueryForListFiles holds the structure of the query to fetch all files from a repository.
type GHQueryForListFiles struct {
Repository struct {
Expand Down

0 comments on commit ba20eb6

Please sign in to comment.