func AddCollaborator(ctx *context.APIContext, form api.AddCollaboratorOption) { collaborator, err := models.GetUserByName(ctx.Params(":collaborator")) if err != nil { if models.IsErrUserNotExist(err) { ctx.Error(422, "", err) } else { ctx.Error(500, "GetUserByName", err) } return } if err := ctx.Repo.Repository.AddCollaborator(collaborator); err != nil { ctx.Error(500, "AddCollaborator", err) return } if form.Permission != nil { if err := ctx.Repo.Repository.ChangeCollaborationAccessMode(collaborator.ID, models.ParseAccessMode(*form.Permission)); err != nil { ctx.Error(500, "ChangeCollaborationAccessMode", err) return } } ctx.Status(204) }
// https://github.com/gogits/go-gogs-client/wiki/Repositories-Contents#download-archive func GetArchive(ctx *context.APIContext) { repoPath := models.RepoPath(ctx.Params(":username"), ctx.Params(":reponame")) gitRepo, err := git.OpenRepository(repoPath) if err != nil { ctx.Error(500, "OpenRepository", err) return } ctx.Repo.GitRepo = gitRepo repo.Download(ctx.Context) }
func GetUserByParamsName(ctx *context.APIContext, name string) *models.User { user, err := models.GetUserByName(ctx.Params(name)) if err != nil { if models.IsErrUserNotExist(err) { ctx.Status(404) } else { ctx.Error(500, "GetUserByName", err) } return nil } return user }
func GetRepositoryByParams(ctx *context.APIContext) *models.Repository { repo, err := models.GetRepositoryByName(ctx.Org.Team.OrgID, ctx.Params(":reponame")) if err != nil { if models.IsErrRepoNotExist(err) { ctx.Status(404) } else { ctx.Error(500, "GetRepositoryByName", err) } return nil } return repo }
// https://github.com/gogits/go-gogs-client/wiki/Repositories#get-branch func GetBranch(ctx *context.APIContext) { branch, err := ctx.Repo.Repository.GetBranch(ctx.Params(":branchname")) if err != nil { ctx.Error(500, "GetBranch", err) return } c, err := branch.GetCommit() if err != nil { ctx.Error(500, "GetCommit", err) return } ctx.JSON(200, convert.ToBranch(branch, c)) }
func CreateOrgRepo(ctx *context.APIContext, opt api.CreateRepoOption) { org, err := models.GetOrgByName(ctx.Params(":org")) if err != nil { if models.IsErrUserNotExist(err) { ctx.Error(422, "", err) } else { ctx.Error(500, "GetOrgByName", err) } return } if !org.IsOwnedBy(ctx.User.Id) { ctx.Error(403, "", "Given user is not owner of organization.") return } CreateUserRepo(ctx, org, opt) }
func GetInfo(ctx *context.APIContext) { u, err := models.GetUserByName(ctx.Params(":username")) if err != nil { if models.IsErrUserNotExist(err) { ctx.Status(404) } else { ctx.Error(500, "GetUserByName", err) } return } // Hide user e-mail when API caller isn't signed in. if !ctx.IsSigned { u.Email = "" } ctx.JSON(200, convert.ToUser(u)) }
// https://github.com/gogits/go-gogs-client/wiki/Users#get-a-single-user func GetInfo(ctx *context.APIContext) { u, err := models.GetUserByName(ctx.Params(":username")) if err != nil { if models.IsErrUserNotExist(err) { ctx.Status(404) } else { ctx.Error(500, "GetUserByName", err) } return } // Hide user e-mail when API caller isn't signed in. if !ctx.IsSigned { u.Email = "" } ctx.JSON(200, &api.User{u.ID, u.Name, u.FullName, u.Email, u.AvatarLink()}) }
func GetEditorconfig(ctx *context.APIContext) { ec, err := ctx.Repo.GetEditorconfig() if err != nil { if git.IsErrNotExist(err) { ctx.Error(404, "GetEditorconfig", err) } else { ctx.Error(500, "GetEditorconfig", err) } return } fileName := ctx.Params("filename") def := ec.GetDefinitionForFilename(fileName) if def == nil { ctx.Error(404, "GetDefinitionForFilename", err) return } ctx.JSON(200, def) }
func parseOwnerAndRepo(ctx *context.APIContext) (*models.User, *models.Repository) { owner, err := models.GetUserByName(ctx.Params(":username")) if err != nil { if models.IsErrUserNotExist(err) { ctx.Error(422, "", err) } else { ctx.Error(500, "GetUserByName", err) } return nil, nil } repo, err := models.GetRepositoryByName(owner.Id, ctx.Params(":reponame")) if err != nil { if models.IsErrRepoNotExist(err) { ctx.Status(404) } else { ctx.Error(500, "GetRepositoryByName", err) } return nil, nil } return owner, repo }