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.

45 lines
1.4 KiB

  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 models
  5. import (
  6. "fmt"
  7. "os"
  8. "strings"
  9. )
  10. // PushingEnvironment returns an os environment to allow hooks to work on push
  11. func PushingEnvironment(doer *User, repo *Repository) []string {
  12. return FullPushingEnvironment(doer, doer, repo, 0)
  13. }
  14. // FullPushingEnvironment returns an os environment to allow hooks to work on push
  15. func FullPushingEnvironment(author, committer *User, repo *Repository, prID int64) []string {
  16. isWiki := "false"
  17. if strings.HasSuffix(repo.Name, ".wiki") {
  18. isWiki = "true"
  19. }
  20. authorSig := author.NewGitSig()
  21. committerSig := committer.NewGitSig()
  22. // We should add "SSH_ORIGINAL_COMMAND=gitea-internal",
  23. // once we have hook and pushing infrastructure working correctly
  24. return append(os.Environ(),
  25. "GIT_AUTHOR_NAME="+authorSig.Name,
  26. "GIT_AUTHOR_EMAIL="+authorSig.Email,
  27. "GIT_COMMITTER_NAME="+committerSig.Name,
  28. "GIT_COMMITTER_EMAIL="+committerSig.Email,
  29. EnvRepoName+"="+repo.Name,
  30. EnvRepoUsername+"="+repo.MustOwnerName(),
  31. EnvRepoIsWiki+"="+isWiki,
  32. EnvPusherName+"="+committer.Name,
  33. EnvPusherID+"="+fmt.Sprintf("%d", committer.ID),
  34. ProtectedBranchRepoID+"="+fmt.Sprintf("%d", repo.ID),
  35. ProtectedBranchPRID+"="+fmt.Sprintf("%d", prID),
  36. "SSH_ORIGINAL_COMMAND=gitea-internal",
  37. )
  38. }