logo
Free, unlimited AI code reviews that run on commit
git-lrc git-lrc GitHub Install Now We'd appreciate a star git-lrc - Free, unlimited AI code reviews that run on commit | Product Hunt git-lrc - Free, unlimited AI code reviews that run on commit | Product Hunt

API::GitForge - generic interface to APIs of sites like GitHub, GitLab etc.

Author

       Sean Whitton <spwhitton@spwhitton.name>

Description

       A gitforge is a site like GitHub, GitLab etc.  This module provides access to some operations which one
       might wish to perform against any git forge, wrapping the details of the APIs of particular forges.  An
       example of such an operation is forking a repository into the user's own namespace.

       See API::GitForge::Role::GitForge for details of all the currently supported operations.  Patches adding
       other operations, and support for other git forges, are welcome.

Functions

new_from_domaindomain=>$domain,access_key=>$key
       Instantiate an object representing the GitForge at $domain which does API::GitForge::Role::GitForge.
       This function will only succeed for known forges; see %API::GitForge::known_forges.  The "access_key"
       argument is optional; if present, it should be an API key for the forge.

           $API::GitForge::known_forges{"ourlab.com"} = "API::GitForge::GitLab";

           my $ourlab = API::GitForge::new_from_domain(
               domain     => "ourlab.com",
               access_key => API::GitForge::forge_access_token("ourlab.com")
           );

   forge_access_token$domain
       Return access token for forge at $domain, assumed to be stored under
       "$ENV{XDG_CONFIG_HOME}/gitforge/access_tokens/$domain" where the environment variable defaults to
       "~/.config" if unset.

   remote_forge_info$remote
       Look at the URL for git remote $remote, as returned by "git remote get-url", assume that this remote is a
       git forge, and return the domain name of that forge and the path to the repository.

           system qw(git remote add salsa https://salsa.debian.org/spwhitton/foo);
           my ($forge_domain, $forge_repo) = API::GitForge::remote_forge_info("salsa");

           say $forge_domain;          # outputs 'salsa.debian.org'
           say $forge_repo;            # outputs 'spwhitton/foo'

Name

       API::GitForge - generic interface to APIs of sites like GitHub, GitLab etc.

Status

       Unstable.  Interface may change.

Synopsis

           # try to autodetect the forge type; works for GitHub and some others
           my $github = API::GitForge->new_from_domain(
               domain     => "github.com",
               access_key => "12345678"
           );

           # specify the forge type yourself by instantiating the right class
           my $salsa = API::GitForge::GitLab->new(
               domain     => "salsa.debian.org",
               access_key => "abcdef"
           );

           # generic user operations regardless of the forge type
           $github->clean_fork("spwhitton/git-remote-gcrypt");
           $salsa->clean_fork("Debian/devscripts");

Version

       version 0.007

See Also