Allow initial document minor publishing
Signed-off-by: Cursor Agent <cursoragent@cursor.com> Co-authored-by: Bryan FRIMIN <bryan@frimin.fr>
This commit is contained in:
committed by
Bryan Frimin
parent
6dfdd7ca49
commit
b721179974
@@ -222,6 +222,109 @@ func TestDocumentVersion_PublishVersion(t *testing.T) {
|
|||||||
assert.Equal(t, 0, result.Node.Versions.Edges[0].Node.Minor)
|
assert.Equal(t, 0, result.Node.Versions.Edges[0].Node.Minor)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestDocumentVersion_PublishInitialMinorVersion(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
owner := testutil.NewClient(t, testutil.RoleOwner)
|
||||||
|
|
||||||
|
docID, _ := createTestDocument(t, owner)
|
||||||
|
|
||||||
|
publishMutation := `
|
||||||
|
mutation($input: PublishDocumentInput!) {
|
||||||
|
publishDocument(input: $input) {
|
||||||
|
document {
|
||||||
|
currentPublishedMajor
|
||||||
|
currentPublishedMinor
|
||||||
|
}
|
||||||
|
documentVersion {
|
||||||
|
status
|
||||||
|
major
|
||||||
|
minor
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
`
|
||||||
|
|
||||||
|
var publishResult struct {
|
||||||
|
PublishDocument struct {
|
||||||
|
Document struct {
|
||||||
|
CurrentPublishedMajor *int `json:"currentPublishedMajor"`
|
||||||
|
CurrentPublishedMinor *int `json:"currentPublishedMinor"`
|
||||||
|
} `json:"document"`
|
||||||
|
DocumentVersion struct {
|
||||||
|
Status string `json:"status"`
|
||||||
|
Major int `json:"major"`
|
||||||
|
Minor int `json:"minor"`
|
||||||
|
} `json:"documentVersion"`
|
||||||
|
} `json:"publishDocument"`
|
||||||
|
}
|
||||||
|
|
||||||
|
err := owner.Execute(publishMutation, map[string]any{
|
||||||
|
"input": map[string]any{
|
||||||
|
"minor": true,
|
||||||
|
"documentId": docID,
|
||||||
|
"changelog": "Initial minor release",
|
||||||
|
},
|
||||||
|
}, &publishResult)
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
require.NotNil(t, publishResult.PublishDocument.Document.CurrentPublishedMajor)
|
||||||
|
require.NotNil(t, publishResult.PublishDocument.Document.CurrentPublishedMinor)
|
||||||
|
assert.Equal(t, 0, *publishResult.PublishDocument.Document.CurrentPublishedMajor)
|
||||||
|
assert.Equal(t, 1, *publishResult.PublishDocument.Document.CurrentPublishedMinor)
|
||||||
|
assert.Equal(t, "PUBLISHED", publishResult.PublishDocument.DocumentVersion.Status)
|
||||||
|
assert.Equal(t, 0, publishResult.PublishDocument.DocumentVersion.Major)
|
||||||
|
assert.Equal(t, 1, publishResult.PublishDocument.DocumentVersion.Minor)
|
||||||
|
|
||||||
|
var updateResult struct {
|
||||||
|
UpdateDocument struct {
|
||||||
|
DocumentVersion *struct {
|
||||||
|
Status string `json:"status"`
|
||||||
|
Major int `json:"major"`
|
||||||
|
Minor int `json:"minor"`
|
||||||
|
} `json:"documentVersion"`
|
||||||
|
} `json:"updateDocument"`
|
||||||
|
}
|
||||||
|
|
||||||
|
err = owner.Execute(`
|
||||||
|
mutation($input: UpdateDocumentInput!) {
|
||||||
|
updateDocument(input: $input) {
|
||||||
|
documentVersion {
|
||||||
|
status
|
||||||
|
major
|
||||||
|
minor
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
`, map[string]any{
|
||||||
|
"input": map[string]any{
|
||||||
|
"id": docID,
|
||||||
|
"content": testutil.ProseMirrorTextDoc("Updated content for 0.2"),
|
||||||
|
},
|
||||||
|
}, &updateResult)
|
||||||
|
require.NoError(t, err)
|
||||||
|
require.NotNil(t, updateResult.UpdateDocument.DocumentVersion)
|
||||||
|
assert.Equal(t, "DRAFT", updateResult.UpdateDocument.DocumentVersion.Status)
|
||||||
|
assert.Equal(t, 0, updateResult.UpdateDocument.DocumentVersion.Major)
|
||||||
|
assert.Equal(t, 2, updateResult.UpdateDocument.DocumentVersion.Minor)
|
||||||
|
|
||||||
|
err = owner.Execute(publishMutation, map[string]any{
|
||||||
|
"input": map[string]any{
|
||||||
|
"minor": true,
|
||||||
|
"documentId": docID,
|
||||||
|
"changelog": "Second minor release",
|
||||||
|
},
|
||||||
|
}, &publishResult)
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
require.NotNil(t, publishResult.PublishDocument.Document.CurrentPublishedMajor)
|
||||||
|
require.NotNil(t, publishResult.PublishDocument.Document.CurrentPublishedMinor)
|
||||||
|
assert.Equal(t, 0, *publishResult.PublishDocument.Document.CurrentPublishedMajor)
|
||||||
|
assert.Equal(t, 2, *publishResult.PublishDocument.Document.CurrentPublishedMinor)
|
||||||
|
assert.Equal(t, "PUBLISHED", publishResult.PublishDocument.DocumentVersion.Status)
|
||||||
|
assert.Equal(t, 0, publishResult.PublishDocument.DocumentVersion.Major)
|
||||||
|
assert.Equal(t, 2, publishResult.PublishDocument.DocumentVersion.Minor)
|
||||||
|
}
|
||||||
|
|
||||||
func TestDocumentVersion_AutoCreateDraft(t *testing.T) {
|
func TestDocumentVersion_AutoCreateDraft(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
owner := testutil.NewClient(t, testutil.RoleOwner)
|
owner := testutil.NewClient(t, testutil.RoleOwner)
|
||||||
|
|||||||
@@ -41,7 +41,7 @@ export const description: INodeProperties[] = [
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
default: false,
|
default: false,
|
||||||
description: 'Whether to publish as a minor version. Approvers are ignored when set. The document must already have a published major version.',
|
description: 'Whether to publish as a minor version. Approvers are ignored when set.',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
displayName: 'Approver IDs',
|
displayName: 'Approver IDs',
|
||||||
|
|||||||
@@ -70,7 +70,7 @@ func NewCmdPublish(f *cmdutil.Factory) *cobra.Command {
|
|||||||
Long: `Publish the latest draft of a document.
|
Long: `Publish the latest draft of a document.
|
||||||
|
|
||||||
By default, the draft is published as a new major version. Pass --minor to
|
By default, the draft is published as a new major version. Pass --minor to
|
||||||
publish as a minor version (the document must already have a major version).
|
publish as a minor version.
|
||||||
When --approver is set (one or more profile IDs), an approval is requested
|
When --approver is set (one or more profile IDs), an approval is requested
|
||||||
instead of publishing immediately. Approvers are ignored with --minor.`,
|
instead of publishing immediately. Approvers are ignored with --minor.`,
|
||||||
Args: cobra.ExactArgs(1),
|
Args: cobra.ExactArgs(1),
|
||||||
|
|||||||
@@ -541,10 +541,8 @@ func (s DocumentService) generateChangelog(
|
|||||||
|
|
||||||
// PublishVersion is the single entry point for publishing a document
|
// PublishVersion is the single entry point for publishing a document
|
||||||
// version. The behaviour depends on req.Minor and req.ApproverIDs:
|
// version. The behaviour depends on req.Minor and req.ApproverIDs:
|
||||||
// - Minor=true: publish the existing draft as a minor bump (currentMajor.
|
// - Minor=true: publish the existing draft as a minor version. ApproverIDs
|
||||||
// currentMinor+1). ApproverIDs are ignored. Errors with
|
// are ignored.
|
||||||
// ErrCannotPublishMinorWithoutMajor when the document has never been
|
|
||||||
// published.
|
|
||||||
// - Minor=false with ApproverIDs: open an approval quorum on the draft as
|
// - Minor=false with ApproverIDs: open an approval quorum on the draft as
|
||||||
// a pending major bump (currentMajor+1.0). Result.Quorum is set.
|
// a pending major bump (currentMajor+1.0). Result.Quorum is set.
|
||||||
// - Minor=false without ApproverIDs: publish the draft immediately as a
|
// - Minor=false without ApproverIDs: publish the draft immediately as a
|
||||||
@@ -2826,10 +2824,6 @@ func (s *DocumentService) publishMinorVersionInTx(
|
|||||||
return document, documentVersion, nil
|
return document, documentVersion, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
if document.CurrentPublishedMajor == nil || document.CurrentPublishedMinor == nil {
|
|
||||||
return nil, nil, &ErrCannotPublishMinorWithoutMajor{}
|
|
||||||
}
|
|
||||||
|
|
||||||
document.CurrentPublishedMajor = &documentVersion.Major
|
document.CurrentPublishedMajor = &documentVersion.Major
|
||||||
document.CurrentPublishedMinor = &documentVersion.Minor
|
document.CurrentPublishedMinor = &documentVersion.Minor
|
||||||
|
|
||||||
|
|||||||
@@ -6321,7 +6321,7 @@ components:
|
|||||||
description: Document ID
|
description: Document ID
|
||||||
minor:
|
minor:
|
||||||
type: boolean
|
type: boolean
|
||||||
description: When true, publish the draft as a minor version (currentMajor.currentMinor+1) and ignore approver_ids; the document must already have a published major version. When false, publish as a new major version; if approver_ids are provided, an approval is requested instead.
|
description: When true, publish the draft as a minor version and ignore approver_ids. When false, publish as a new major version; if approver_ids are provided, an approval is requested instead.
|
||||||
approver_ids:
|
approver_ids:
|
||||||
type: array
|
type: array
|
||||||
items:
|
items:
|
||||||
|
|||||||
Reference in New Issue
Block a user