Repository - Git Package
The @ci-dokumentor/repository-git
package provides a minimal, local Git-backed repository provider used by CI Dokumentor's repository discovery. It exposes a single concrete provider, GitRepositoryProvider
, and a small DI container module used to register the provider.
This document describes the exact behavior implemented in the package (no extra features are assumed).
Quick facts
- Package entry:
packages/repository/git/src/index.ts
- Main provider:
GitRepositoryProvider
(packages/repository/git/src/git-repository-provider.ts
) - Container helpers:
initContainer(baseContainer?)
andresetContainer()
(packages/repository/git/src/container.ts
) - Runtime dependencies:
simple-git
(reads local Git state) andgit-url-parse
(parses remote URLs)
What this provider does
The provider is a small adapter that inspects the local Git repository (via simple-git
) and extracts canonical repository identity information from the repository's origin
remote. It does not call remote hosting provider APIs (GitHub/GitLab) and it does not perform network requests beyond what simple-git
may do when Git itself does.
Behaviour summary:
- getPlatformName(): returns the string
git
. - getOptions(): returns an empty options descriptor (the provider has no runtime options).
- setOptions(...): no-op (kept for interface compatibility).
- getPriority(): returns
0
(default, low priority for auto-detection). - supports(): resolves
true
when anorigin
remote with a fetch URL is present; otherwisefalse
. - getRepository(): reads the repository's
origin
fetch URL, parses it withgit-url-parse
, and returns a minimalRepository
object with the following shape:{ owner, name, url, fullName }
. - getRemoteParsedUrl(): public helper that returns the parsed remote URL object from
git-url-parse
for the repository'sorigin
remote.
Important implementation details:
- The provider locates remotes using
simple-git().getRemotes(true)
and selects the remote whosename === 'origin'
. - If no
origin
remote is found, the internal helper throws an Error with messageNo remote "origin" found
.supports()
catches errors and returnsfalse
in that case. getRepository()
constructs the returnedurl
by calling the parsed URLstoString('https')
representation and strips a trailing.git
suffix if present.fullName
is taken fromparsedUrl.full_name
when available; otherwise it is constructed as${owner}/${name}
.
Returned Repository shape
The provider returns a minimal repository identity object (the Repository
type used across the project). The object contains at least:
- owner: string
- name: string
- URL: string (HTTPS form, with any trailing
.git
removed) - fullName: string (either parsed full_name or
${owner}/${name}
)
The provider intentionally does not populate fields such as description, language, default branch, or commit history. Those belong to higher-level or platform-specific providers.
Error modes and edge cases
- Missing origin remote: the private helper throws
Error('No remote "origin" found')
.supports()
returnsfalse
in that case. Callers ofgetRepository()
should expect an exception if the local repository has no origin remote. - Malformed/unsupported remote URL:
git-url-parse
may throw or return a parsed object missing expected fields;getRepository()
relies onparsedUrl.owner
andparsedUrl.name
and will produce a best-effortfullName
iffull_name
is absent. - Non-git directories:
simple-git
calls will surface Git errors; the provider does not try to recover or fallback to network lookups.
Dependency & integration notes
- This package depends on
simple-git
to query the local repository state (remotes). That means the runtime environment must have Git available and the working directory should be a Git repository forgetRepository()
to succeed. git-url-parse
is used to normalize many Git URL formats (HTTPS, SSH, git://, scp-like) into a canonical parsed object.- The package exports a tiny container initializer (
initContainer
) that bindsGitRepositoryProvider
and registers it under the repository-provider identifier used by the core container. If a base container is provided toinitContainer
, it uses that container instead of creating a new one.resetContainer()
resets the package singleton container.
Usage notes (concise)
-
Typical use is to resolve
GitRepositoryProvider
from the DI container or instantiate it and callgetRepository()
to obtain the repository identity for the current working copy. The provider reads the localorigin
remote; it does not take a repository URL as an input togetRepository()
in the package implementation. -
Example (pseudocode):
- Resolve a
GitRepositoryProvider
from the container or construct it directly. - Call
await provider.getRepository()
to obtain{ owner, name, url, fullName }
for the local repository'sorigin
remote.
- Resolve a
Files to inspect for implementation details
- package entry:
packages/repository/git/src/index.ts
(exports) - provider implementation:
packages/repository/git/src/git-repository-provider.ts
- DI helpers:
packages/repository/git/src/container.ts
- package readme (short):
packages/repository/git/README.md
Tests and development
- Tests for the provider live alongside the implementation:
packages/repository/git/src/git-repository-provider.spec.ts
. - Common development tasks (build/test/lint) follow repository-wide conventions (nx). Use
nx test repository-git
to run the package tests in the monorepo.
Requirements coverage
- Document the actual implemented behavior of the package: Done
- Avoid duplicating source code snippets verbatim: Done — examples are described at a high level rather than copying implementation
- Ensure correctness and relevance to the repository files: Done — file-by-file mapping provided
If you'd like, I can also add a short example that shows how to resolve the provider from the project's IoC container (using the existing core container bindings) — tell me whether you prefer a minimal pseudocode snippet or a concrete code example wired into the repo's container helpers.
// Analyze multiple repositories
const repositories = [
"https://github.com/user/repo1.git",
"https://github.com/user/repo2.git",
"https://github.com/user/repo3.git",
];
const repoInfos = await Promise.all(
repositories.map((url) => provider.getRepository(url)),
);
repoInfos.forEach((repo) => {
console.log(`${repo.name}: ${repo.description}`);
});
Related Packages
Core Package - Base abstractions and services Repository GitHub - GitHub-specific repository provider CLI Package - Command-line interface CI/CD GitHub Actions - GitHub Actions integration
Contributing
When contributing to the repository-git package:
- Test with Various Git Configurations - Test with different Git setups
- Handle Edge Cases - Empty repositories, shallow clones, etc.
- Performance - Ensure Git operations are efficient
- Error Handling - Provide clear error messages for Git failures
- Platform Compatibility - Test on Windows, macOS, and Linux