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.

commit_status.go 1.1KB

123456789101112131415161718192021222324252627282930313233343536373839
  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 repofiles
  5. import (
  6. "fmt"
  7. "code.gitea.io/gitea/models"
  8. "code.gitea.io/gitea/modules/git"
  9. )
  10. // CreateCommitStatus creates a new CommitStatus given a bunch of parameters
  11. // NOTE: All text-values will be trimmed from whitespaces.
  12. // Requires: Repo, Creator, SHA
  13. func CreateCommitStatus(repo *models.Repository, creator *models.User, sha string, status *models.CommitStatus) error {
  14. repoPath := repo.RepoPath()
  15. // confirm that commit is exist
  16. gitRepo, err := git.OpenRepository(repoPath)
  17. if err != nil {
  18. return fmt.Errorf("OpenRepository[%s]: %v", repoPath, err)
  19. }
  20. if _, err := gitRepo.GetCommit(sha); err != nil {
  21. return fmt.Errorf("GetCommit[%s]: %v", sha, err)
  22. }
  23. if err := models.NewCommitStatus(models.NewCommitStatusOptions{
  24. Repo: repo,
  25. Creator: creator,
  26. SHA: sha,
  27. CommitStatus: status,
  28. }); err != nil {
  29. return fmt.Errorf("NewCommitStatus[repo_id: %d, user_id: %d, sha: %s]: %v", repo.ID, creator.ID, sha, err)
  30. }
  31. return nil
  32. }