Class RepositoriesImpl

java.lang.Object
io.github.intisy.gradle.github.impl.RepositoriesImpl
All Implemented Interfaces:
Repositories

public class RepositoriesImpl extends Object implements 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): a GitHub carries one ResourceSettings, 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 scoped GitHub per 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 own cloneUrl verbatim 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 at path itself (the same way remoteOf(java.io.File) does) rather than from whichever repository happened to be configured at construction time. exists(java.io.File), remoteOf(java.io.File) and configuredRepo() genuinely have no repository-specific behavior to scope, so they keep using the construction-time GitHub.
  • Constructor Details

  • Method Details

    • cloneOrPull

      public void cloneOrPull(File target, String owner, String repo, String branch) throws IOException
      Description copied from interface: Repositories
      Clones owner/repo into target if no checkout exists there yet, otherwise pulls the latest changes for branch (or the current branch, if null).
      Specified by:
      cloneOrPull in interface Repositories
      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

      public void cloneOrPullFrom(File target, String cloneUrl, String branch) throws IOException
      Description copied from interface: Repositories
      Clones or pulls cloneUrl into target, 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:
      cloneOrPullFrom in interface Repositories
      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

      public boolean exists(File path)
      Specified by:
      exists in interface Repositories
      Parameters:
      path - the directory to check.
      Returns:
      true if a git repository checkout exists at path.
    • isUpToDate

      public boolean isUpToDate(File path)
      Specified by:
      isUpToDate in interface Repositories
      Parameters:
      path - the checkout to check, whose own origin remote 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

      public RemoteRepo remoteOf(File projectDir)
      Specified by:
      remoteOf in interface Repositories
      Parameters:
      projectDir - the checkout whose origin remote is parsed.
      Returns:
      the owner and repository name parsed from projectDir's origin remote URL.
    • configuredRepo

      public RemoteRepo configuredRepo()
      Description copied from interface: Repositories
      The owner and repository parsed from the implementation's own configured repository URL.
      Specified by:
      configuredRepo in interface Repositories
      Returns:
      the configured owner and repo, or a RemoteRepo with null fields if none is configured.