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: deletes singular CL when from CLs when specified #381

Merged
merged 16 commits into from
May 17, 2023

Conversation

WillieRuemmele
Copy link
Member

What does this PR do?

this will parse the CLs file and delete an individual CL when a delete is encountered with source tracking commands
identical to what's here for source delete salesforcecli/plugin-deploy-retrieve#613

What issues does this PR fix or reference?

@W-13167950@
tests: salesforcecli/plugin-source#839

Copy link
Contributor

@mshanemc mshanemc left a comment

Choose a reason for hiding this comment

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

that's a nice test

* @param filename - a path to a custom labels file
* @param customLabels - an array of SourceComponents representing the custom labels to delete
*/
public static async deleteCustomLabels(filename: string, customLabels: SourceComponent[]): Promise<void> {
Copy link
Contributor

Choose a reason for hiding this comment

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

if it's not using anything from the class, it could be a standalone function, top-level exported if needed by the plugins.

} else {
// in theory, we should only have custom labels passed in, but filter just to make sure
const customLabelsToDelete = customLabels
.filter((label) => label.type.id === 'customlabel')
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd put this up at the top of the function. You could filter/warn/throw even before parsing the file if you got something unexpected

ignoreAttributes: false,
attributeNamePrefix: '@_',
});
const cls = parser.parse(fs.readFileSync(filename, 'utf8')) as {
Copy link
Contributor

Choose a reason for hiding this comment

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

alternatively, there's kit/ensureArray so you can have fewer conditionals. If you filtered the array and it ends up empty, you've got a check below for that to delete the file.

import * as sinon from 'sinon';
import { SourceComponent } from '@salesforce/source-deploy-retrieve';
import { expect } from 'chai';
import { SourceTracking } from '../../src';
Copy link
Contributor

Choose a reason for hiding this comment

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

can you import it from the file instead of the parent folder?

* @param filename - a path to a custom labels file
* @param customLabels - an array of SourceComponents representing the custom labels to delete
*/
export const deleteCustomLabels = (filename: string, customLabels: SourceComponent[]): Promise<void> => {
Copy link
Contributor

@mshanemc mshanemc May 11, 2023

Choose a reason for hiding this comment

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

Can it return some sort of results structure?

Like maybe it returns a Promise of either the file contents as JSON or undefined (if it was deleted), inside an object for potential future expansion? like, {fileContents?: cls }

you'd still need the writeStub in your test, but you could assert from the function response?

@mshanemc mshanemc merged commit 26fbdb0 into main May 17, 2023
@mshanemc mshanemc deleted the wr/deleteCustomLabels branch May 17, 2023 21:33
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