aboutsummaryrefslogtreecommitdiffstats
path: root/services/repository/repository.go
diff options
context:
space:
mode:
authorJohn Olheiser <42128690+jolheiser@users.noreply.github.com>2019-12-14 20:49:52 -0600
committerLunny Xiao <xiaolunwen@gmail.com>2019-12-15 10:49:52 +0800
commit6715677b2bf7a065d0184ea7f2647e70ca2598d4 (patch)
treeec2ed74b0eb153391bd46a9552923b2282867be5 /services/repository/repository.go
parent47c24be293ac8b1b28310d2fb2be58b8191a5bae (diff)
downloadgitea-6715677b2bf7a065d0184ea7f2647e70ca2598d4.tar.gz
gitea-6715677b2bf7a065d0184ea7f2647e70ca2598d4.zip
Push to create repo (#8419)
* Refactor Signed-off-by: jolheiser <john.olheiser@gmail.com> * Add push-create to SSH serv Signed-off-by: jolheiser <john.olheiser@gmail.com> * Cannot push for another user unless admin Signed-off-by: jolheiser <john.olheiser@gmail.com> * Get owner in case admin pushes for another user Signed-off-by: jolheiser <john.olheiser@gmail.com> * Set new repo ID in result Signed-off-by: jolheiser <john.olheiser@gmail.com> * Update to service and use new org perms Signed-off-by: jolheiser <john.olheiser@gmail.com> * Move pushCreateRepo to services Signed-off-by: jolheiser <john.olheiser@gmail.com> * Fix import order Signed-off-by: jolheiser <john.olheiser@gmail.com> * Changes for @guillep2k * Check owner (not user) in SSH * Add basic tests for created repos (private, not empty) Signed-off-by: jolheiser <john.olheiser@gmail.com>
Diffstat (limited to 'services/repository/repository.go')
-rw-r--r--services/repository/repository.go27
1 files changed, 27 insertions, 0 deletions
diff --git a/services/repository/repository.go b/services/repository/repository.go
index 5135435c78..2fb45bb617 100644
--- a/services/repository/repository.go
+++ b/services/repository/repository.go
@@ -5,6 +5,8 @@
package repository
import (
+ "fmt"
+
"code.gitea.io/gitea/models"
"code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/notification"
@@ -54,3 +56,28 @@ func DeleteRepository(doer *models.User, repo *models.Repository) error {
return nil
}
+
+// PushCreateRepo creates a repository when a new repository is pushed to an appropriate namespace
+func PushCreateRepo(authUser, owner *models.User, repoName string) (*models.Repository, error) {
+ if !authUser.IsAdmin {
+ if owner.IsOrganization() {
+ if ok, err := owner.CanCreateOrgRepo(authUser.ID); err != nil {
+ return nil, err
+ } else if !ok {
+ return nil, fmt.Errorf("cannot push-create repository for org")
+ }
+ } else if authUser.ID != owner.ID {
+ return nil, fmt.Errorf("cannot push-create repository for another user")
+ }
+ }
+
+ repo, err := CreateRepository(authUser, owner, models.CreateRepoOptions{
+ Name: repoName,
+ IsPrivate: true,
+ })
+ if err != nil {
+ return nil, err
+ }
+
+ return repo, nil
+}