code.gitea.io/gitea@v1.21.7/services/convert/wiki.go (about)

     1  // Copyright 2021 The Gitea Authors. All rights reserved.
     2  // SPDX-License-Identifier: MIT
     3  
     4  package convert
     5  
     6  import (
     7  	"time"
     8  
     9  	"code.gitea.io/gitea/modules/git"
    10  	api "code.gitea.io/gitea/modules/structs"
    11  )
    12  
    13  // ToWikiCommit convert a git commit into a WikiCommit
    14  func ToWikiCommit(commit *git.Commit) *api.WikiCommit {
    15  	return &api.WikiCommit{
    16  		ID: commit.ID.String(),
    17  		Author: &api.CommitUser{
    18  			Identity: api.Identity{
    19  				Name:  commit.Author.Name,
    20  				Email: commit.Author.Email,
    21  			},
    22  			Date: commit.Author.When.UTC().Format(time.RFC3339),
    23  		},
    24  		Committer: &api.CommitUser{
    25  			Identity: api.Identity{
    26  				Name:  commit.Committer.Name,
    27  				Email: commit.Committer.Email,
    28  			},
    29  			Date: commit.Committer.When.UTC().Format(time.RFC3339),
    30  		},
    31  		Message: commit.CommitMessage,
    32  	}
    33  }
    34  
    35  // ToWikiCommitList convert a list of git commits into a WikiCommitList
    36  func ToWikiCommitList(commits []*git.Commit, total int64) *api.WikiCommitList {
    37  	result := make([]*api.WikiCommit, len(commits))
    38  	for i := range commits {
    39  		result[i] = ToWikiCommit(commits[i])
    40  	}
    41  	return &api.WikiCommitList{
    42  		WikiCommits: result,
    43  		Count:       total,
    44  	}
    45  }