Verified Commit a9383206 authored by Roman Lacko's avatar Roman Lacko
Browse files

add Repositories API

parent 1fe6a4f4
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -13,6 +13,7 @@ use GitLab::Groups;
use GitLab::Members;
use GitLab::Namespaces;
use GitLab::Projects;
use GitLab::Repositories;
use GitLab::Runners;
use GitLab::Users;
use Try::Tiny;

GitLab/Repositories.pm

0 → 100644
+180 −0
Original line number Diff line number Diff line
package GitLab::Repositories;

use utf8;
use strict;
use warnings;
use vars qw($VERSION);

use GitLab::API;
use Log::Any        qw($log);

our $VERSION = v11.3.4;

my $requests = {
    ls_tree => {
        method      => "GET",
        path        => "/projects/<pid>/repository/tree",
        optional    => [qw(
            path
            ref
            recursive
        )],
        paginated   => 1,
    },

    get_blob => {
        method      => "GET",
        path        => "/projects/<pid>/repository/blobs/<sha>",
    },

    get_blob_raw => {
        method      => "GET",
        path        => "/projects/<pid>/repository/blobs/<sha>/raw",
    },

    get_archive => {
        method      => "GET",
        path        => "/projects/<pid>/repository/archive",
        optional    => [qw(
            sha
            format
        )],
    },

    compare_refs => {
        method      => "GET",
        path        => "/projects/<pid>/repository/compare",
        required    => [qw(
            from
            to
        )],
        optional    => [qw(
            straight
        )],
    },

    contributors => {
        method      => "GET",
        path        => "/projects/<pid>/repository/contributos",
        optional    => [qw(
            order_by
            sort
        )],
    },

    merge_base => {
        method      => "GET",
        path        => "/projects/<pid>/repository/merge_base",
        required    => [qw(
            refs
        )],
    },
};

sub import {
    $log->debug("initializing " . __PACKAGE__);
    while (my ($name, $tmpl) = each(%$requests)) {
        $tmpl->{name} = $name unless exists $tmpl->{name};
        GitLab::API->register($tmpl);
    }
}

1;

__END__

=head1 NAME

GitLab::Repository - implements repositories API calls

See L<GitLab API -- Users|http://doc.gitlab.com/ce/api/repositories.html> for details and
response formats.

=head1 VERSION

Implements API calls for GitLab CE C<v11.3.4>.

=head1 DESCRIPTION

=over

=item L<ls_tree()|https://docs.gitlab.com/ce/api/repositories.html#list-repository-tree>

    $objects = $gitlab->ls_tree( :pid );

Get a list of repository files and directories in a project.
This endpoint can be accessed without authentication if the repository is publicly accessible.

=item L<get_blob()|https://docs.gitlab.com/ce/api/repositories.html#get-a-blob-from-repository>

=item L<get_blob_raw()|https://docs.gitlab.com/ce/api/repositories.html#raw-blob-content>

    $blob_base64 = $gitlab->get_blob( :id, :sha );
    $blob        = $gitlab->get_blob_raw( :id, :sha );

Allows you to receive information about blob in repository like size and content.

=item L<get_archive()|https://docs.gitlab.com/ce/api/repositories.html#get-file-archive>

    $archive = $gitlab->get_archive( :pid, [:sha], [:format] );

Get an archive of the repository.
This endpoint can be accessed without authentication if the repository is
publicly accessible.

Archive formats are

=over

=item C<tar.gz>

Default.

=item C<tar.bz2>

=item C<tbz>

=item C<tbz2>

=item C<tb2>

=item C<bz2>

=item C<tar>

=item C<zip>

=back

=item L<compare_refs()|https://docs.gitlab.com/ce/api/repositories.html#compare-branches-tags-or-commits>

    $cmp = $gitlab->compare_refs( :pid, :from, :to, [:straight] );

Compare branches, tags or commits.

=item L<contributors()|https://docs.gitlab.com/ce/api/repositories.html#contributors>

    $list = $gitlab->contributors( :pid, [:order_by], [:sort] );

Get repository contributors list. This endpoint can be accessed without
authentication if the repository is publicly accessible.

=item L<merge_base()|https://docs.gitlab.com/ce/api/repositories.html#merge-base>

    $base = $gitlab->merge_base( :id, :refs );

Get the common ancestor for 2 refs (commit SHAs, branch names or tags).

=head1 AUTHOR

Roman Lacko <L<xlacko1@fi.muni.cz>>

=head1 SEE ALSO

=over

=item L<GitLab>

Wrapper around L<GitLab::API> and other C<GitLab::*> modules.

=back