-
Notifications
You must be signed in to change notification settings - Fork 2
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
Providers schema #53
Providers schema #53
Conversation
johncalesp
commented
Mar 28, 2023
- Added a new setting so users can reference external JSON files about cloud instances
- Added new JSON schema for cloud providers
- Change references to pull data from centML S3 bucket
- Changed README file to let users know about our JSON schema
… testing | changed parsers.js
code: `status: ${resp.statusText} | code: ${resp.status}`, | ||
}); | ||
} | ||
} else { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Identical blocks of code found in 2 locations. Consider refactoring.
this.errors = []; | ||
} | ||
} | ||
export const loadJsonFiles = async (habitatData, additionalProviders) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function loadJsonFiles
has 77 lines of code (exceeds 25 allowed). Consider refactoring.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You could refactor by wrapping some repeated logic with helper functions
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
moved logic to utils.js
logo: cloudProvider.logo, | ||
color: cloudProvider.color, | ||
}; | ||
for (const instanceData of cloudProvider.instances) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Avoid deeply nested control flow statements.
<DeploymentTab numIterations={numIterations} habitatData={data} /> | ||
); | ||
// Mock fetch response | ||
jest.spyOn(global, 'fetch').mockResolvedValue({ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Identical blocks of code found in 3 locations. Consider refactoring.
// ARRANGE | ||
// Mock fetch response | ||
jest.spyOn(global, 'fetch').mockResolvedValue({ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Identical blocks of code found in 3 locations. Consider refactoring.
|
||
const { ResizeObserver } = window; | ||
const numIterations = 10000; | ||
|
||
const data = [ | ||
const habitatData = [ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Similar blocks of code found in 3 locations. Consider refactoring.
// ARRANGE | ||
const { container } = render(<ProviderPanel numIterations={numIterations} habitatData={noHabitatData} />); | ||
// Mock fetch response | ||
jest.spyOn(global, 'fetch').mockResolvedValue({ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Identical blocks of code found in 3 locations. Consider refactoring.
["RTX4000", 20.2342], | ||
]; | ||
|
||
const correctData = [ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Identical blocks of code found in 2 locations. Consider refactoring.
@@ -19,6 +21,35 @@ const data = [ | |||
["RTX4000", 20.2342], | |||
]; | |||
|
|||
const correctData = [ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Identical blocks of code found in 2 locations. Consider refactoring.
})), | ||
}); | ||
} | ||
} catch (error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Identical blocks of code found in 2 locations. Consider refactoring.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You could encapsulate this into a helper function
README.md
Outdated
@@ -29,14 +29,44 @@ To install, either: | |||
Once you have the vsix file, run `code --install-extension vscode*.vsix` to install the extension. | |||
**Note: the file [build_vsix_dev.sh] is only to be used for development** | |||
|
|||
**Adding cloud instances to the Deployment Tab:** You can include information about the instances that you use thrugh the extension settings. There you will find an option named **providers** that accepts a list of urls separated by commas. Each url must be a JSON file that follows the schema speficied here : [schema](skyline-vscode/react-ui/src/schema/CloudProvidersSchema.js).<br/> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
typo on "specified"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
README.md
Outdated
@@ -29,14 +29,44 @@ To install, either: | |||
Once you have the vsix file, run `code --install-extension vscode*.vsix` to install the extension. | |||
**Note: the file [build_vsix_dev.sh] is only to be used for development** | |||
|
|||
**Adding cloud instances to the Deployment Tab:** You can include information about the instances that you use thrugh the extension settings. There you will find an option named **providers** that accepts a list of urls separated by commas. Each url must be a JSON file that follows the schema speficied here : [schema](skyline-vscode/react-ui/src/schema/CloudProvidersSchema.js).<br/> | |||
Addittionally, you need to add the necessary access so the extension can read the file.<br/> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Typo on Additionally
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
export const loadJsonFiles = async (habitatData, additionalProviders) => { | ||
const buffer = new ResponseBuffer(); | ||
let urlList = [ | ||
"https://deepview-explorer-public.s3.amazonaws.com/vscode-cloud-providers/providers.json", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be stored as a constant in properties.js
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
moved variable to properties.js
const ajv = new Ajv({ allErrors: true }); // to report all validation errors (rather than failing on the first errors) | ||
const validate = ajv.compile(cloudProviderSchema); | ||
|
||
class ResponseBuffer { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rename this so it is more clear what is used for
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
class was deleted
})), | ||
}); | ||
} | ||
} catch (error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You could encapsulate this into a helper function
this.errors = []; | ||
} | ||
} | ||
export const loadJsonFiles = async (habitatData, additionalProviders) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You could refactor by wrapping some repeated logic with helper functions
const ajv = new Ajv({ allErrors: true }); // to report all validation errors (rather than failing on the first errors) | ||
const validate = ajv.compile(cloudProviderSchema); | ||
|
||
export const loadJsonFiles = async (habitatData, additionalProviders) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function loadJsonFiles
has 68 lines of code (exceeds 25 allowed). Consider refactoring.
fill: "#ea4335", | ||
z: 200, | ||
}); | ||
expect(resp.instanceArray).toContainEqual({ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Similar blocks of code found in 2 locations. Consider refactoring.
import { enableFetchMocks } from "jest-fetch-mock"; | ||
enableFetchMocks(); | ||
|
||
const habitatData = [ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Similar blocks of code found in 3 locations. Consider refactoring.
}, | ||
}); | ||
expect(resp.instanceArray.length).toEqual(2); | ||
expect(resp.instanceArray).toContainEqual({ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Similar blocks of code found in 2 locations. Consider refactoring.
json: jest.fn().mockResolvedValue(correctData) | ||
}) | ||
|
||
const { container } = render( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Similar blocks of code found in 3 locations. Consider refactoring.
} | ||
|
||
export function fetchingURLErrors(type, response, validationErrors) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this function should function is doing too much specific work and not general work. I think you should keep the general case. For the invalid schema error, you can revert that change and have this only handle errors when fetching URLs.
Also I think you should remain the function to the active voice (e.g. getErrMsgFromInvalidURL
const ajv = new Ajv({ allErrors: true }); // to report all validation errors (rather than failing on the first errors) | ||
const validate = ajv.compile(cloudProviderSchema); | ||
|
||
export const loadJsonFiles = async (habitatData, additionalProviders) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function loadJsonFiles
has 74 lines of code (exceeds 25 allowed). Consider refactoring.
ok: true, | ||
json: jest.fn().mockResolvedValue(correctData) | ||
}) | ||
const { container } = render(<ProviderPanel numIterations={numIterations} habitatData={noHabitatData} additionalProviders={""}/>); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Similar blocks of code found in 3 locations. Consider refactoring.
const ajv = new Ajv({ allErrors: true }); // to report all validation errors (rather than failing on the first errors) | ||
const validate = ajv.compile(cloudProviderSchema); | ||
|
||
export const loadJsonFiles = async (habitatData, additionalProviders) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function loadJsonFiles
has a Cognitive Complexity of 24 (exceeds 5 allowed). Consider refactoring.
]; | ||
|
||
test("Validate JSON file (URL) and return list of cloud providers and instances", async () => { | ||
jest.spyOn(global, "fetch").mockResolvedValue({ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Similar blocks of code found in 2 locations. Consider refactoring.
}); | ||
|
||
test("JSON file (URL) is not in the correct format", async () => { | ||
jest.spyOn(global, "fetch").mockResolvedValue({ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Similar blocks of code found in 2 locations. Consider refactoring.
Code Climate has analyzed commit 2349588 and detected 19 issues on this pull request. Here's the issue category breakdown:
View more on Code Climate. |