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

fix(cli): Remove logic converting empty array to undefined in changelog metadata #690

Merged
merged 5 commits into from
Aug 28, 2023

Conversation

kreddlear
Copy link
Contributor

@kreddlear kreddlear commented Aug 4, 2023

Currently, if either an App type update or an Issue type update is present, the promotion process expects both to be present and errors if not.

If only one is present, the other is converted to undefined instead of an empty array. However, in the promote command, there is a join attempt on both values (code here) -- so if one is undefined, the code returns something like TypeError: issueFeatureUpdates is not iterable.

This error blocks the developer from promoting and doesn't clearly state what they need to do to fix it, which is not ideal.

After some discussion about this, I updated the join so that it accounts for the undefined condition.

Jira ticket with link to report from customer

pragmatic-zac
pragmatic-zac previously approved these changes Aug 7, 2023
Copy link
Member

@eliangcs eliangcs left a comment

Choose a reason for hiding this comment

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

Good catch!

Since appMetadata and issueMetadata can no longer be undefined, the places that make such assumption should be changed too.

Here's one I found: Line 120-129 in promote.js:

      if (
        !appFeatureUpdates &&
        !issueFeatureUpdates &&
        !appBugfixes &&
        !issueBugfixes
      ) {
        this.log(
          `No metadata was found in the changelog. Remember, you can associate the changelog with issues or triggers/actions.\n\n${metadataPromptHelper}`
        );
      }

should be changed to the following (or something equivalent). Otherwise, the this.log in the if statement will be unreachable because appFeatureUpdates and its friends are always truthy (an empty arrays is truthy).

      if (
        _.isEmpty(appFeatureUpdates) &&
        _.isEmpty(issueFeatureUpdates) &&
        _.isEmpty(appBugfixes) &&
        _.isEmpty(issueBugfixes)
      ) {
        this.log(
          `No metadata was found in the changelog. Remember, you can associate the changelog with issues or triggers/actions.\n\n${metadataPromptHelper}`
        );
      }

There are others in promote.js like line 93 and 116.

@kreddlear
Copy link
Contributor Author

Thank you for the feedback @eliangcs ! I updated those lines so that they'll check if the array is empty, instead of if the value is truthy or not. I checked around and don't see other problematic checks on that, so hopefully we are all good here 🤞

Question for you -- do you think this is the best way of fixing this? Or, would changing the check and the join be better here? I went with this way because I could see others expecting this to be an array and creating similar bugs in the future, but open to alternatives, although I know this is a simple situation!

Comment on lines 116 to 118
if (!_.isEmpty(appBugfixes) || !_.isEmpty(issueBugfixes)) {
this.log(`Bug fixes: ${[...appBugfixes, issueBugfixes].join(', ')}`);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Alternatively, does something like this fix the issue? @kreddlear

if (appBugfixes || issueBugfixes) {
  this.log(`Bug fixes: ${[...(appBugfixes ?? []), ...(issueBugfixes ?? [])].join(', ')}`);
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@standielpls yes I think so! I was just playing with something like that, I just remembered the ?? operator in JS exists 😅 I asked ChangHung something similar above, but do you think that would be a cleaner solution? I'm leaning towards yes since it's a one-line change and would mean all those isEmpty checks don't have to apply.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think you're right! The isEmpty check is mostly important if we change from a undefined to [] so we should be able to omit those

Copy link
Contributor

@standielpls standielpls left a comment

Choose a reason for hiding this comment

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

I didn't test this locally but I think this solution should work!

@rnegron rnegron linked an issue Aug 16, 2023 that may be closed by this pull request
Copy link
Member

@eliangcs eliangcs left a comment

Choose a reason for hiding this comment

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

Assuming you tested it, this is cleaner. Thanks!

@kreddlear kreddlear merged commit e0afe65 into main Aug 28, 2023
13 checks passed
@kreddlear kreddlear deleted the pde-4177-fix-changelog-logic branch August 28, 2023 16:47
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.

[Bug]: issueFeatureUpdates is not iterable
4 participants