git: order gitea commits

This commit is contained in:
Chris Sexton 2019-11-29 11:07:52 -05:00 committed by Chris Sexton
parent 6e66498d25
commit 72da1d3c78
2 changed files with 9 additions and 2 deletions

View File

@ -4,6 +4,7 @@ import (
"encoding/json" "encoding/json"
"fmt" "fmt"
"net/http" "net/http"
"sort"
"strings" "strings"
"github.com/rs/zerolog/log" "github.com/rs/zerolog/log"
@ -25,7 +26,11 @@ func (p *GitPlugin) giteaEvent(w http.ResponseWriter, r *http.Request) {
repo := evt.Repository.Name repo := evt.Repository.Name
msg := " " 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] m := strings.Split(c.Message, "\n")[0]
msg += fmt.Sprintf("%s %s pushed to %s (<%s|%s>) %s\n", msg += fmt.Sprintf("%s %s pushed to %s (<%s|%s>) %s\n",
icon, icon,

View File

@ -1,5 +1,7 @@
package git package git
import "time"
type GiteaPush struct { type GiteaPush struct {
Secret string `json:"secret"` Secret string `json:"secret"`
Ref string `json:"ref"` Ref string `json:"ref"`
@ -20,7 +22,7 @@ type GiteaPush struct {
Email string `json:"email"` Email string `json:"email"`
Username string `json:"username"` Username string `json:"username"`
} `json:"committer"` } `json:"committer"`
Timestamp string `json:"timestamp"` Timestamp time.Time `json:"timestamp"`
} `json:"commits"` } `json:"commits"`
Repository struct { Repository struct {
ID int `json:"id"` ID int `json:"id"`