From af7d3c25bdb7602e16e47bd1e99ce03acb0905dc Mon Sep 17 00:00:00 2001 From: Sacha Al Himdani Date: Thu, 5 Jun 2025 22:15:00 -0700 Subject: [PATCH] Update changelog Signed-off-by: Sacha Al Himdani --- .../documents/ShowDocumentView.tsx | 6 +++- pkg/agents/changelog_generator.go | 7 +++-- pkg/probo/document_service.go | 29 ++++++++++++++++--- 3 files changed, 34 insertions(+), 8 deletions(-) diff --git a/apps/console/src/pages/organizations/documents/ShowDocumentView.tsx b/apps/console/src/pages/organizations/documents/ShowDocumentView.tsx index edf0338e0..1229f63a5 100644 --- a/apps/console/src/pages/organizations/documents/ShowDocumentView.tsx +++ b/apps/console/src/pages/organizations/documents/ShowDocumentView.tsx @@ -398,9 +398,13 @@ function ShowDocumentContent({ loadQuery({ documentId: documentValue.id, organizationId: organizationId! }); }, onError: (error) => { + const description = error.message.includes("no changes detected") ? + "Draft and published version are identical." + : error.message || "An unknown error occurred"; + toast({ title: "Error publishing document", - description: error.message || "An unknown error occurred", + description, variant: "destructive", }); }, diff --git a/pkg/agents/changelog_generator.go b/pkg/agents/changelog_generator.go index db290080a..9085b29f6 100644 --- a/pkg/agents/changelog_generator.go +++ b/pkg/agents/changelog_generator.go @@ -31,10 +31,11 @@ const ( Focus on additions, deletions, modifications, and restructuring. # 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 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 - Be objective and neutral in tone. @@ -43,7 +44,7 @@ const ( **Example output format:** 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 ` ) diff --git a/pkg/probo/document_service.go b/pkg/probo/document_service.go index 196045702..f47f99293 100644 --- a/pkg/probo/document_service.go +++ b/pkg/probo/document_service.go @@ -73,6 +73,7 @@ func (s DocumentService) GenerateChangelog( ctx context.Context, documentID gid.GID, ) (*string, error) { + var changelog *string draftVersion := &coredata.DocumentVersion{} publishedVersion := &coredata.DocumentVersion{} @@ -93,7 +94,8 @@ func (s DocumentService) GenerateChangelog( } if document.CurrentPublishedVersion == nil { - publishedVersion.Content = "" + initialVersionChangelog := "Initial version" + changelog = &initialVersionChangelog } else { if err := publishedVersion.LoadByDocumentIDAndVersionNumber(ctx, conn, s.svc.scope, documentID, *document.CurrentPublishedVersion); err != nil { return fmt.Errorf("cannot load published version: %w", err) @@ -108,9 +110,16 @@ func (s DocumentService) GenerateChangelog( return nil, err } - changelog, err := s.svc.agent.GenerateChangelog(ctx, publishedVersion.Content, draftVersion.Content) - if err != nil { - return nil, fmt.Errorf("failed to generate changelog: %w", err) + if publishedVersion.Content == draftVersion.Content { + noDiffChangelog := "No changes detected" + 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 @@ -124,6 +133,7 @@ func (s *DocumentService) PublishVersion( ) (*coredata.Document, *coredata.DocumentVersion, error) { document := &coredata.Document{} documentVersion := &coredata.DocumentVersion{} + publishedVersion := &coredata.DocumentVersion{} now := time.Now() err := s.svc.pg.WithTx( @@ -141,6 +151,17 @@ func (s *DocumentService) PublishVersion( 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 { documentVersion.Changelog = *changelog }