From 72da1d3c78795e1191dd9bb1555fc325b1f01bc0 Mon Sep 17 00:00:00 2001 From: Chris Sexton Date: Fri, 29 Nov 2019 11:07:52 -0500 Subject: [PATCH] git: order gitea commits --- plugins/git/gitea.go | 7 ++++++- plugins/git/gitea_push.go | 4 +++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/plugins/git/gitea.go b/plugins/git/gitea.go index 5674e55..47166d7 100644 --- a/plugins/git/gitea.go +++ b/plugins/git/gitea.go @@ -4,6 +4,7 @@ import ( "encoding/json" "fmt" "net/http" + "sort" "strings" "github.com/rs/zerolog/log" @@ -25,7 +26,11 @@ func (p *GitPlugin) giteaEvent(w http.ResponseWriter, r *http.Request) { repo := evt.Repository.Name msg := " " - for _, c := range evt.Commits { + commits := evt.Commits + sort.Slice(commits, func(i, j int) bool { + return commits[i].Timestamp.Before(commits[j].Timestamp) + }) + for _, c := range commits { m := strings.Split(c.Message, "\n")[0] msg += fmt.Sprintf("%s %s pushed to %s (<%s|%s>) %s\n", icon, diff --git a/plugins/git/gitea_push.go b/plugins/git/gitea_push.go index a102478..ddd5ab0 100644 --- a/plugins/git/gitea_push.go +++ b/plugins/git/gitea_push.go @@ -1,5 +1,7 @@ package git +import "time" + type GiteaPush struct { Secret string `json:"secret"` Ref string `json:"ref"` @@ -20,7 +22,7 @@ type GiteaPush struct { Email string `json:"email"` Username string `json:"username"` } `json:"committer"` - Timestamp string `json:"timestamp"` + Timestamp time.Time `json:"timestamp"` } `json:"commits"` Repository struct { ID int `json:"id"`