Update changelog

Signed-off-by: Sacha Al Himdani <sacha@getprobo.com>
This commit is contained in:
Sacha Al Himdani
2025-06-05 22:15:00 -07:00
parent 6b9edeaaf4
commit af7d3c25bd
3 changed files with 34 additions and 8 deletions

View File

@@ -398,9 +398,13 @@ function ShowDocumentContent({
loadQuery({ documentId: documentValue.id, organizationId: organizationId! }); loadQuery({ documentId: documentValue.id, organizationId: organizationId! });
}, },
onError: (error) => { onError: (error) => {
const description = error.message.includes("no changes detected") ?
"Draft and published version are identical."
: error.message || "An unknown error occurred";
toast({ toast({
title: "Error publishing document", title: "Error publishing document",
description: error.message || "An unknown error occurred", description,
variant: "destructive", variant: "destructive",
}); });
}, },

View File

@@ -31,10 +31,11 @@ const (
Focus on additions, deletions, modifications, and restructuring. Focus on additions, deletions, modifications, and restructuring.
# Response Format # Response Format
Respond with simple and short phrases that describe the changes, if possible use a single phrase. Respond with ONE simple phrase that describe the changes.
# Change types # Change types
Change types can include: "Added", "Removed", "Updated", "Reworded", "Reorganized", "Fixed", etc. If possible use the following words with additional context to describe the change types:
"Added", "Removed", "Updated", "Reworded", "Reorganized", "Fixed", etc.
# SOP # SOP
- Be objective and neutral in tone. - Be objective and neutral in tone.
@@ -43,7 +44,7 @@ const (
**Example output format:** **Example output format:**
Respond ONLY with the phrase that describes the changes. No explanation, no markdown, no preamble. Like this: Respond ONLY with the phrase that describes the changes. No explanation, no markdown, no preamble. Like this:
Added Clause about sharing personal information with trusted partners Added clauses about sharing personal information with trusted partners
` `
) )

View File

@@ -73,6 +73,7 @@ func (s DocumentService) GenerateChangelog(
ctx context.Context, ctx context.Context,
documentID gid.GID, documentID gid.GID,
) (*string, error) { ) (*string, error) {
var changelog *string
draftVersion := &coredata.DocumentVersion{} draftVersion := &coredata.DocumentVersion{}
publishedVersion := &coredata.DocumentVersion{} publishedVersion := &coredata.DocumentVersion{}
@@ -93,7 +94,8 @@ func (s DocumentService) GenerateChangelog(
} }
if document.CurrentPublishedVersion == nil { if document.CurrentPublishedVersion == nil {
publishedVersion.Content = "" initialVersionChangelog := "Initial version"
changelog = &initialVersionChangelog
} else { } else {
if err := publishedVersion.LoadByDocumentIDAndVersionNumber(ctx, conn, s.svc.scope, documentID, *document.CurrentPublishedVersion); err != nil { if err := publishedVersion.LoadByDocumentIDAndVersionNumber(ctx, conn, s.svc.scope, documentID, *document.CurrentPublishedVersion); err != nil {
return fmt.Errorf("cannot load published version: %w", err) return fmt.Errorf("cannot load published version: %w", err)
@@ -108,9 +110,16 @@ func (s DocumentService) GenerateChangelog(
return nil, err return nil, err
} }
changelog, err := s.svc.agent.GenerateChangelog(ctx, publishedVersion.Content, draftVersion.Content) if publishedVersion.Content == draftVersion.Content {
if err != nil { noDiffChangelog := "No changes detected"
return nil, fmt.Errorf("failed to generate changelog: %w", err) changelog = &noDiffChangelog
}
if changelog == nil {
changelog, err = s.svc.agent.GenerateChangelog(ctx, publishedVersion.Content, draftVersion.Content)
if err != nil {
return nil, fmt.Errorf("failed to generate changelog: %w", err)
}
} }
return changelog, nil return changelog, nil
@@ -124,6 +133,7 @@ func (s *DocumentService) PublishVersion(
) (*coredata.Document, *coredata.DocumentVersion, error) { ) (*coredata.Document, *coredata.DocumentVersion, error) {
document := &coredata.Document{} document := &coredata.Document{}
documentVersion := &coredata.DocumentVersion{} documentVersion := &coredata.DocumentVersion{}
publishedVersion := &coredata.DocumentVersion{}
now := time.Now() now := time.Now()
err := s.svc.pg.WithTx( err := s.svc.pg.WithTx(
@@ -141,6 +151,17 @@ func (s *DocumentService) PublishVersion(
return fmt.Errorf("cannot publish version") return fmt.Errorf("cannot publish version")
} }
if document.CurrentPublishedVersion != nil {
if err := publishedVersion.LoadByDocumentIDAndVersionNumber(ctx, tx, s.svc.scope, documentID, *document.CurrentPublishedVersion); err != nil {
return fmt.Errorf("cannot load published version: %w", err)
}
if publishedVersion.Content == documentVersion.Content &&
publishedVersion.Title == documentVersion.Title &&
publishedVersion.OwnerID == documentVersion.OwnerID {
return fmt.Errorf("cannot publish version: no changes detected")
}
}
if changelog != nil { if changelog != nil {
documentVersion.Changelog = *changelog documentVersion.Changelog = *changelog
} }