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

Allow customising detector name #86

Merged
merged 1 commit into from
Jul 3, 2024
Merged

Allow customising detector name #86

merged 1 commit into from
Jul 3, 2024

Conversation

hmaurer
Copy link
Contributor

@hmaurer hmaurer commented Jul 1, 2024

Allow users of the action to customise the detector name. New inputs:

  • detector-name
  • detector-version
  • detector-url

If detector-name is not specified, then information extracted from package.json is used, as before (no changes).

@hmaurer hmaurer marked this pull request as ready for review July 1, 2024 16:50
};
const detectorName = core.getInput("detector-name");
if (detectorName == "") {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Wouldn't this be a !== check, as we would only set this if it is not empty?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Also if this cannot legitimately be set to an empty/white space string, then we should use a check like: detectorName && detectorName.trim().length > 0 or get the core.getInput() call to do the trimming for us with this option; https://github.com/actions/toolkit/blob/main/packages/core/src/core.ts#L18

Copy link

Choose a reason for hiding this comment

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

My preference would be that this not be allowed to be empty. I can't say for sure that it would error out, but it just seems like the kind of thing that can only cause problems.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@peter-murray getInput trims whitespace by default.

if (detectorName == "") {
snapshotConfig.detector = {
name: detectorName,
url: core.getInput("detector-url"),
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can these be empty strings as valid values? I have not looked too deeply into these configuration values. Would we want a default for these if not specified, or just take the potential empty string value from the caller?

Copy link

Choose a reason for hiding this comment

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

I'm not sure if empty strings would pass validation off the top of my head, but I would encourage setting non-empty default values either way.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've made a change so that if detector-name is specified then detector-version and detector-url are required to be specified by the user. There are no sensible defaults we could use here, only dummy ones (e.g. detector-url: https://example.com). Requiring the user to intentionally make that decision feels better to me.

@peter-murray peter-murray merged commit 2219818 into main Jul 3, 2024
3 checks passed
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.

3 participants