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 878B

123456789101112131415161718192021222324252627
  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. "code.gitea.io/gitea/modules/repofiles"
  8. api "code.gitea.io/gitea/modules/structs"
  9. )
  10. func createFileInBranch(user *models.User, repo *models.Repository, treePath, branchName, content string) (*api.FileResponse, error) {
  11. opts := &repofiles.UpdateRepoFileOptions{
  12. OldBranch: branchName,
  13. TreePath: treePath,
  14. Content: content,
  15. IsNewFile: true,
  16. Author: nil,
  17. Committer: nil,
  18. }
  19. return repofiles.CreateOrUpdateRepoFile(repo, user, opts)
  20. }
  21. func createFile(user *models.User, repo *models.Repository, treePath string) (*api.FileResponse, error) {
  22. return createFileInBranch(user, repo, treePath, repo.DefaultBranch, "This is a NEW file")
  23. }