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.

wiki.go 1.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. // Copyright 2021 The Gitea Authors. All rights reserved.
  2. // SPDX-License-Identifier: MIT
  3. package convert
  4. import (
  5. "time"
  6. repo_model "code.gitea.io/gitea/models/repo"
  7. "code.gitea.io/gitea/modules/git"
  8. api "code.gitea.io/gitea/modules/structs"
  9. "code.gitea.io/gitea/modules/util"
  10. wiki_service "code.gitea.io/gitea/services/wiki"
  11. )
  12. // ToWikiCommit convert a git commit into a WikiCommit
  13. func ToWikiCommit(commit *git.Commit) *api.WikiCommit {
  14. return &api.WikiCommit{
  15. ID: commit.ID.String(),
  16. Author: &api.CommitUser{
  17. Identity: api.Identity{
  18. Name: commit.Author.Name,
  19. Email: commit.Author.Email,
  20. },
  21. Date: commit.Author.When.UTC().Format(time.RFC3339),
  22. },
  23. Committer: &api.CommitUser{
  24. Identity: api.Identity{
  25. Name: commit.Committer.Name,
  26. Email: commit.Committer.Email,
  27. },
  28. Date: commit.Committer.When.UTC().Format(time.RFC3339),
  29. },
  30. Message: commit.CommitMessage,
  31. }
  32. }
  33. // ToWikiCommitList convert a list of git commits into a WikiCommitList
  34. func ToWikiCommitList(commits []*git.Commit, total int64) *api.WikiCommitList {
  35. result := make([]*api.WikiCommit, len(commits))
  36. for i := range commits {
  37. result[i] = ToWikiCommit(commits[i])
  38. }
  39. return &api.WikiCommitList{
  40. WikiCommits: result,
  41. Count: total,
  42. }
  43. }
  44. // ToWikiPageMetaData converts meta information to a WikiPageMetaData
  45. func ToWikiPageMetaData(wikiName wiki_service.WebPath, lastCommit *git.Commit, repo *repo_model.Repository) *api.WikiPageMetaData {
  46. subURL := string(wikiName)
  47. _, title := wiki_service.WebPathToUserTitle(wikiName)
  48. return &api.WikiPageMetaData{
  49. Title: title,
  50. HTMLURL: util.URLJoin(repo.HTMLURL(), "wiki", subURL),
  51. SubURL: subURL,
  52. LastCommit: ToWikiCommit(lastCommit),
  53. }
  54. }