Skip to content

Commit 1afc677

Browse files
committed
batch5
1 parent fc4f2ea commit 1afc677

File tree

22 files changed

+2964
-8
lines changed

22 files changed

+2964
-8
lines changed

.devcontainer/postCreateCommand.sh

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,5 +28,17 @@ echo "$PREFIX ✅ Setting up safe git repository to prevent dubious ownership er
2828
git config --local --get include.path | grep -e ../.gitconfig >/dev/null 2>&1 || git config --local --add include.path ../.gitconfig
2929
echo "$PREFIX ✅ Setting up git configuration to support .gitconfig in repo-root"
3030

31-
echo "$PREFIX Leaving $(basename $0)"
32-
exit 0
31+
# Install Go dependencies if go.mod exists
32+
if [ -f "go.mod" ]; then
33+
echo "$PREFIX Installing Go dependencies (go mod download)..."
34+
go mod download
35+
36+
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | \
37+
sh -s -- -b $(go env GOPATH)/bin latest
38+
echo "$PREFIX ✅ Installing golangci-lint"
39+
40+
fi
41+
42+
43+
echo "$PREFIX ✅ SUCCESS"
44+
exit 0
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
name: Build Go Binary
2+
description: Build a Go binary for a specific platform (OS/Architecture). Assumes workspace and Go environment are already set up.
3+
4+
inputs:
5+
os:
6+
description: Target operating system (linux, darwin, windows)
7+
required: true
8+
arch:
9+
description: Target architecture (amd64, arm64)
10+
required: true
11+
ext:
12+
description: File extension (e.g., '.exe' for Windows)
13+
required: false
14+
default: ''
15+
binary-name:
16+
description: Prefix for the binary name (e.g., 'godo' produces godo-linux-amd64)
17+
required: true
18+
upload-artifact:
19+
description: Upload the built binary as an artifact
20+
required: false
21+
default: 'true'
22+
23+
outputs:
24+
artifact-name:
25+
description: Name of the uploaded artifact
26+
value: ${{ steps.build.outputs.artifact-name }}
27+
binary-path:
28+
description: Path to the built binary
29+
value: ${{ steps.build.outputs.binary-path }}
30+
31+
runs:
32+
using: composite
33+
steps:
34+
- name: Build binary
35+
id: build
36+
shell: bash
37+
env:
38+
GOOS: ${{ inputs.os }}
39+
GOARCH: ${{ inputs.arch }}
40+
BINARY_NAME: ${{ inputs.binary-name }}
41+
EXT: ${{ inputs.ext }}
42+
run: |
43+
# Create output directory
44+
mkdir -p dist
45+
46+
# Build binary
47+
OUTPUT_FILE="dist/${BINARY_NAME}-${{ inputs.os }}-${{ inputs.arch }}${EXT}"
48+
echo "Building for ${{ inputs.os }}/${{ inputs.arch }}..."
49+
go build -ldflags="-s -w" -o "$OUTPUT_FILE" .
50+
51+
if [ $? -eq 0 ]; then
52+
echo "✓ Built ${OUTPUT_FILE}"
53+
ls -lh "$OUTPUT_FILE"
54+
55+
# Set outputs
56+
echo "artifact-name=${{ inputs.binary-name }}-${{ inputs.os }}-${{ inputs.arch }}" >> $GITHUB_OUTPUT
57+
echo "binary-path=$OUTPUT_FILE" >> $GITHUB_OUTPUT
58+
else
59+
echo "✗ Failed to build for ${{ inputs.os }}/${{ inputs.arch }}"
60+
exit 1
61+
fi
62+
63+
- name: Upload artifact
64+
if: inputs.upload-artifact == 'true'
65+
uses: actions/upload-artifact@v4
66+
with:
67+
name: ${{ steps.build.outputs.artifact-name }}
68+
path: ${{ steps.build.outputs.binary-path }}
69+
retention-days: 1
70+
71+

.github/copilot-instructions.md

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
# GitHub Copilot Instructions for gh-godo
2+
3+
## Project Overview
4+
5+
This repository contains `gh-godo`, a GitHub CLI extension written in Go. The extension provides utility commands for GitHub workflows and automation.
6+
7+
## Project Structure
8+
9+
- `main.go` - Entry point in the repository root
10+
- `cmd/` - Command implementations using Cobra CLI framework
11+
- `internal/` - Internal packages not meant for external use
12+
- `Makefile` - Build automation and common tasks
13+
- `.githooks/` - Git hooks including pre-commit checks
14+
- `.github/workflows/` - CI/CD workflows
15+
16+
## Code Standards
17+
18+
### Go Programming
19+
20+
1. **Use Go 1.23+** - This project targets Go 1.23 or higher
21+
2. **Follow standard Go conventions**:
22+
- Use `gofmt` for formatting
23+
- Run `go vet` for static analysis
24+
- Use `golangci-lint` for comprehensive linting
25+
3. **Package organization**:
26+
- `cmd/` for command-line interface commands
27+
- `internal/` for internal application code
28+
- Each package should have focused responsibility
29+
30+
### CLI Design Principles
31+
32+
1. **Named flags over anonymous arguments**: Always use named flags (`--flag` or `-f`) instead of positional arguments
33+
2. **Long and short forms**: Provide both long (`--file`) and short (`-f`) versions for commonly used flags
34+
3. **Cobra framework**: Use the Cobra library for all CLI command implementations
35+
4. **Help text**: Provide clear, concise help text for all commands and flags
36+
37+
### Testing
38+
39+
1. **Write table-driven tests**: Use Go's standard table-driven testing pattern
40+
2. **Test coverage**: Aim for high test coverage on business logic
41+
3. **Run tests before commit**: The pre-commit hook runs all tests automatically
42+
43+
### Build and Development
44+
45+
1. **Use Makefile targets**:
46+
- `make build` - Build the binary
47+
- `make test` - Run tests
48+
- `make lint` - Run linters
49+
- `make coverage` - Generate coverage report
50+
- `make build-all` - Build for all platforms
51+
52+
2. **Cross-platform builds**: Support Linux, Darwin (macOS), and Windows on AMD64 and ARM64
53+
54+
### Git Workflow
55+
56+
1. **Pre-commit hooks**: All commits are validated by `.githooks/pre-commit`
57+
2. **Checks run before commit**:
58+
- Spell checking (cspell)
59+
- Markdown linting
60+
- Code formatting (prettier, gofmt)
61+
- Go vet
62+
- golangci-lint
63+
- Go tests
64+
- Build verification
65+
66+
## Making Changes
67+
68+
When modifying the code:
69+
70+
1. **Minimal changes**: Make the smallest possible change to achieve the goal
71+
2. **Test first**: Run tests locally before committing
72+
3. **Lint your code**: Ensure `make lint` passes
73+
4. **Update tests**: Add or update tests for new functionality
74+
5. **Document**: Update relevant documentation
75+
76+
## GH CLI Extension
77+
78+
This project is designed to be installed as a GitHub CLI extension:
79+
80+
```bash
81+
gh extension install lakruzz/gh-godo
82+
gh godo mkissue --file issue.md
83+
```
84+
85+
The binary must be named `godo` and placed in the repository root to be recognized by the `gh` CLI.
86+
87+
## RAG Instructions Location
88+
89+
Additional instructions can be found in:
90+
91+
- `.github/copilot-instructions.md` (this file)
92+
- `.github/instructions/*.instructions.md` - Specific topic instructions
Lines changed: 179 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,179 @@
1+
# Go Development Standards
2+
3+
## Go Version
4+
5+
- **Current version**: Go 1.23
6+
- **Update policy**: Keep reasonably current with stable Go releases
7+
8+
## Project Layout
9+
10+
Follow the standard Go project layout:
11+
12+
```txt
13+
/
14+
├── main.go # Application entry point
15+
├── cmd/ # Command implementations
16+
├── internal/ # Private application code
17+
│ └── <package>/ # Internal packages
18+
├── go.mod # Module definition
19+
├── go.sum # Dependency checksums
20+
├── Makefile # Build automation
21+
└── .golangci.yml # Linter configuration
22+
```
23+
24+
## Coding Standards
25+
26+
### Formatting
27+
28+
- Use `gofmt` for all Go files (enforced by pre-commit hook)
29+
- Use `goimports` for import organization (included in golangci-lint)
30+
31+
### Naming Conventions
32+
33+
- **Packages**: Short, lowercase, single-word names (e.g., `issue`, `cmd`)
34+
- **Interfaces**: End with `-er` suffix when appropriate (e.g., `Reader`, `Writer`)
35+
- **Variables**: Use camelCase
36+
- **Constants**: Use MixedCaps or UPPER_CASE for exported constants
37+
- **Exported names**: Start with uppercase letter
38+
- **Unexported names**: Start with lowercase letter
39+
40+
### Error Handling
41+
42+
- Always check errors explicitly
43+
- Wrap errors with context using `fmt.Errorf` with `%w` verb
44+
- Return errors up the call stack; handle at the appropriate level
45+
- Don't use panic for normal error handling
46+
47+
Example:
48+
49+
```go
50+
content, err := os.ReadFile(filePath)
51+
if err != nil {
52+
return fmt.Errorf("failed to read file: %w", err)
53+
}
54+
```
55+
56+
### Testing
57+
58+
- **Location**: Tests go in `*_test.go` files alongside the code
59+
- **Pattern**: Use table-driven tests for multiple test cases
60+
- **Coverage**: Run `make coverage` to check coverage
61+
- **Race detector**: Tests run with `-race` flag in CI
62+
63+
Example table-driven test:
64+
65+
```go
66+
func TestFunction(t *testing.T) {
67+
tests := []struct {
68+
name string
69+
input string
70+
want string
71+
wantErr bool
72+
}{
73+
{"case 1", "input1", "output1", false},
74+
{"error case", "bad", "", true},
75+
}
76+
77+
for _, tt := range tests {
78+
t.Run(tt.name, func(t *testing.T) {
79+
got, err := Function(tt.input)
80+
if (err != nil) != tt.wantErr {
81+
t.Errorf("error = %v, wantErr %v", err, tt.wantErr)
82+
return
83+
}
84+
if got != tt.want {
85+
t.Errorf("got %v, want %v", got, tt.want)
86+
}
87+
})
88+
}
89+
}
90+
```
91+
92+
## Dependencies
93+
94+
- **Minimize dependencies**: Only add well-maintained, necessary dependencies
95+
- **Use go.mod**: Manage dependencies with Go modules
96+
- **Version pinning**: Use specific versions in go.mod
97+
- **Update regularly**: Keep dependencies updated for security
98+
99+
### Current Dependencies
100+
101+
- `github.com/spf13/cobra` - CLI framework (standard for Go CLI apps)
102+
103+
## Linting
104+
105+
### golangci-lint Configuration
106+
107+
The project uses `golangci-lint` with multiple linters enabled:
108+
109+
- **errcheck**: Unchecked errors
110+
- **gosimple**: Code simplification
111+
- **govet**: Suspicious constructs
112+
- **staticcheck**: Static analysis
113+
- **gofmt**: Code formatting
114+
- **goimports**: Import organization
115+
- **revive**: Comprehensive linting (golint replacement)
116+
- **gosec**: Security issues
117+
- **gocyclo**: Cyclomatic complexity (threshold: 15)
118+
- **gocognit**: Cognitive complexity (threshold: 20)
119+
120+
### Running Linters
121+
122+
```bash
123+
make lint # Run all linters
124+
make fmt # Format code
125+
make vet # Run go vet
126+
```
127+
128+
## Build Process
129+
130+
### Local Development
131+
132+
```bash
133+
make build # Build for current platform
134+
make test # Run tests
135+
make coverage # Generate coverage report
136+
```
137+
138+
### Multi-Platform Builds
139+
140+
```bash
141+
make build-all # Build for:
142+
# - linux/amd64, linux/arm64
143+
# - darwin/amd64, darwin/arm64
144+
# - windows/amd64, windows/arm64
145+
```
146+
147+
## Performance Considerations
148+
149+
- Use profiling for performance-critical code (`go test -cpuprofile`, `-memprofile`)
150+
- Pre-allocate slices when size is known
151+
- Use string builders for string concatenation
152+
- Be mindful of memory allocations in hot paths
153+
154+
## Security
155+
156+
- Run `gosec` linter (included in golangci-lint)
157+
- Never hard-code credentials
158+
- Validate all external inputs
159+
- Use `crypto/rand` for random numbers (not `math/rand`)
160+
- Keep dependencies updated for security patches
161+
162+
## Documentation
163+
164+
- **Package comments**: Every package should have a package-level comment
165+
- **Exported functions**: Document all exported functions, types, and constants
166+
- **Examples**: Provide examples for complex functionality
167+
- **README**: Keep README.md updated with usage instructions
168+
169+
## Git Hooks
170+
171+
The pre-commit hook runs:
172+
173+
1. Go formatting check (`gofmt`)
174+
2. Go vet
175+
3. golangci-lint
176+
4. Go tests with race detector
177+
5. Build verification
178+
179+
All checks must pass before commit.
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
name: Copilot Setup Steps
2+
3+
on:
4+
workflow_dispatch:
5+
push:
6+
paths:
7+
- .github/workflows/copilot-setup-steps.yml
8+
pull_request:
9+
paths:
10+
- .github/workflows/copilot-setup-steps.yml
11+
12+
jobs:
13+
copilot-setup-steps:
14+
runs-on: ubuntu-latest
15+
permissions:
16+
contents: read
17+
18+
steps:
19+
- name: Checkout
20+
uses: actions/checkout@v6
21+
22+
- name: Set up runner environment
23+
uses: ./.github/actions/prep-runner
24+
25+
- name: test precommit hook
26+
run: ./.githooks/pre-commit
27+

0 commit comments

Comments
 (0)