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 1.0KB

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