1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042
|
package Net::GitHub::V3::Repos;
use Moo;
our $VERSION = '1.05';
our $AUTHORITY = 'cpan:FAYLAND';
use Carp;
use URI::Escape;
use URI;
use HTTP::Request::Common qw(POST);
with 'Net::GitHub::V3::Query';
sub list {
my ( $self, $args ) = @_;
return $self->query(_repos_arg2url($args));
}
sub next_repo {
my ( $self, $args ) = @_;
return $self->next(_repos_arg2url($args));
}
sub close_repo {
my ( $self, $args ) = @_;
return $self->close(_repos_arg2url($args));
}
sub _repos_arg2url {
my ($args) = @_;
# for old
unless (ref($args) eq 'HASH') {
$args = { type => $args };
}
my $uri = URI->new('/user/repos');
$uri->query_form($args);
return $uri->as_string;
}
sub list_all {
my ( $self, $since ) = @_;
return $self->query(_all_repos_arg2url($since));
}
sub next_all_repo {
my ( $self, $since ) = @_;
return $self->next(_all_repos_arg2url($since));
}
sub close_all_repo {
my ( $self, $since ) = @_;
return $self->close(_all_repos_arg2url($since));
}
sub _all_repos_arg2url {
my ( $since ) = @_;
$since ||= 'first';
my $u = '/repositories';
$u .= '?since=' . $since if $since ne 'first';
return $u;
}
sub list_user {
my $self = shift;
return $self->query($self->_user_repos_arg2url(@_));
}
sub next_user_repo {
my $self = shift;
return $self->next($self->_user_repos_arg2url(@_));
}
sub close_user_repo {
my $self = shift;
return $self->close($self->_user_repos_arg2url(@_));
}
sub _user_repos_arg2url {
my ($self, $user, $args) = @_;
$user ||= $self->u;
# for old
unless (ref($args) eq 'HASH') {
$args = { type => $args };
}
my $uri = URI->new("/users/" . uri_escape($user) . "/repos");
$uri->query_form($args);
return $uri->as_string;
}
sub list_org {
my $self = shift;
return $self->query($self->_org_repos_arg2url(@_));
}
sub next_org_repo {
my $self = shift;
return $self->next($self->_org_repos_arg2url(@_));
}
sub close_org_repo {
my $self = shift;
return $self->close($self->_org_repos_arg2url(@_));
}
sub _org_repos_arg2url {
my ($self, $org, $type) = @_;
$type ||= 'all';
my $u = "/orgs/" . uri_escape($org) . "/repos";
$u .= '?type=' . $type if $type ne 'all';
return $u;
}
sub create {
my ( $self, $data ) = @_;
my $u = '/user/repos';
if (exists $data->{org}) {
my $o = delete $data->{org};
$u = "/orgs/" . uri_escape($o) . "/repos";
}
return $self->query('POST', $u, $data);
}
sub upload_asset {
my $self = shift;
unshift @_, $self->u, $self->repo if @_ < 5;
my ($user, $repos, $release_id, $name, $content_type, $file_content) = @_;
my $ua = $self->ua;
my $url = $self->upload_url . "/repos/$user/$repos/releases/$release_id/assets?name=" . uri_escape($name);
my $req = HTTP::Request->new( 'POST', $url );
$req->accept_decodable;
$req->content($file_content);
$req->header( 'Content-Type', $content_type );
my $res = $ua->request($req);
my $data;
if ($res->header('Content-Type') and $res->header('Content-Type') =~ 'application/json') {
my $json = $res->decoded_content;
$data = eval { $self->json->decode($json) };
unless ($data) {
# We tolerate bad JSON for errors,
# otherwise we just rethrow the JSON parsing problem.
die unless $res->is_error;
$data = { message => $res->message };
}
} else {
$data = { message => $res->message };
}
return wantarray ? %$data : $data;
}
sub commits {
my $self = shift;
return $self->query($self->_commits_arg2url(@_));
}
sub next_commit {
my $self = shift;
return $self->next($self->_commits_arg2url(@_));
}
sub close_commit {
my $self = shift;
return $self->close($self->_commits_arg2url(@_));
}
sub _commits_arg2url {
my $self = shift;
if (@_ < 2) {
unshift @_, $self->repo;
unshift @_, $self->u;
}
my ($user, $repos, $args) = @_;
my $uri = URI->new("/repos/" . uri_escape($user) . "/" . uri_escape($repos) . '/commits');
$uri->query_form($args);
return $uri->as_string;
}
sub list_deployments {
my $self = shift;
return $self->query($self->deployments_arg2url(@_));
}
sub next_deployment {
my $self = shift;
return $self->next($self->deployments_arg2url(@_));
}
sub close_deployment {
my $self = shift;
return $self->close($self->deployments_arg2url(@_));
}
sub _deployments_arg2url {
my $self = shift;
if (@_ < 2) {
unshift @_, $self->repo;
unshift @_, $self->u;
}
my ($user, $repos, $args) = @_;
my $uri = URI->new("/repos/" . uri_escape($user) . "/" . uri_escape($repos) . '/deployments');
$uri->query_form($args);
return $uri->as_string;
}
## build methods on fly
my %__methods = (
get => { url => "/repos/%s/%s" },
update => { url => "/repos/%s/%s", method => 'PATCH', args => 1 },
contributors => { url => "/repos/%s/%s/contributors", paginate => 1 },
languages => { url => "/repos/%s/%s/languages" },
teams => { url => "/repos/%s/%s/teams", paginate => 1 },
tags => { url => "/repos/%s/%s/tags", paginate => 1 },
branches => { url => "/repos/%s/%s/branches", paginate => 1 },
branch => { url => "/repos/%s/%s/branches/%s" },
delete => { url => "/repos/%s/%s", method => 'DELETE', check_status => 204 },
# http://developer.github.com/v3/repos/collaborators/
collaborators => { url => "/repos/%s/%s/collaborators", paginate => 1 },
is_collaborator => { url => "/repos/%s/%s/collaborators/%s", check_status => 204 },
add_collaborator => { url => "/repos/%s/%s/collaborators/%s", method => 'PUT', check_status => 204 },
delete_collaborator => { url => "/repos/%s/%s/collaborators/%s", method => 'DELETE', check_status => 204 },
# http://developer.github.com/v3/repos/commits/
commit => { url => "/repos/%s/%s/commits/%s" },
comments => { url => "/repos/%s/%s/comments", paginate => 1 },
comment => { url => "/repos/%s/%s/comments/%s" },
commit_comments => { url => "/repos/%s/%s/commits/%s/comments", paginate => 1 },
create_comment => { url => "/repos/%s/%s/commits/%s/comments", method => 'POST', args => 1 },
update_comment => { url => "/repos/%s/%s/comments/%s", method => 'PATCH', args => 1 },
delete_comment => { url => "/repos/%s/%s/comments/%s", method => 'DELETE', check_status => 204 },
compare_commits => { url => "/repos/%s/%s/compare/%s...%s" },
# http://developer.github.com/v3/repos/contents/
readme => { url => "/repos/%s/%s/readme" },
get_content => { url => "/repos/:owner/:repo/contents/:path", v => 2 },
# http://developer.github.com/v3/repos/downloads/
downloads => { url => "/repos/%s/%s/downloads", paginate => 1 },
download => { url => "/repos/%s/%s/downloads/%s" },
delete_download => { url => "/repos/%s/%s/downloads/%s", method => 'DELETE', check_status => 204 },
# http://developer.github.com/v3/repos/releases/
releases => { url => "/repos/%s/%s/releases", paginate => 1 },
release => { url => "/repos/%s/%s/releases/%s" },
create_release => { url => "/repos/%s/%s/releases", method => 'POST', args => 1 },
update_release => { url => "/repos/%s/%s/releases/%s", method => 'PATCH', args => 1 },
delete_release => { url => "/repos/%s/%s/releases/%s", method => 'DELETE', check_status => 204 },
release_assets => { url => "/repos/%s/%s/releases/%s/assets", paginate => 1 },
release_asset => { url => "/repos/%s/%s/releases/%s/assets/%s" },
update_release_asset => { url => "/repos/%s/%s/releases/%s/assets/%s", method => 'PATCH', args => 1 },
delete_release_asset => { url => "/repos/%s/%s/releases/%s/assets/%s", method => 'DELETE', check_status => 204 },
forks => { url => "/repos/%s/%s/forks", paginate => 1 },
# http://developer.github.com/v3/repos/keys/
keys => { url => "/repos/%s/%s/keys", paginate => 1 },
key => { url => "/repos/%s/%s/keys/%s" },
create_key => { url => "/repos/%s/%s/keys", method => 'POST', args => 1 },
update_key => { url => "/repos/%s/%s/keys/%s", method => 'PATCH', check_status => 204, args => 1 },
delete_key => { url => "/repos/%s/%s/keys/%s", method => 'DELETE', check_status => 204 },
# http://developer.github.com/v3/repos/watching/
watchers => { url => "/repos/%s/%s/watchers", paginate => 1 },
is_watching => { url => "/user/watched/%s/%s", is_u_repo => 1, check_status => 204 },
watch => { url => "/user/watched/%s/%s", is_u_repo => 1, method => 'PUT', check_status => 204 },
unwatch => { url => "/user/watched/%s/%s", is_u_repo => 1, method => 'DELETE', check_status => 204 },
subscribers => { url => "/repos/%s/%s/subscribers", paginate => 1 },
subscription => { url => "/repos/%s/%s/subscription" },
is_subscribed => { url => "/repos/%s/%s/subscription", check_status => 200 },
subscribe => { url => "/repos/%s/%s/subscription", method => 'PUT',
check_status => 200, args => 1 },
unsubscribe => { url => "/repos/%s/%s/subscription", method => 'DELETE', check_status => 204 },
# http://developer.github.com/v3/repos/hooks/
hooks => { url => "/repos/%s/%s/hooks", paginate => 1 },
hook => { url => "/repos/%s/%s/hooks/%s" },
delete_hook => { url => "/repos/%s/%s/hooks/%s", method => 'DELETE', check_status => 204 },
test_hook => { url => "/repos/%s/%s/hooks/%s/test", method => 'POST', check_status => 204 },
create_hook => { url => "/repos/%s/%s/hooks", method => 'POST', args => 1 },
update_hook => { url => "/repos/%s/%s/hooks/%s", method => 'PATCH', args => 1 },
# http://developer.github.com/v3/repos/merging/
merges => { url => "/repos/%s/%s/merges", method => 'POST', args => 1 },
# http://developer.github.com/v3/repos/statuses/
list_statuses => { url => "/repos/%s/%s/statuses/%s", paginate => { name => 'status' } },
create_status => { url => "/repos/%s/%s/statuses/%s", method => 'POST', args => 1 },
# https://developer.github.com/v3/repos/deployments
create_deployment => { url => "/repos/%s/%s/deployments", method => 'POST', args => 1 },
create_deployment_status => { url => "/repos/%s/%s/deployments/%s/statuses", method => 'POST', args => 1},
list_deployment_statuses => { url => "/repos/%s/%s/deployments/%s/statuses", method => 'GET', paginate => { name => 'deployment_status' } },
contributor_stats => { url => "/repos/%s/%s/stats/contributors", method => 'GET'},
commit_activity => { url => "/repos/%s/%s/stats/commit_activity", method => 'GET'},
code_frequency => { url => "/repos/%s/%s/stats/code_frequency", method => 'GET'},
participation => { url => "/repos/%s/%s/stats/participation", method => 'GET'},
punch_card => { url => "/repos/%s/%s/stats/punch_card", method => 'GET'},
# https://docs.github.com/en/rest/branches/branch-protection
branch_protection => { url => "/repos/%s/%s/branches/%s/protection", method => 'GET'},
delete_branch_protection => { url => "/repos/%s/%s/branches/%s/protection", method => 'DELETE', check_status => 204 },
update_branch_protection => { url => "/repos/%s/%s/branches/%s/protection", method => 'PUT', args => 1 },
);
__build_methods(__PACKAGE__, %__methods);
sub create_download {
my $self = shift;
if (@_ == 1) {
unshift @_, $self->repo;
unshift @_, $self->u;
}
my ($user, $repos, $download) = @_;
my $file = delete $download->{file};
my $u = "/repos/" . uri_escape($user) . "/" . uri_escape($repos) . '/downloads';
my $d = $self->query('POST', $u, $download);
if (defined $file) {
return $self->upload_download($d, $file);
} else {
return $d;
}
}
sub upload_download {
my $self = shift;
if (@_ < 3) {
unshift @_, $self->repo;
unshift @_, $self->u;
}
my ($user, $repos, $download, $file) = @_;
# must successful on create_download
return 0 unless exists $download->{s3_url};
## POST form-data
my %data = (
Content_Type => 'form-data',
Content => [
'key' => $download->{path},
'acl' => $download->{acl},
'success_action_status' => 201,
'Filename' => $download->{name},
'AWSAccessKeyId' => $download->{accesskeyid},
'Policy' => $download->{policy},
'Signature' => $download->{signature},
'Content-Type' => $download->{mime_type},
'file' => [ $file ],
],
);
my $request = POST $download->{s3_url}, %data;
my $res = $self->ua->request($request);
return $res->code == 201 ? 1 : 0;
}
## http://developer.github.com/v3/repos/forks/
sub create_fork {
my $self = shift;
if (@_ < 2) {
unshift @_, $self->repo;
unshift @_, $self->u;
}
my ($user, $repos, $org) = @_;
my $u = "/repos/" . uri_escape($user) . "/" . uri_escape($repos) . '/forks';
$u .= '?org=' . $org if defined $org;
return $self->query('POST', $u);
}
## http://developer.github.com/v3/repos/watching/
sub watched {
my ($self, $user) = @_;
my $u = $user ? '/users/' . uri_escape($user). '/watched' : '/user/watched';
return $self->query($u);
}
no Moo;
1;
__END__
=head1 NAME
Net::GitHub::V3::Repos - GitHub Repos API
=head1 SYNOPSIS
use Net::GitHub::V3;
my $gh = Net::GitHub::V3->new; # read L<Net::GitHub::V3> to set right authentication info
my $repos = $gh->repos;
# set :user/:repo for simple calls
$repos->set_default_user_repo('fayland', 'perl-net-github');
my @contributors = $repos->contributors; # don't need pass user and repos
=head1 DESCRIPTION
=head2 METHODS
=head3 Repos
L<http://developer.github.com/v3/repos/>
=over 4
=item list
=item list_all
# All public repositories on Github
my @rp = $repos->list_all;
# starting at id 500
my @rp = $repos->list_all(500);
=item list_user
=item list_org
my @rp = $repos->list; # or my $rp = $repos->list;
my @rp = $repos->list({
type => 'private'
sort => 'updated'
});
my @rp = $repos->list_user('c9s');
my @rp = $repos->list_user('c9s', {
type => 'member'
});
my @rp = $repos->list_org('perlchina');
my @rp = $repos->list_org('perlchina', 'public');
=item next_repo, next_all_repo, next_user_repo, next_org_repo
# Iterate over your repositories
while (my $repo = $repos->next_repo) { ...; }
# Iterate over all public repositories
while (my $repo = $repos->next_all_repo(500)) { ...; }
# Iterate over repositories of another user
while (my $repo = $repos->next_user_repo('c9s')) { ...; }
# Iterate over repositories of an organisation
while (my $repo = $repos->next_org_repo('perlchina','public')) { ...; }
=item create
# create for yourself
my $rp = $repos->create( {
"name" => "Hello-World",
"description" => "This is your first repo",
"homepage" => "https://github.com"
} );
# create for organization
my $rp = $repos->create( {
"org" => "perlchina", ## the organization
"name" => "Hello-World",
"description" => "This is your first repo",
"homepage" => "https://github.com"
} );
=item get
my $rp = $repos->get('fayland', 'perl-net-github');
=back
B<To ease the keyboard, we provied two ways to call any method which starts with :user/:repo>
1. SET user/repos before call methods below
$gh->set_default_user_repo('fayland', 'perl-net-github'); # take effects for all $gh->
$repos->set_default_user_repo('fayland', 'perl-net-github'); # only take effect to $gh->repos
my @contributors = $repos->contributors;
2. If it is just for once, we can pass :user, :repo before any arguments
my @contributors = $repos->contributors($user, $repo);
=over 4
=item update
$repos->update({ homepage => 'https://metacpan.org/module/Net::GitHub' });
=item delete
$repos->delete();
=item contributors
=item languages
=item teams
=item tags
=item contributors
my @contributors = $repos->contributors;
my @languages = $repos->languages;
my @teams = $repos->teams;
my @tags = $repos->tags;
my @branches = $repos->branches;
my $branch = $repos->branch('master');
while (my $contributor = $repos->next_contributor) { ...; }
while (my $team = $repos->next_team) { ... ; }
while (my $tags = $repos->next_tag) { ... ; }
=back
=head3 Repo Collaborators API
L<http://developer.github.com/v3/repos/collaborators/>
=over 4
=item collaborators
=item is_collaborator
=item add_collaborator
=item delete_collaborator
my @collaborators = $repos->collaborators;
while (my $collaborator = $repos->next_collaborator) { ...; }
my $is = $repos->is_collaborator('fayland');
$repos->add_collaborator('fayland');
$repos->delete_collaborator('fayland');
=back
=head3 Commits API
L<http://developer.github.com/v3/repos/commits/>
=over 4
=item commits
=item commit
my @commits = $repos->commits;
my @commits = $repos->commits({
author => 'fayland'
});
my $commit = $repos->commit($sha);
while (my $commit = $repos->next_commit({...})) { ...; }
=item comments
=item commit_comments
=item create_comment
=item comment
=item update_comment
=item delete_comment
my @comments = $repos->comments;
while (my $comment = $repos->next_comment) { ...; }
my @comments = $repos->commit_comments($sha);
while (my $comment = $repos->next_commit_comment($sha)) { ...; }
my $comment = $repos->create_comment($sha, {
"body" => "Nice change",
"commit_id" => "6dcb09b5b57875f334f61aebed695e2e4193db5e",
"line" => 1,
"path" => "file1.txt",
"position" => 4
});
my $comment = $repos->comment($comment_id);
my $comment = $repos->update_comment($comment_id, {
"body" => "Nice change"
});
my $st = $repos->delete_comment($comment_id);
=item compare_commits
my $diffs = $repos->compare_commits($base, $head);
=back
=head3 Forks API
L<http://developer.github.com/v3/repos/forks/>
=over 4
=item forks
=item create_fork
my @forks = $repos->forks;
while (my $fork = $repos->next_fork) { ...; }
my $fork = $repos->create_fork;
my $fork = $repos->create_fork($org);
=back
=head3 Repos Deploy Keys API
L<http://developer.github.com/v3/repos/keys/>
=over 4
=item keys
=item key
=item create_key
=item update_key
=item delete_key
my @keys = $repos->keys;
while (my $key = $repos->next_key) { ...; }
my $key = $repos->key($key_id); # get key
$repos->create_key( {
title => 'title',
key => $key
} );
$repos->update_key($key_id, {
title => $title,
key => $key
});
$repos->delete_key($key_id);
=back
=head3 Repo Watching API
L<http://developer.github.com/v3/repos/watching/>
=over 4
=item watchers
my @watchers = $repos->watchers;
while (my $watcher = $repos->next_watcher) { ...; }
=item watched
my @repos = $repos->watched; # what I watched
my @repos = $repos->watched('c9s');
=item is_watching
my $is_watching = $repos->is_watching;
my $is_watching = $repos->is_watching('fayland', 'perl-net-github');
=item watch
=item unwatch
my $st = $repos->watch();
my $st = $repos->watch('fayland', 'perl-net-github');
my $st = $repos->unwatch();
my $st = $repos->unwatch('fayland', 'perl-net-github');
=back
=head3 Subscriptions
Github changed the ideas of Watchers (stars) and Subscriptions (new watchers).
https://github.com/blog/1204-notifications-stars
The Watchers code in this module predates the terminology change, so the new
Watcher methods use the GitHub 'subscription' terminology.
=over 4
=item subscribers
Returns a list of subscriber data hashes.
=item next_subscriber
Returns the next subscriber in the list, or undef if there are no more subscribers.
=item is_subscribed
Returns true or false if you are subscribed
$repos->is_subscribed();
$repos->is_subscribed('fayland','perl-net-github');
=item subscription
Returns more information about your subscription to a repo.
is_subscribed is a shortcut to calling this and checking for
subscribed => 1.
=item subscribe
Required argument telling github if you want to subscribe or if you want
to ignore mentions. If you want to change from subscribed to ignores you
need to unsubscribe first.
$repos->subscribe('fayland','perl-net-github', { subscribed => 1 })
$repos->subscribe('fayland','perl-net-github', { ignored => 1 })
=item unsubscribe
$repos->unsubscribe('fayland','perl-net-github');
=back
=head3 Hooks API
L<http://developer.github.com/v3/repos/hooks/>
=over 4
=item hooks
=item next_hook
=item hook
=item create_hook
=item update_hook
=item test_hook
=item delete_hook
my @hooks = $repos->hooks;
while (my $hook = $repos->next_hook) { ...; }
my $hook = $repos->hook($hook_id);
my $hook = $repos->create_hook($hook_hash);
my $hook = $repos->update_hook($hook_id, $new_hook_hash);
my $st = $repos->test_hook($hook_id);
my $st = $repos->delete_hook($hook_id);
=back
=head3 Repo Merging API
L<http://developer.github.com/v3/repos/merging/>
=over 4
=item merges
my $status = $repos->merges( {
"base" => "master",
"head" => "cool_feature",
"commit_message" => "Shipped cool_feature!"
} );
=back
=head3 Repo Statuses API
L<http://developer.github.com/v3/repos/statuses/>
=over 4
=item list_statuses
$gh->set_default_user_repo('fayland', 'perl-net-github');
my @statuses = $repos->lists_statuses($sha);
Or:
my @statuses = $repos->list_statuses('fayland', 'perl-net-github', $sha);
=item next_status
while (my $status = $repos->next_status($sha)) { ...; }
=item create_status
$gh->set_default_user_repo('fayland', 'perl-net-github');
my %payload = {
"state" => "success",
"target_url" => "https://example.com/build/status",
"description" => "The build succeeded!",
"context" => "build/status"
};
my $status = $repos->create_status($sha, %payload);
Or:
my %payload = {
"state" => "success",
"target_url" => "https://example.com/build/status",
"description" => "The build succeeded!",
"context" => "build/status"
};
my $status = $repos->create_status(
'fayland', 'perl-net-github', $sha, %payload
);
=back
=head3 Repo Releases API
L<http://developer.github.com/v3/repos/releases/>
=over 4
=item releases
my @releases = $repos->releases();
while (my $release = $repos->next_release) { ...; }
=item release
my $release = $repos->release($release_id);
=item create_release
my $release = $repos->create_release({
"tag_name" => "v1.0.0",
"target_commitish" => "master",
"name" => "v1.0.0",
"body" => "Description of the release",
"draft" => \1,
});
=item update_release
my $release = $repos->update_release($release_id, {
"tag_name" => "v1.0.0",
"target_commitish" => "master",
"name" => "v1.0.0",
"body" => "Description of the release",
});
=item delete_release
$repos->delete_release($release_id);
=item release_assets
my @release_assets = $repos->release_assets($release_id);
while (my $asset = $repos->next_release_asset($release_id)) { ...; }
=item upload_asset
my $asset = $repos->upload_asset($release_id, $name, $content_type, $file_content);
Check examples/upload_asset.pl for a working example.
=item release_asset
my $release_asset = $repos->release_asset($release_id, $asset_id);
=item update_release_asset
my $release_asset = $repos->update_release_asset($release_id, $asset_id, {
name" => "foo-1.0.0-osx.zip",
"label" => "Mac binary"
});
=item delete_release_asset
my $ok = $repos->delete_release_asset($release_id, $asset_id);
=back
=head3 Contents API
L<https://developer.github.com/v3/repos/contents/>
=over 4
=item get_content
Gets the contents of a file or directory in a repository.
Specify the file path or directory in $path.
If you omit $path, you will receive the contents of all files in the repository.
my $response = $repos->get_content( $owner, $repo, $path )
or
$repos->get_content(
{ owner => $owner, repo => $repo, path => $path },
)
or
$repos->get_content(
{ owner => $owner, repo => $repo, path => $path },
{ ref => 'feature-branch' }
)
=back
=head3 Repo Deployment API
L<http://developer.github.com/v3/repos/deployments/>
=over 4
=item list_deployments
my $response = $repos->list_deployments( $owner, $repo, {
'ref' => 'feature-branch',
});
=item next_deployment
while (my $deployment = $repos->next_deployment( $owner, $repo, {
'ref' => 'feature-branch',
}) { ...; }
=item create_deployment
my $response = $repos->create_deployment( $owner, $repo, {
"ref" => 'feature-branch',
"description" => "deploying my new feature",
});
=item list_deployment_statuses
my $response = $repos->list_deployment_statuses( $owner, $repo, $deployment_id );
=item next_deployment_status
while (my $status = next_deployment_status($o,$r,$id)) { ...; }
=item create_deployment_status
my $response = $repos->create_deployment_status( $owner, $repo, $deployment_id, {
"state": "success",
"target_url": "https://example.com/deployment/42/output",
"description": "Deployment finished successfully."
});
=back
=head3 Repo Statistics API
L<http://developer.github.com/v3/repos/statistics/>
=over 4
=item contributor stats
=item commit activity
=item code frequency
=item participation
=item punch card
my $contributor_stats = $repos->contributor_stats($owner, $repo);
my $commit_activity = $repos->commit_activity($owner, $repo);
my $code_freq = $repos->code_frequency($owner, $repo);
my $participation = $repos->participation($owner, $repo);
my $punch_card = $repos->punch_card($owner, $repo);
=back
=head3 Branch Protection API
L<https://docs.github.com/en/rest/branches/branch-protection>
=over 4
=item branch_protection
my $protection = $repos->branch_protection('fayland', 'perl-net-github', 'master');
=item delete_branch_protection
$repos->delete_branch_protection('fayland', 'perl-net-github', 'master');
=item update_branch_protection
$repos->update_branch_protection('fayland', 'perl-net-github', 'master', {
allow_deletions => \0,
allow_force_pushes => \0,
block_creations => \1,
enforce_admins => \1,
required_conversation_resolution => \1,
required_linear_history => \0,
required_pull_request_reviews => {
dismiss_stale_reviews => \1,
require_code_owner_reviews => \1,
required_approving_review_count => 2,
},
required_status_checks => {
strict => \1,
contexts => []
},
restrictions => undef,
});
=back
=head1 AUTHOR & COPYRIGHT & LICENSE
Refer L<Net::GitHub>
|