Documentation
¶
Overview ¶
Package cocogh to collect GitHub contents
Index ¶
- type CommitOpsClient
- type GHQueryForListFiles
- type GitHub
- type GitHubCommitsOpsClient
- func (gClient *GitHubCommitsOpsClient) GetCommit(ctx context.Context, owner, repo, sha string, opts *github.ListOptions) (*github.RepositoryCommit, *github.Response, error)
- func (gClient *GitHubCommitsOpsClient) ListCommits(ctx context.Context, owner, repo string, opts *github.CommitsListOptions) ([]*github.RepositoryCommit, *github.Response, error)
- type GitHubConfig
- type GitHubFilter
- type GraphQLClient
- type Paths
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type CommitOpsClient ¶
type CommitOpsClient interface { ListCommits(ctx context.Context, owner, repo string, opts *github.CommitsListOptions) ([]*github.RepositoryCommit, *github.Response, error) GetCommit(ctx context.Context, owner, repo, sha string, opts *github.ListOptions) (*github.RepositoryCommit, *github.Response, error) }
CommitOpsClient is an interface to help test the GitHub GitHubCommitsOpsClient.
type GHQueryForListFiles ¶
type GHQueryForListFiles struct { Repository struct { Object struct { Tree struct { Entries []struct { Name string Path string Type string } } `graphql:"... on Tree"` } `graphql:"object(expression: $expression)"` } `graphql:"repository(owner: $owner, name: $name)"` }
GHQueryForListFiles is a struct representing the GraphQL query for listing files in a GitHub repository. It contains the information necessary to make the query, including the owner, name, expression, and path of the repository.
type GitHub ¶
type GitHub struct { Configuration GitHubConfig // contains filtered or unexported fields }
GitHub stores CommitOpsClient, GraphQLClient and configuration.
func NewGitHubClient ¶
func NewGitHubClient(commitOpsClient CommitOpsClient, graphQLClient GraphQLClient, configuration GitHubConfig) *GitHub
NewGitHubClient creates a new instance of the GitHub client. It takes a CommitOpsClient, GraphQLClient, and GitHubConfig as parameters and returns a pointer to a GitHub struct. The CommitOpsClient is responsible for making REST API calls to the GitHub API. The GraphQLClient is responsible for making GraphQL API calls to the GitHub API. The GitHubConfig contains the configuration parameters for the GitHub client, such as owner, repositories, default branch, and filter options. The new GitHub client is initialized with the provided CommitOpsClient, GraphQLClient, and GitHubConfig. The GitHub client can be used to interact with the GitHub API and perform various operations, such as retrieving file paths for repositories and getting changed file paths since a specified time. Usage:
commitOpsClient := NewGitHubCommitsOpsClient() graphQLClient := NewGraphQLClient() config := GitHubConfig{ Owner: "testowner", Repositories: []string{"repo1", "repo2"}, DefaultBranch: "main", Filter: GitHubFilter{ FilePath: "path/to/files", FileTypes: []string{".txt"}, }, } githubClient := NewGitHubClient(commitOpsClient, graphQLClient, config) filepaths, err := githubClient.GetFilePathsFromRepositories() if err != nil { log.Fatal(err) } for _, path := range filepaths { fmt.Println(path) }
func (*GitHub) GetChangedFilePathsSince ¶
GetChangedFilePathsSince retrieves the list of file paths that have changed in the specified repositories within the specified time frame. The function iterates over repositories defined in the GitHub configuration and uses the GitHub commit operations client to fetch the commits and commit details for each repository. It aggregates the file paths from all repositories into a single Paths object. The function filters these file paths based on the directory filter and the specified time frame and file path filter defined in the GitHub configuration. The Paths object is populated with lists of added, removed, and modified file paths accordingly.
Parameters:
- hoursSince: An integer representing the number of hours since the specified time. This parameter is used to determine the time frame for fetching changed file paths.
Returns:
- Paths: A struct containing lists of added, removed, and modified file paths. This struct provides an organized way to access the changed files.
- error: An error instance if an error occurs during the execution of the function. It will be nil if the function executes successfully.
Usage:
const sinceHours = 24 changedFiles, err := c.GetChangedFilePathsSince(sinceHours) if err != nil { log.Fatal(err) } fmt.Println("Added files:", changedFiles.Added) fmt.Println("Modified files:", changedFiles.Modified) fmt.Println("Removed files:", changedFiles.Removed)
func (*GitHub) GetFilePathsFromRepositories ¶
GetFilePathsFromRepositories retrieves the file paths for the repositories specified in the GitHub configuration. It iterates over each repository, calls the getFilePathsForRepo method to get the file paths, and appends them to the files slice. If there are no file types specified in the configuration, it returns the files directly. Otherwise, it filters the files based on the file types specified in the configuration and returns the filtered files. If there's an error during the process, it returns nil and the error.
Usage:
repos := []string{"repo1", "repo2", "repo3"} filePaths, err := GetFilePathsFromRepositories(repos) if err != nil { log.Fatal(err) } for _, paths := range filePaths { for _, path := range paths { fmt.Println(path) } }
type GitHubCommitsOpsClient ¶
GitHubCommitsOpsClient is a type that represents an operations client for GitHub commits. It contains a pointer to a GitHub client from the go-github library.
func NewGitHubCommitsOpsClient ¶
func NewGitHubCommitsOpsClient(httpClient *http.Client) *GitHubCommitsOpsClient
NewGitHubCommitsOpsClient creates a new GitHubCommitsOpsClient with the given http.Client. It initializes the GitHubClient inside GitHubCommitsOpsClient using the provided http.Client. The GitHubClient is responsible for interacting with the GitHub API.
func (*GitHubCommitsOpsClient) GetCommit ¶
func (gClient *GitHubCommitsOpsClient) GetCommit(ctx context.Context, owner, repo, sha string, opts *github.ListOptions) (*github.RepositoryCommit, *github.Response, error)
GetCommit retrieves a specific commit from a repository.
Parameters:
- ctx: The context.Context used for the API call. It allows you to cancel the request, set deadlines, etc.
- owner: The username or organization name of the repository owner. This string identifies the owner of the repository.
- repo: The name of the repository. It specifies which repository's commit is being retrieved.
- sha: The SHA hash of the commit. This string uniquely identifies the commit within the repository.
- opts: Optional parameters for the API call, provided as a pointer to github.ListOptions. This includes pagination options.
Returns:
- *github.RepositoryCommit: The retrieved commit information, including details like the commit message, author, etc.
- *github.Response: The HTTP response from the API call. This includes information like the status code and headers.
- error: An error instance if an error occurs during the API call. It will be nil if the call is successful.
Example:
commit, resp, err := gClient.GetCommit(ctx, "octocat", "hello-world", "6dcb09b5b57875f334f61aebed695e2e4193db5e", nil)
func (*GitHubCommitsOpsClient) ListCommits ¶
func (gClient *GitHubCommitsOpsClient) ListCommits(ctx context.Context, owner, repo string, opts *github.CommitsListOptions) ([]*github.RepositoryCommit, *github.Response, error)
ListCommits fetches the list of commits for a specific repository.
type GitHubConfig ¶
type GitHubConfig struct { Owner string Repositories []string DefaultBranch string Filter GitHubFilter }
GitHubConfig represents the configuration for GitHub repositories.
Owner represents the owner of the repositories. Repositories represents a list of repository names. DefaultBranch represents the default branch for the repositories. Filter represents the filter to apply when fetching file paths from the repositories.
type GitHubFilter ¶
GitHubFilter represents a filter used to narrow down the file paths in a GitHub repository based on the file path and file types.