Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add defaults to ticket custom fields #207

Merged
merged 5 commits into from
Aug 15, 2024
Merged

Conversation

laurenleach
Copy link
Contributor

@laurenleach laurenleach commented Aug 15, 2024

Summary by CodeRabbit

  • New Features

    • Enhanced validation for ticket custom fields, including Annotations and DefaultValue.
    • New functions for retrieving default values for custom fields, improving data handling.
    • Schema updates to include new fields for default values and annotations in ticket custom fields.
  • Bug Fixes

    • Improved handling of empty or nil values in custom field retrieval and validation, ensuring more robust functionality.

@laurenleach laurenleach requested a review from jirwin as a code owner August 15, 2024 03:32
@laurenleach laurenleach requested a review from btipling August 15, 2024 03:32
Copy link

coderabbitai bot commented Aug 15, 2024

Walkthrough

The updates enhance the validation and retrieval processes for ticket custom fields, focusing on the addition of default values and improved error handling. Key changes include enhanced validation logic for Annotations and DefaultValue fields, new functions for value retrieval, and structural updates in the protobuf schema to support these features. Overall, these modifications ensure more robust handling of ticket custom fields, leading to greater flexibility and accuracy in data management.

Changes

Files Change Summary
pb/c1/connector/v2/ticket.pb.validate.go, Enhanced validation logic for Annotations and DefaultValue fields in TicketCustomField, improving error handling.
pkg/types/ticket/custom_fields.go Updated GetCustomFieldValue, added GetDefaultCustomFieldValue, and GetCustomFieldValueOrDefault for improved retrieval and validation of custom field values.
proto/c1/connector/v2/ticket.proto Added annotations and default_value fields to various TicketCustomField messages, enhancing data structure capabilities.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant TicketService
    participant ValidationModule
    participant Database

    User->>TicketService: Request Ticket
    TicketService->>ValidationModule: Validate Ticket Fields
    ValidationModule->>Database: Check Annotations and Default Values
    Database-->>ValidationModule: Return Validation Results
    ValidationModule-->>TicketService: Return Validation Status
    TicketService-->>User: Respond with Ticket Data
Loading

🐇 In fields of bright, our changes sprout,
With validations strong, we sing and shout.
Default values dance in the light,
Making ticket handling a pure delight!
Hop along, let errors flee,
A smoother path, oh joy, you'll see! 🌼


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 9709c3e and 1ab8d68.

Files ignored due to path filters (1)
  • pb/c1/connector/v2/ticket.pb.go is excluded by !**/*.pb.go
Files selected for processing (3)
  • pb/c1/connector/v2/ticket.pb.validate.go (6 hunks)
  • pkg/types/ticket/custom_fields.go (9 hunks)
  • proto/c1/connector/v2/ticket.proto (2 hunks)
Additional context used
golangci-lint
pkg/types/ticket/custom_fields.go

320-320: error is not nil (line 318) but it returns nil

(nilerr)

GitHub Check: go-lint
pkg/types/ticket/custom_fields.go

[failure] 320-320:
error is not nil (line 318) but it returns nil (nilerr)

Additional comments not posted (16)
proto/c1/connector/v2/ticket.proto (8)

41-41: Addition of annotations is appropriate.

The addition of repeated google.protobuf.Any annotations enhances the flexibility of the TicketCustomField message by allowing for additional metadata.


46-46: Addition of default_value is beneficial.

The string default_value field in TicketCustomFieldStringValue provides a useful fallback mechanism for default values.


51-51: Support for multiple default values is appropriate.

The repeated string default_values field in TicketCustomFieldStringValues aligns with the message's purpose of handling multiple values.


60-60: Addition of default_value is useful.

The google.protobuf.Timestamp default_value field in TicketCustomFieldTimestampValue ensures that a default timestamp is available.


66-66: Default value for pickable strings is beneficial.

The string default_value field in TicketCustomFieldPickStringValue enhances usability by providing a default option.


72-72: Support for multiple default options is appropriate.

The repeated string default_values field in TicketCustomFieldPickMultipleStringValues aligns with the message's purpose of handling multiple selectable values.


78-78: Default object value is beneficial.

The TicketCustomFieldObjectValue default_value field in TicketCustomFieldPickObjectValue ensures a default object is available.


84-84: Support for multiple default object values is appropriate.

The repeated TicketCustomFieldObjectValue default_values field in TicketCustomFieldPickMultipleObjectValues aligns with the message's purpose of handling multiple selectable objects.

pkg/types/ticket/custom_fields.go (3)

215-218: Enhanced handling of empty values is robust.

The added checks for empty string and slice values in GetCustomFieldValue improve robustness by ensuring empty values are explicitly handled.

Also applies to: 222-226, 235-239, 242-246, 252-256


263-315: Addition of GetDefaultCustomFieldValue is valuable.

The GetDefaultCustomFieldValue function provides a fallback mechanism for default values, enhancing the existing logic.


317-326: GetCustomFieldValueOrDefault simplifies value retrieval.

The GetCustomFieldValueOrDefault function streamlines the logic by combining the retrieval of actual and default values.

Tools
golangci-lint

320-320: error is not nil (line 318) but it returns nil

(nilerr)

GitHub Check: go-lint

[failure] 320-320:
error is not nil (line 318) but it returns nil (nilerr)

pb/c1/connector/v2/ticket.pb.validate.go (5)

283-315: Annotations validation logic is consistent and well-implemented.

The validation logic for the Annotations field follows the established pattern, ensuring robust error handling.


1095-1123: DefaultValue validation logic is consistent and well-implemented.

The validation logic for the DefaultValue field in TicketCustomFieldTimestampValue is consistent with the established pattern, ensuring robust error handling.


1506-1534: DefaultValue validation logic is consistent and well-implemented.

The validation logic for the DefaultValue field in TicketCustomFieldPickObjectValue follows the established pattern, ensuring robust error handling.


1709-1742: DefaultValues validation logic is consistent and well-implemented.

The validation logic for the DefaultValues field in TicketCustomFieldPickMultipleObjectValues follows the established pattern, ensuring robust error handling.


754-755: Verify if DefaultValue requires validation.

There are no validation rules for the DefaultValue field in TicketCustomFieldStringValue. Ensure this is intentional and correct.

func GetCustomFieldValueOrDefault(field *v2.TicketCustomField) (interface{}, error) {
v, err := GetCustomFieldValue(field)
if err != nil {
return nil, nil
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fix error handling in GetCustomFieldValueOrDefault.

The function should return the error instead of nil when an error occurs.

-		return nil, nil
+		return nil, err
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
return nil, nil
return nil, err
Tools
golangci-lint

320-320: error is not nil (line 318) but it returns nil

(nilerr)

GitHub Check: go-lint

[failure] 320-320:
error is not nil (line 318) but it returns nil (nilerr)

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

Outside diff range, codebase verification and nitpick comments (1)
pkg/types/ticket/custom_fields.go (1)

Line range hint 215-260:
Document the behavior of returning nil for empty values.

The function returns nil for empty string and slice values. Consider adding documentation or comments to clarify this behavior, as it might not be suitable for all use cases.

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 1ab8d68 and 0cc4e08.

Files selected for processing (1)
  • pkg/types/ticket/custom_fields.go (9 hunks)
Additional comments not posted (3)
pkg/types/ticket/custom_fields.go (3)

263-314: LGTM!

The GetDefaultCustomFieldValue function is well-implemented and aligns with the PR objectives by providing a fallback mechanism for default values.


317-326: LGTM!

The GetCustomFieldValueOrDefault function effectively combines value retrieval and default handling, enhancing robustness and flexibility.


Line range hint 390-594:
LGTM!

The updates to the ValidateTicket function ensure comprehensive validation by considering default values for required fields.

Copy link
Contributor

@btipling btipling left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you. These default values are defined in the connectors yes?

@laurenleach
Copy link
Contributor Author

Thank you. These default values are defined in the connectors yes?

@btipling yes like ConductorOne/baton-servicenow#17

@laurenleach laurenleach merged commit 2547caa into main Aug 15, 2024
4 checks passed
@laurenleach laurenleach deleted the lauren/default-custom-field branch August 15, 2024 04:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants