Browse Source

Prevent empty commits and webmention spam

master
Jan-Lukas Else 9 months ago
parent
commit
580724e9f9
2 changed files with 8 additions and 1 deletions
  1. +7
    -0
      storage.go
  2. +1
    -1
      webmention.go

+ 7
- 0
storage.go 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")


+ 1
- 1
webmention.go 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())


Loading…
Cancel
Save