You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

api_repo_file_helpers.go 962B

12345678910111213141516171819202122232425262728
  1. // Copyright 2019 The Gitea Authors. All rights reserved.
  2. // Use of this source code is governed by a MIT-style
  3. // license that can be found in the LICENSE file.
  4. package integrations
  5. import (
  6. "code.gitea.io/gitea/models"
  7. user_model "code.gitea.io/gitea/models/user"
  8. api "code.gitea.io/gitea/modules/structs"
  9. files_service "code.gitea.io/gitea/services/repository/files"
  10. )
  11. func createFileInBranch(user *user_model.User, repo *models.Repository, treePath, branchName, content string) (*api.FileResponse, error) {
  12. opts := &files_service.UpdateRepoFileOptions{
  13. OldBranch: branchName,
  14. TreePath: treePath,
  15. Content: content,
  16. IsNewFile: true,
  17. Author: nil,
  18. Committer: nil,
  19. }
  20. return files_service.CreateOrUpdateRepoFile(repo, user, opts)
  21. }
  22. func createFile(user *user_model.User, repo *models.Repository, treePath string) (*api.FileResponse, error) {
  23. return createFileInBranch(user, repo, treePath, repo.DefaultBranch, "This is a NEW file")
  24. }