Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set modified time for Algolia doc object when requesting a review #54

Merged
merged 1 commit into from
Feb 15, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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