Skip to content

Added validation for uploaded file in create artifact log#78

Open
parnikarangnekar wants to merge 1 commit intodevelopfrom
77-make-file-upload-optional-for-alc-logging
Open

Added validation for uploaded file in create artifact log#78
parnikarangnekar wants to merge 1 commit intodevelopfrom
77-make-file-upload-optional-for-alc-logging

Conversation

@parnikarangnekar
Copy link
Copy Markdown

Closes- #77

@parnikarangnekar parnikarangnekar linked an issue Jan 13, 2026 that may be closed by this pull request
@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello @parnikarangnekar, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request enhances the createArtifactLog service by introducing greater flexibility in how artifact logs can be generated. It modifies the service to no longer strictly require an uploaded file, allowing an eventMessage to serve as an alternative input. The changes include robust validation to ensure that a valid input (either a file or a message) is always provided, and that any uploaded files meet the expected format requirements, improving the service's usability and error handling.

Highlights

  • Flexible Artifact Log Creation: The createArtifactLog service now allows for more flexibility by making the uploadedFile parameter optional, enabling artifact logs to be created without a file if an eventMessage is provided.
  • Input Validation: New validation has been added to ensure that at least one of uploadedFile or eventMessage is present when creating an artifact log, preventing logs from being created with no content.
  • Enhanced File Handling: The service now includes conditional logic for processing uploaded files, performing file name parsing, extension validation (CSV/JSON), and stream handling only when an uploadedFile is actually provided.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request adds necessary validation for file uploads when creating an artifact log. It correctly makes the uploadedFile parameter optional and ensures that either a file or an eventMessage is provided. The logic to handle an optional file, including file extension validation and file saving, is mostly well-implemented. However, I've found a critical issue with redundant code that could cause errors when no file is uploaded. Please see my detailed comment.

Comment on lines 157 to 158
<set field="logFilePath" type="String" value="runtime://ArtifactLogs/${fileName}_${dateTime}.${fileFormat}"/>
<set field="fileReference" from="ec.resource.getLocationReference(logFilePath)"/>
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

critical

These lines are redundant and will cause issues when no file is uploaded. The logFilePath and fileReference variables are already correctly set on lines 154-155, which handle the case where uploadedFile is null. These redundant lines will overwrite logFilePath with a malformed value (e.g., runtime://ArtifactLogs/null_..._....null) when no file is present, which will likely lead to an error. Please remove these two lines.

Copy link
Copy Markdown
Contributor

@puru-khedre puru-khedre left a comment

Choose a reason for hiding this comment

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

The current changes does not look correct to me.

IMO, we just needed one conditional block that handles everything only when a file is uploaded. If no file is uploaded, none of the file-related handling should be executed.

<in-parameters>
<auto-parameters entity-name="co.hotwax.alc.ArtifactLog" include="nonpk"/>
<parameter name="uploadedFile" type="org.apache.commons.fileupload.FileItem" required="true"/>
<!-- TODO: Do validation -->
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Unnecessary change, removed the comment note.

<if condition="userGroupCount == 0"><then><return error="true" message="You must be a member of the tenant group to create an Artifact Log"/></then></if>

<!-- Validate uploadedFile or eventMessage presence -->
<if condition="(uploadedFile == null || uploadedFile.getSize() == 0) &amp;&amp; ec.util.isEmpty(eventMessage)">
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Complex validation

And what is this ec.util.isEmpty()? Does this method even exist?

<set field="extIndex" from="fileName.lastIndexOf('.')"/>
<if condition="extIndex == -1">
<return message="No file extension found. Please upload a file with an extension, Supported extensions are: .csv, .json" error="true"/>
<set field="dateTime" from="ec.l10n.format(ec.user.nowTimestamp, 'yyyy-MM-dd-HH-mm-ss-SSS')"/>
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

unnecessary change

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.

Make File Upload Optional for ALC Logging

2 participants