Browse Source

Prevent empty commits and webmention spam

master
Jan-Lukas Else 1 year ago
parent
commit
580724e9f9
  1. 7
      storage.go
  2. 2
      webmention.go

7
storage.go

@ -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")

2
webmention.go

@ -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())

Loading…
Cancel
Save