diff options
-rw-r--r-- | .gitignore | 1 | ||||
-rw-r--r-- | Changes | 7 | ||||
-rw-r--r-- | dist.ini | 7 | ||||
-rw-r--r-- | lib/API/GitForge/GitLab.pm | 28 | ||||
-rw-r--r-- | lib/API/GitForge/Role/GitForge.pm | 4 |
5 files changed, 38 insertions, 9 deletions
@@ -1 +1,2 @@ /API-GitForge-* +/.build @@ -2,5 +2,12 @@ Revision history for API::GitForge {{$NEXT}} +0.002 2020-03-09 12:17:47-07:00 America/Phoenix + - Implement API::GitForge::GitLab::_ensure_repo(). + - Add git repo metadata to dist.ini. + - Don't disable merge requests in GitLab clean forks. + Otherwise we can't submit merge requests upstream. + - Code cleanup. + 0.001 2020-02-16 16:20:35-07:00 America/Phoenix - First public release. @@ -4,7 +4,7 @@ license = GPL_3 copyright_holder = Sean Whitton <spwhitton@spwhitton.name> copyright_year = 2017, 2020 -version = 0.001 +version = 0.002 [PkgVersion] [PodWeaver] @@ -26,3 +26,8 @@ signoff = 1 [AutoPrereqs] [Prereqs] perl = 5.028 + +[MetaResources] +repository.url = https://git.spwhitton.name/p5-API-GitForge +repository.web = https://git.spwhitton.name/p5-API-GitForge +repository.type = git diff --git a/lib/API/GitForge/GitLab.pm b/lib/API/GitForge/GitLab.pm index 7ffd844..3f38bf7 100644 --- a/lib/API/GitForge/GitLab.pm +++ b/lib/API/GitForge/GitLab.pm @@ -70,12 +70,11 @@ sub _ensure_fork { sub _assert_fork_has_parent { my ($self, $upstream) = @_; - my (undef, $repo) = _extract_project_id($upstream); + my ($path, $repo) = _extract_project_id($upstream); my $user = $self->{_api}->current_user->{username}; my $fork = $self->{_api}->project("$user/$repo"); - $upstream =~ s/\.git$//; - $fork->{forked_from_project}{path_with_namespace} eq $upstream + $fork->{forked_from_project}{path_with_namespace} eq $path . "/" . $repo or croak "$user/$repo does not have parent $upstream; don't know what to do"; } @@ -101,15 +100,28 @@ sub _clean_config_fork { $self->{_api}->edit_project( "$user/$repo", { - default_branch => "gitforge", - description => "Temporary fork for merge request(s)", + default_branch => "gitforge", + description => "Temporary fork for merge request(s)", + issues_access_level => "disabled", + # merge requests have to be enabled in the fork in order + # to submit merge requests to the upstream repo from which + # we forked, it seems + merge_requests_access_level => "enabled", }); - - $self->_clean_config_repo("$user/$repo"); } sub _ensure_repo { - die "unimplemented"; + my ($self, $target) = @_; + my ($ns, $repo) = _extract_project_id($target); + + # first we are required to get the namespace id + my $namespace = $self->{_api}->namespace($ns) + or croak "invalid project namespace $ns"; + + # now create the project unless it already exists + return if $self->{_api}->project($target); + $self->{_api} + ->create_project({ name => $repo, namespace_id => $namespace->{id} }); } sub _nuke_fork { diff --git a/lib/API/GitForge/Role/GitForge.pm b/lib/API/GitForge/Role/GitForge.pm index 933b166..bacc293 100644 --- a/lib/API/GitForge/Role/GitForge.pm +++ b/lib/API/GitForge/Role/GitForge.pm @@ -126,6 +126,10 @@ sub clean_fork { $self->_clean_config_fork(@_); + # TODO use API to unprotect all branches in the fork. we still + # want to use git-push(1) to delete the branches, rather than + # using the API for that, because that's maximally compatible + # assume that if we had to create the gitforge branch, we just # created the fork, so can go ahead and nuke all branches there. # may fail if some branches are protected; that's okay. |