Class RepositoriesImpl
java.lang.Object
io.github.intisy.gradle.github.impl.RepositoriesImpl
- All Implemented Interfaces:
Repositories
Repositories that builds a fresh, per-call GitHub scoped to the exact owner and
repo an operation names, instead of reusing the single GitHub GitHubApi.create
was given.- Implementation Note:
- Mirrors
SourceBuilder.buildFromSource(java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String): aGitHubcarries oneResourceSettings, so its own update path (which resolves the owner from that extension) is only correct for repeated calls against the same repository.cloneOrPull(java.io.File, java.lang.String, java.lang.String, java.lang.String)builds its own scopedGitHubper call so a consumer can target any repository, any number of times, without a previous call's target leaking into the next one.cloneOrPullFrom(java.io.File, java.lang.String, java.lang.String)does the same but scopes to the caller's owncloneUrlverbatim instead of reconstructing a github.com URL from owner and repo, so a non-github.com host (self-hosted GitLab, Gitea, a GitHub Enterprise instance) is honoured rather than silently redirected to public github.com.isUpToDate(java.io.File)takes no owner/repo, so it derives the repository identity from the checkout atpathitself (the same wayremoteOf(java.io.File)does) rather than from whichever repository happened to be configured at construction time.exists(java.io.File),remoteOf(java.io.File)andconfiguredRepo()genuinely have no repository-specific behavior to scope, so they keep using the construction-timeGitHub.
-
Constructor Summary
ConstructorsConstructorDescriptionRepositoriesImpl(GitHub configured, GitHubConfig config, GitHubLogger logger) -
Method Summary
Modifier and TypeMethodDescriptionvoidcloneOrPull(File target, String owner, String repo, String branch) Clonesowner/repointotargetif no checkout exists there yet, otherwise pulls the latest changes forbranch(or the current branch, if null).voidcloneOrPullFrom(File target, String cloneUrl, String branch) Clones or pullscloneUrlintotarget, using the given URL directly rather than reconstructing one from an owner and repo, so any git host is honoured exactly as configured (github.com, GitHub Enterprise, or any other host).The owner and repository parsed from the implementation's own configured repository URL.booleanbooleanisUpToDate(File path)
-
Constructor Details
-
RepositoriesImpl
- Parameters:
configured- the construction-timeGitHub, used as-is by operations that have no repository-specific behavior to scope (exists(java.io.File),remoteOf(java.io.File),configuredRepo()).config- the access token and auth/cli/resilience settings, reused to build each per-call scopedGitHub.logger- receives diagnostic output from each per-call scopedGitHub.
-
-
Method Details
-
cloneOrPull
Description copied from interface:RepositoriesClonesowner/repointotargetif no checkout exists there yet, otherwise pulls the latest changes forbranch(or the current branch, if null).- Specified by:
cloneOrPullin interfaceRepositories- Parameters:
target- the local directory to clone into or pull within.owner- the GitHub account or organization that owns the repository.repo- the repository name, without the owner prefix.branch- the branch to clone or pull, or null for the current/default branch.- Throws:
IOException- if the clone or pull fails.
-
cloneOrPullFrom
Description copied from interface:RepositoriesClones or pullscloneUrlintotarget, using the given URL directly rather than reconstructing one from an owner and repo, so any git host is honoured exactly as configured (github.com, GitHub Enterprise, or any other host).- Specified by:
cloneOrPullFromin interfaceRepositories- Parameters:
target- the local directory to clone into or pull within.cloneUrl- the exact URL to clone from.branch- the branch to clone or pull, or null for the current/default branch.- Throws:
IOException- if the clone or pull fails.
-
exists
- Specified by:
existsin interfaceRepositories- Parameters:
path- the directory to check.- Returns:
- true if a git repository checkout exists at
path.
-
isUpToDate
- Specified by:
isUpToDatein interfaceRepositories- Parameters:
path- the checkout to check, whose ownoriginremote identifies the repository.- Returns:
- true if
path's current branch matches its remote counterpart, false if it is behind or the check itself fails (e.g. no network access).
-
remoteOf
- Specified by:
remoteOfin interfaceRepositories- Parameters:
projectDir- the checkout whoseoriginremote is parsed.- Returns:
- the owner and repository name parsed from
projectDir'soriginremote URL.
-
configuredRepo
Description copied from interface:RepositoriesThe owner and repository parsed from the implementation's own configured repository URL.- Specified by:
configuredRepoin interfaceRepositories- Returns:
- the configured owner and repo, or a
RemoteRepowith null fields if none is configured.
-