jlelse
/
hugo-micropub
Archived
1
Fork 0

Prevent empty commits and webmention spam

This commit is contained in:
Jan-Lukas Else 2020-04-20 21:46:59 +02:00
parent 09e3b77453
commit 580724e9f9
2 changed files with 8 additions and 1 deletions

View File

@ -127,6 +127,13 @@ func (g *Git) unsafeUpdateFile(filepath string, file string, message string) err
if err != nil {
return errors.New("failed to write to file")
}
status, err := w.Status()
if err == nil && status.IsClean() {
// No file changes, prevent empty commit
return nil
} else {
err = nil
}
_, err = w.Add(filepath)
if err != nil {
return errors.New("failed to stage file")

View File

@ -138,7 +138,7 @@ func HandleWebmention(w http.ResponseWriter, r *http.Request) {
e := saveWebmention(&Mention{
Source: sourceUrl.String(),
Target: targetUrl.String(),
Date: time.Now().Format(time.RFC3339),
Date: time.Now().Format("2006-01-02"),
})
if e != nil {
fmt.Println("Failed to save webmention:", e.Error())