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

Feature/logic function get #696

Merged
merged 51 commits into from
Dec 8, 2023

Conversation

keeramis
Copy link
Contributor

@keeramis keeramis commented Dec 4, 2023

Description

This PR points to the execute command PR .

This PR does the following:

  • Implements the get command which downloads a logic function. The logic function can be specified using the --name or --id parameter on the CLI. Or it can be selected from the list of available logic functions
  • Uses list to get the name and id mapping to obtain one from the other
  • Improves color representation on the UI messages
  • Add a boolean parameter called display to the list method which controls whether to return the list for other helper methods or display it to the UI for the user
  • Add hyphen similar to create command if there are spaces (This will change as the specs change)
  • TODO: Remove the organization option in help (compare with the other PR)

How to Test

  1. Do the setup drill (checkout the branch, install dependencies, etc)
  2. Run this command npm start -- logic-function get and tinker with it using options --name, --id, --org
  3. Usage includes but not limited to the following
    npm start -- logic-function get
    npm start -- logic-function get --name myLF
    npm start -- logic-function get --id xxxx-xxxx-xxxx-xxxx-xxxx
    npm start -- logic-function get --org Particle
    

Related Issues / Discussions

Completeness

  • User is totes amazing for contributing!
  • Contributor has signed CLA
  • Problem and solution clearly stated
  • Tests have been provided
  • Docs have been updated
  • CI is passing

@hugomontero hugomontero force-pushed the feature/sc-123396/implement-execute-command-with-eventdata branch from fa201f4 to 1312a53 Compare December 5, 2023 16:15
Base automatically changed from feature/sc-123396/implement-execute-command-with-eventdata to feature/logic-function December 5, 2023 17:12
// 3. Download it to files. Take care of formatting
const api = createAPI();
({ name, id } = await this._getLogicFunctionIdAndName(org, name, id));
const slugName = name.toLowerCase().replace(/\s/g, '-');
Copy link
Contributor

Choose a reason for hiding this comment

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

let's change it with slugify from utils


await logicFunctionCommands.get({ name: 'LF1' });

expect(fs.existsSync(path.join(process.cwd(), 'LF1', 'LF1.js'))).to.be.true;
Copy link
Contributor

Choose a reason for hiding this comment

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

Pretty sure that's making linux tests fail.
I'd rather use fixtures/__root__/... folder for creation. Let's try to repro the test error in a linux machine.
the only thing that came to my mind now is lf1 dir and files should be in lower case since we're converting the name with slugify function.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ah that's a good point - that these might be in lower case!

});

describe('get', async () => {
beforeEach(() => {
Copy link
Contributor

Choose a reason for hiding this comment

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

use afterEach to return everything to normal after your test

@keeramis keeramis marked this pull request as ready for review December 6, 2023 16:36
Copy link
Contributor

@hugomontero hugomontero left a comment

Choose a reason for hiding this comment

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

I'd say let's merge it since we agree to change the dir creation in other story as well the list function

Copy link
Member

@monkbroc monkbroc left a comment

Choose a reason for hiding this comment

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

Keerthy and I reviewed this PR over Zoom. Keerthy has some notes on things to improve.

@keeramis
Copy link
Contributor Author

keeramis commented Dec 8, 2023

@hugomontero @monkbroc I made the improvements we discussed yday.

Hugo, I modified the helpers a bit, but didn't make many changes to the create and execute commands because I know that you are working on them separately and I didn't want to interfere with your changes.

Please let me know if I am missing something. Hope the functionality is clearer now when reading the code.

choices : list,
nonInteractiveError: 'Provide name for the logic function'
});
return answer.logic_function;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@monkbroc I know we discussed to return name and id here. I didn't make that change to keep the _getLogicFunctionIdAndName look consistent in the way it calls the _getXFromY methods - Kindly let me know if this should have been different.

lf1/lf1.js Outdated Show resolved Hide resolved
Copy link
Member

@monkbroc monkbroc left a comment

Choose a reason for hiding this comment

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

Retest the get and create functions after the latest changes and once they work, go ahead and merge

_printListHelperOutput() {
this.ui.stdout.write(`No Logic Functions currently deployed in your ${getOrgName(this.org)}.${os.EOL}`);
this.ui.stdout.write(`${os.EOL}`);
this.ui.stdout.write('To create a Logic Function, see ' + this.ui.chalk.yellow('\'particle logic-function create\'.') + `${os.EOL}`);
Copy link
Member

Choose a reason for hiding this comment

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

I suggest you don't include the quote for commands inside of chalk.yellow. It makes it harder to copy paste. Also make sure the period at the end of the line is not in yellow.

Suggested change
this.ui.stdout.write('To create a Logic Function, see ' + this.ui.chalk.yellow('\'particle logic-function create\'.') + `${os.EOL}`);
this.ui.stdout.write(`To create a Logic Function, see ${this.ui.chalk.yellow('particle logic-function create')}.${os.EOL}`);

this.ui.stdout.write(` - ID: ${item.id}${os.EOL}`);
this.ui.stdout.write(` - ${item.logic_triggers[0].type} based trigger ${os.EOL}`);
});
this.ui.stdout.write(`${os.EOL}To view a Logic Function's code, see \`particle logic-function get.\`${os.EOL}`);
Copy link
Member

Choose a reason for hiding this comment

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

Format the command in yellow


const { dirPath, jsonPath, jsPath } = await this._generateFiles({ logicFunctionConfigData, logicFunctionCode, name });

this._printGetFilesOutput({ dirPath, jsonPath, jsPath });
Copy link
Member

Choose a reason for hiding this comment

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

I get this._printGetFilesOutput is not a function when I call particle logic-function get

existingLogicFunction = existingLogicFunctions.find((item) => item.name === name);
} catch (error) {
const logicFuncNameExists = this.logicFuncList.find((item) => item.name === name);
if (!logicFuncNameExists) {
this.ui.stdout.write(this.ui.chalk.yellow(`Warn: We were unable to check if a Logic Function with name ${name} already exists.${os.EOL}`));
Copy link
Member

Choose a reason for hiding this comment

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

I get this message when I create a LF

? What would you like to call your Function? local test
? Please provide a short description of your Function: 
Creating Logic Function local test for Sandbox...
Warn: We were unable to check if a Logic Function with name local test already exists.
Successfully created local test in .
Files created:
- local-test/@types/particle_core.d.ts
- local-test/@types/particle_encoding.d.ts
- local-test/local-test.js
- local-test/local-test.logic.json

Guidelines for creating your Logic Function can be found <TBD>.
Once you have written your Logic Function, run
- 'particle logic-function execute' to run your Function
- 'particle logic-function deploy' to deploy your new changes

}

_printGetOutput({ dirPath, jsonPath, jsPath }) {
if (dirPath || jsonPath || jsPath) {
Copy link
Member

Choose a reason for hiding this comment

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

What is this if for?

}

_printListOutput({ logicFunctionsList }) {
this.ui.stdout.write(`Logic Functions currently deployed in your ${getOrgName(this.org)}:${os.EOL}`);
Copy link
Member

Choose a reason for hiding this comment

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

General comment for another PR: make getOrgName return "your Sandbox" or the name of the org so that the messages print like this:
Logic Functions currently deployed in your Sandbox
Logic Functions currently deployed in Particle

instead of currently which would show
Logic Functions currently deployed in your Particle

@keeramis keeramis merged commit 6ec5118 into feature/logic-function Dec 8, 2023
5 checks passed
@monkbroc monkbroc deleted the feature/logic-function-get branch January 19, 2024 19:42
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