Skip to content

Commit

Permalink
Set modified time for Algolia doc object when requesting a review (ha…
Browse files Browse the repository at this point in the history
  • Loading branch information
jfreda authored Feb 15, 2023
1 parent 8250f33 commit d026636
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions internal/api/reviews.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"net/url"
"path"
"strings"
"time"

"github.com/hashicorp-forge/hermes/internal/config"
"github.com/hashicorp-forge/hermes/internal/email"
Expand Down Expand Up @@ -160,6 +161,35 @@ func ReviewHandler(
"path", r.URL.Path,
)

// Get file from Google Drive so we can get the latest modified time.
file, err := s.GetFile(docID)
if err != nil {
l.Error("error getting document file from Google",
"error", err,
"path", r.URL.Path,
"method", r.Method,
"doc_id", docID,
)
http.Error(w, `{"error": "Error creating review"}`,
http.StatusInternalServerError)
return
}

// Parse and set modified time.
modifiedTime, err := time.Parse(time.RFC3339Nano, file.ModifiedTime)
if err != nil {
l.Error("error parsing modified time",
"error", err,
"path", r.URL.Path,
"method", r.Method,
"doc_id", docID,
)
http.Error(w, `{"error": "Error creating review"}`,
http.StatusInternalServerError)
return
}
docObj.SetModifiedTime(modifiedTime.Unix())

// Get latest Google Drive file revision.
latestRev, err := s.GetLatestRevision(docID)
if err != nil {
Expand Down

0 comments on commit d026636

Please sign in to comment.