feat: Add createDraftNote api support, useful for bulk code review #183
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Overview
This PR adds complete support for GitLab's Draft Notes API, enabling users to create, manage, and publish draft comments on merge requests
before making them visible to other collaborators.
What are Draft Notes?
Draft Notes are a GitLab feature that allows users to:
• Write comments on merge requests that are only visible to the author
• Review and edit comments before publishing
• Publish individual draft notes or all drafts at once
• Add comments to specific lines in diffs (with position support)
Features Added
🛠️ New Tools (6 total)
🔧 Technical Improvements
• Flexible Schema Validation: Enhanced schemas to handle GitLab API inconsistencies
• Position Support: Full support for diff positioning in draft comments
• Error Handling: Robust handling of empty responses from GitLab API
• Parameter Normalization: Handles both body and note field variations
• Type Safety: Complete TypeScript definitions for all draft note operations
Implementation Details
Core Functions (index.ts)
• Added 6 new API functions with comprehensive error handling
• Implemented proper URL encoding and parameter validation
• Added support for diff positioning and discussion resolution
• Enhanced response parsing to handle GitLab's variable response formats
Schema Definitions (schemas.ts)
• Created flexible GitLabDraftNoteSchema with field normalization
• Added separate schemas for each operation (CRUD + publish operations)
• Split position schemas into flexible (responses) and strict (creation) variants
• Made user schema fields optional for better API compatibility
Documentation Updates
• Updated README.md with new tool descriptions
• Added comprehensive inline documentation for all functions
• Included parameter descriptions and usage examples
API Endpoints Covered
GET /projects/:id/merge_requests/:merge_request_iid/draft_notes
POST /projects/:id/merge_requests/:merge_request_iid/draft_notes
PUT /projects/:id/merge_requests/:merge_request_iid/draft_notes/:draft_note_id
DELETE /projects/:id/merge_requests/:merge_request_iid/draft_notes/:draft_note_id
PUT /projects/:id/merge_requests/:merge_request_iid/draft_notes/:draft_note_id/publish
POST /projects/:id/merge_requests/:merge_request_iid/draft_notes/bulk_publish
Breaking Changes
None - this is a purely additive feature that doesn't modify existing functionality.
Usage Example
typescript
// Create a draft note
await createDraftNote("project-id", "123", "This needs improvement", {
position_type: "text",
base_sha: "abc123",
head_sha: "def456",
start_sha: "ghi789",
new_path: "src/file.js",
new_line: 42
});
// Publish all drafts when ready
await bulkPublishDraftNotes("project-id", "123");
Benefits
• Improved Code Review Workflow: Users can draft and refine comments before publishing
• Better Collaboration: Reduces noise in merge request discussions
• Enhanced Productivity: Bulk operations save time when reviewing large changes
• Complete API Coverage: Full parity with GitLab's native draft notes functionality