On this page
article
23.11-git-calls
What
Program must get data from git repository:
- Files diff
- Commit names and authors
How
git cli calls
This method is used by reviewdog
Pros:
- Simple execution
Cons:
- Require result parsing
- App depends on git cli
go-git library
This method known to me. I used it in devex
Pros:
- Compile safety
- No dependency on external apps
- Allows parallel data fetching (speed)
Cons:
- Binary size
- Rare dependency
Package design
type Git interface {
// Branches returns PR source and target branch
Branches() (source, target string)
// Commits returns PR commits
Commits() []Commit
// Changes returns PR repository files diff
Changes() []FileChange
}
Few methods to create it:
InitPR
creates diff between current and target branch (like PR diff)InitLast
creates diff for last N current branch commits
Why publicity and full abstraction from go-git:
- Current benefit for this project. Package can be used now for checks automation via go scripts.
- Current benefit for my work projects. Package can be used outside this project as library.
- Full DI control in other packages tests.