@@ -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",
|
||||
});
|
||||
},
|
||||
|
||||
@@ -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
|
||||
`
|
||||
)
|
||||
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user