本站源代码
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.

46 lines
1.4KB

  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, repo.Name, 0)
  13. }
  14. // FullPushingEnvironment returns an os environment to allow hooks to work on push
  15. func FullPushingEnvironment(author, committer *User, repo *Repository, repoName string, prID int64) []string {
  16. isWiki := "false"
  17. if strings.HasSuffix(repoName, ".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+"="+repoName,
  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. }
上海开阖软件有限公司 沪ICP备12045867号-1