Skip to content

Conversation

@fearphage
Copy link

@fearphage fearphage commented Oct 5, 2025

Changes

  • Created a constant that maps the NoFileOptions to their corresponding core methods
  • Switched to early exit/return pattern to further simplify and de-indent the code
    Everything after the return statement is just white-space changes.

Note

There is no change in functionality here.

@fearphage fearphage requested a review from a team as a code owner October 5, 2025 14:39
Copilot AI review requested due to automatic review settings October 5, 2025 14:39
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR simplifies the logic for handling "no files" upload notifications by replacing a switch statement with a lookup table pattern and implementing an early return strategy.

  • Replaced switch statement with a constant mapping NoFileOptions to core methods
  • Introduced early exit pattern with return statement to reduce code indentation
  • Simplified control flow by eliminating the else block after the early return

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
src/upload/constants.ts Added NoFileFunctionMap constant mapping enum values to core functions
src/upload/upload-artifact.ts Replaced switch statement with map lookup and implemented early return pattern

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

[NoFileOptions.error]: setFailed,
[NoFileOptions.ignore]: info,
[NoFileOptions.warn]: warning
} as const
Copy link

Copilot AI Oct 5, 2025

Choose a reason for hiding this comment

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

The NoFileFunctionMap could potentially be called with an undefined key if inputs.ifNoFilesFound contains an unexpected value. Consider adding a type annotation or default case to handle this scenario gracefully.

Suggested change
} as const
} as const
/**
* Safely retrieves the function for the given NoFileOptions value.
* Defaults to warning if the value is unrecognized.
*/
export function getNoFileFunction(
option: string
): typeof setFailed | typeof info | typeof warning {
if (option === NoFileOptions.error) {
return setFailed;
} else if (option === NoFileOptions.ignore) {
return info;
} else if (option === NoFileOptions.warn) {
return warning;
} else {
// Default to warning for unexpected values
warning(`Unknown if-no-files-found option: ${option}, defaulting to 'warn'.`);
return warning;
}
}

Copilot uses AI. Check for mistakes.
Comment on lines +33 to 35
NoFileFunctionMap[inputs.ifNoFilesFound]?.(
`No files were found with the provided path: ${inputs.searchPath}. No artifacts will be uploaded.`
)
Copy link

Copilot AI Oct 5, 2025

Choose a reason for hiding this comment

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

Using optional chaining here means that if inputs.ifNoFilesFound is an unexpected value, the function will silently do nothing instead of providing feedback about the invalid option. Consider adding explicit error handling for unsupported values.

Suggested change
NoFileFunctionMap[inputs.ifNoFilesFound]?.(
`No files were found with the provided path: ${inputs.searchPath}. No artifacts will be uploaded.`
)
const noFileHandler = NoFileFunctionMap[inputs.ifNoFilesFound];
if (noFileHandler) {
noFileHandler(
`No files were found with the provided path: ${inputs.searchPath}. No artifacts will be uploaded.`
);
} else {
core.setFailed(
`Invalid value for 'if-no-files-found': '${inputs.ifNoFilesFound}'. Supported options are: ${Object.keys(NoFileFunctionMap).join(', ')}.`
);
}

Copilot uses AI. Check for mistakes.
@fearphage
Copy link
Author

Both of the Copilot suggestions would alter the current functionality. That goes against the current intent.

@Tyszek343
Copy link

Changes

  • Created a constant that maps the NoFileOptions to their corresponding core methods
  • Switched to early exit/return pattern to further simplify and de-indent the code
    Everything after the return statement is just white-space changes.

[!NOTE]

There is no change in functionality here.

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.

4 participants