-
Notifications
You must be signed in to change notification settings - Fork 0
Add Copilot instructions for repository context #11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
Copilot
wants to merge
3
commits into
main
Choose a base branch
from
copilot/set-up-copilot-instructions
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,142 @@ | ||
| # Copilot Instructions for GitInsights | ||
|
|
||
| ## Repository Overview | ||
|
|
||
| GitInsights is a Go-based command-line tool that analyzes GitHub profiles and generates detailed statistics about repository languages, commit patterns, and productivity metrics. The tool updates a README.md file with visual insights about a user's GitHub activity. | ||
|
|
||
| ## Technology Stack | ||
|
|
||
| - **Language**: Go 1.21 | ||
| - **Key Dependencies**: | ||
| - `github.com/google/go-github/v38` - GitHub API client | ||
| - `golang.org/x/oauth2` - OAuth2 authentication | ||
| - **Testing**: Standard Go testing framework | ||
| - **CI/CD**: GitHub Actions | ||
|
|
||
| ## Project Structure | ||
|
|
||
| ``` | ||
| . | ||
| ├── main.go # Main application logic | ||
| ├── main_test.go # Unit tests with mocked GitHub API | ||
| ├── go.mod # Go module dependencies | ||
| ├── go.sum # Dependency checksums | ||
| ├── README.md # Project documentation with embedded statistics | ||
| └── .github/ | ||
| └── workflows/ # GitHub Actions workflows | ||
| ``` | ||
|
|
||
| ## Key Components | ||
|
|
||
| ### Core Functionality | ||
|
|
||
| 1. **GitHub API Integration** (`GitHubClient` interface): | ||
| - `GetUser()` - Retrieve user details | ||
| - `ListRepositories()` - Fetch user's repositories | ||
| - `ListLanguages()` - Get language statistics per repository | ||
| - `ListAllCommits()` - Retrieve commit history across repositories | ||
|
|
||
| 2. **Statistics Generation**: | ||
| - `summarizeGitHubProfile()` - Aggregates language usage across all repositories | ||
| - `calculateMostProductiveDay()` - Analyzes commit patterns by day of week | ||
| - `calculateMostProductiveTime()` - Analyzes commit patterns by hour | ||
| - `generateMarkdown()` - Creates formatted output with progress bars | ||
|
|
||
| 3. **README Update**: | ||
| - `updateReadme()` - Replaces content between `<!--START_SECTION:GitInsights-->` and `<!--END_SECTION:GitInsights-->` markers | ||
|
|
||
| ## Development Workflow | ||
|
|
||
| ### Building | ||
|
|
||
| ```bash | ||
| go build ./... | ||
| ``` | ||
|
|
||
| ### Running Tests | ||
|
|
||
| ```bash | ||
| go test -v ./... | ||
| ``` | ||
|
|
||
| ### Linting | ||
|
|
||
| ```bash | ||
| go vet ./... | ||
| gofmt -l . | ||
| ``` | ||
|
|
||
| ### Running the Application | ||
|
|
||
| Requires `GITHUB_TOKEN` environment variable: | ||
|
|
||
| ```bash | ||
| export GITHUB_TOKEN=$(gh auth token) | ||
| go run main.go | ||
| ``` | ||
|
|
||
| ## Code Style and Conventions | ||
|
|
||
| 1. **Interface-Based Design**: Use the `GitHubClient` interface for GitHub operations to enable mocking in tests | ||
| 2. **Concurrency**: Use goroutines and channels for parallel API calls (see repository and commit processing) | ||
| 3. **Error Handling**: Always return and check errors; log non-fatal errors with `log.Printf()` | ||
| 4. **Testing**: Mock the `GitHubClient` interface using `MockGitHubAPI` for unit tests | ||
| 5. **Formatting**: Code must pass `gofmt` checks (enforced in CI) | ||
|
|
||
| ## Testing Guidelines | ||
|
|
||
| - All tests use mock implementations of `GitHubClient` interface | ||
| - Mock data should be realistic and cover edge cases | ||
| - Test functions follow the pattern `Test<FunctionName>` | ||
| - Use the `MockGitHubAPI` struct defined in `main_test.go` | ||
| - Tests should verify both success cases and error handling | ||
|
|
||
| ## Important Notes | ||
|
|
||
| 1. **README Markers**: The application expects `<!--START_SECTION:GitInsights-->` and `<!--END_SECTION:GitInsights-->` markers in README.md | ||
| 2. **Language Aggregation**: Languages below 5% threshold are combined into "Other" category | ||
| 3. **Concurrency**: Repository and commit processing uses goroutines for performance | ||
| 4. **Authentication**: Requires valid GitHub personal access token with appropriate scopes | ||
|
|
||
| ## GitHub Actions | ||
|
|
||
| Three workflows are configured: | ||
|
|
||
| 1. **test.yaml** - Runs on push/PR: tests, linting, formatting checks, build | ||
| 2. **build_and_release.yaml** - Creates releases with compiled binaries | ||
| 3. **update_readme.yaml** - Scheduled/manual execution to update README with latest statistics | ||
|
|
||
| ## Making Changes | ||
|
|
||
| When modifying code: | ||
|
|
||
| 1. Maintain the interface-based architecture for testability | ||
| 2. Add corresponding unit tests with mocked dependencies | ||
| 3. Ensure concurrent operations use proper synchronization (WaitGroups, channels) | ||
| 4. Run full test suite before committing: `go test -v ./...` | ||
| 5. Verify formatting: `gofmt -l .` (should return no files) | ||
| 6. Run linter: `go vet ./...` | ||
| 7. Test builds successfully: `go build ./...` | ||
|
|
||
| ## Common Tasks | ||
|
|
||
| ### Adding New Statistics | ||
|
|
||
| 1. Create a new function following the pattern of `calculateMostProductiveDay()` | ||
| 2. Add a method to `GitHubClient` interface if new API calls are needed | ||
| 3. Implement the method in both `GitHubAPI` and `MockGitHubAPI` | ||
| 4. Update `generateMarkdown()` to include the new statistic | ||
| 5. Add comprehensive unit tests | ||
|
|
||
| ### Modifying Output Format | ||
|
|
||
| 1. Update `generateMarkdown()` function | ||
| 2. Maintain the `<!--START_SECTION:GitInsights-->` and `<!--END_SECTION:GitInsights-->` markers | ||
| 3. Test with `updateReadme()` function to ensure proper section replacement | ||
|
|
||
| ### Adding API Endpoints | ||
|
|
||
| 1. Add method to `GitHubClient` interface | ||
| 2. Implement in `GitHubAPI` struct using `g.Client` (go-github client) | ||
| 3. Add mock implementation in `MockGitHubAPI` for testing | ||
| 4. Write unit tests using the mock | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| GitInsights | ||
| *.out |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Corrected spelling of 'Github' to 'GitHub' (capital H).