Skip to content

Conversation

@JoshuaSBrown
Copy link
Collaborator

@JoshuaSBrown JoshuaSBrown commented Jan 2, 2025

PR Description

JavaScript code needs quality controls which are currently missing this is an attempt to add them.

Tasks

  • - Formatter has been run
  • - CHANGELOG comment has been added
  • - Labels have been assigned to the pr
  • - A reviwer has been added
  • - A user has been assigned to work on the pr

Summary by Sourcery

Add JavaScript linting and formatting using ESLint and Prettier.

CI:

  • Add a GitHub action to lint and format JavaScript code using ESLint and Prettier.

Tests:

  • Add unit tests for the web application.

@sourcery-ai
Copy link
Contributor

sourcery-ai bot commented Jan 2, 2025

Reviewer's Guide by Sourcery

This pull request introduces a GitHub action to lint and format JavaScript code. This addresses the current lack of quality controls for JavaScript code.

Sequence diagram for authorization check flow

sequenceDiagram
    participant Client
    participant AuthzWorker
    participant CoreService

    Client->>AuthzWorker: checkAuth(client_id, path, action)
    AuthzWorker->>AuthzWorker: isURLValid(path)
    AuthzWorker->>AuthzWorker: removeOrigin(path)
    AuthzWorker->>AuthzWorker: isPathValid(path)
    AuthzWorker->>AuthzWorker: isTestPath(path)
    alt is test path
        AuthzWorker-->>Client: return 0 (allowed)
    else not test path
        AuthzWorker->>CoreService: send authorization request
        CoreService-->>AuthzWorker: response
        AuthzWorker->>AuthzWorker: processResponse(response)
        AuthzWorker-->>Client: return result
    end
Loading

Class diagram for AuthzWorker refactoring

classDiagram
    class AuthzWorker {
        -Config* m_config
        -LogContext m_log_context
        -string m_local_globus_path_root
        -string m_test_path
        -map<CredentialType, string> m_cred_options
        -unique_ptr<ICredentials> m_sec_ctx
        -unique_ptr<ICommunicator> m_comm
        +AuthzWorker(Config*, LogContext)
        +checkAuth(char*, char*, char*) int
        -isTestPath(string) bool
        -isPathValid(string) bool
        -isURLValid(char*) bool
        -removeOrigin(char*) string
        -getAuthzPath(char*) string
        -processResponse(ICommunicator::Response&) int
        -initCommunicator() void
    }
    note for AuthzWorker "Refactored class with improved
modularity and error handling"
Loading

File-Level Changes

Change Details Files
Added a JavaScript linter and formatter GitHub action.
  • Added a JavaScript linter and formatter GitHub action workflow file.
  • Modified files to support the linter and formatter GitHub action.
  • Updated documentation to reflect the addition of the linter and formatter.
  • Updated version and changelog.
.gitlab/common.yml
repository/gridftp/globus5/authz/source/AuthzWorker.cpp
.gitlab/end_to_end.yml
scripts/ci_harbor_artifact_count.sh
scripts/ci_purge_images.sh
core/database/tests/test_setup.sh
docker/entrypoint_foxx.sh
web/static/util.js
core/database/tests/test_foxx.sh
core/server/main.cpp
web/datafed-ws.js
.gitlab/build/build_gcs_image.yml
.gitlab/build/build_gcs_base_image.yml
scripts/dependency_install_functions.sh
CMakeLists.txt
scripts/install_foxx.sh
.gitlab/build/build_ws_image.yml
.gitlab/build/force_build_gcs_base_image.yml
.gitlab/build/force_build_gcs_image.yml
.gitlab/build/build_foxx_image.yml
scripts/compose_build_images.sh
.gitlab/build/build_core_image.yml
.gitlab/stage_image_check.yml
scripts/generate_core_config.sh
.gitlab/stage_pipeline_serialize.yml
core/database/tests/test_teardown.sh
scripts/globus/setup_globus.sh
.gitlab/stage_build_base.yml
scripts/compose_generate_env.sh
.gitlab/build/force_build_ws_image.yml
common/include/common/DynaLog.hpp
web/docker/Dockerfile
.gitlab/build/force_build_core_image.yml
.gitlab/build/force_build_foxx_image.yml
.gitlab/build/force_build_repo_image.yml
CHANGELOG.md
cmake/Version.cmake
python/datafed_pkg/datafed/MessageLib.py
repository/gridftp/globus5/authz/CMakeLists.txt
scripts/dependency_versions.sh
repository/docker/entrypoint_authz.sh
tests/end-to-end/setup.sh
.github/workflows/unit-tests.yml
.gitlab-ci.yml
compose/metadata/build_metadata_images_for_compose.sh
scripts/install_authz_dependencies.sh
.gitlab/stage_clear_cache.yml
compose/all/compose.yml
compose/metadata/compose.yml
core/docker/Dockerfile
common/proto/common/SDMS.proto
common/proto/common/SDMS_Auth.proto
doc_source/source/admin/install_docker.rst
doc_source/source/dev/design.rst
docker/Dockerfile.dependencies
docker/Dockerfile.foxx
docker/Dockerfile.runtime
docs/_sources/admin/general.rst.txt
python/datafed_pkg/README
repository/docker/Dockerfile.gcs
web/package.json.in
web/version.js.in
Added unit tests for AuthzWorker.
  • Added unit tests for path validation, URL validation, origin removal, authorization path retrieval, and response processing.
  • Added testing for version retrieval.
  • Added a new VersionUtils class to the Python client for version-related utilities.
  • Updated CMakeLists.txt to include the new unit tests.
  • Added new dependencies for testing the authz worker.
  • Added unit tests for the new Globus getAuthorizeURL utility function.
repository/gridftp/globus5/authz/tests/unit/test_AuthzWorker.cpp
repository/gridftp/globus5/authz/source/AuthzWorker.hpp
python/datafed_pkg/datafed/VersionUtils.py
repository/gridftp/globus5/authz/tests/unit/test_getVersion.cpp
repository/gridftp/globus5/authz/tests/unit/CMakeLists.txt
cmake/GSSAPI.cmake
cmake/GlobusCommon.cmake
repository/gridftp/globus5/authz/tests/CMakeLists.txt
web/test/util.test.js
Added setup script for collection directory.
  • Added a new script to set up the collection directory, including permission checks and ownership setting.
scripts/globus/setup_collection_directory.sh

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time. You can also use
    this command to specify where the summary should be inserted.

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@JoshuaSBrown JoshuaSBrown changed the base branch from master to devel January 2, 2025 13:44
@JoshuaSBrown JoshuaSBrown self-assigned this Jan 2, 2025
@JoshuaSBrown JoshuaSBrown added the Component: Build Related to the build system label Jan 2, 2025
@JoshuaSBrown
Copy link
Collaborator Author

Currently the formatter is passing and not failing because formatting needs to be fixed in a separate PR. JavaScript formatter is set to pass inspite of failures currently.

Copy link
Contributor

@AronPerez AronPerez left a comment

Choose a reason for hiding this comment

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

actions/setup-node@v3 -> v4
actions/checkout@v3 -> v4

Linter + prettier config

- name: Install ESLint
run: |
npm init -y
npm install eslint@latest @babel/eslint-parser@latest eslint-define-config globals --save
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we want to add a package.json to manage these scripts? That way we could just run npm run lint

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This works as it is. What is the advantage of adding another file to the repo? I suppose if you want to test locally... and ensure the packages are the same?

"vueIndentScriptAndStyle": false,
"proseWrap": "preserve",
"insertPragma": false,
"printWidth": 100,
Copy link
Contributor

Choose a reason for hiding this comment

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

❓: Why 100 and not 120?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@t-ramz any particular reason, do you want to increase it?

Copy link
Collaborator

@t-ramz t-ramz Jan 3, 2025

Choose a reason for hiding this comment

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

No reason, I am happy to increase it. In fact, I don't particularly like width limits at all. More is more here.

"insertPragma": false,
"printWidth": 100,
"requirePragma": false,
"tabWidth": 4,
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: I'm a fan of 2 tabs per tab width personally

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Did you mean spaces? per tab? That is actually my default as well.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

But I don't feel strongly about this.

@@ -0,0 +1,21 @@
{
"arrowParens": "always",
Copy link
Contributor

Choose a reason for hiding this comment

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

❤️

"singleQuote": false,
"jsxSingleQuote": false,
"quoteProps": "as-needed",
"trailingComma": "all",
Copy link
Contributor

Choose a reason for hiding this comment

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

I like the es5 option

continue-on-error: true # Allow this job to fail without failing the entire workflow
run: |
prettier "**/*.js" --write
git diff
Copy link
Contributor

Choose a reason for hiding this comment

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

Why are we doing this?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Prettier won't show the differences, it just shows what files will be changed.

Comment on lines +4 to +11
module.exports = [{
languageOptions: {
globals: {
...globals.jquery,
...globals.node,
},
},
}];
Copy link
Contributor

Choose a reason for hiding this comment

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

We should extend prettier to prevent rule collision issues:

Suggested change
module.exports = [{
languageOptions: {
globals: {
...globals.jquery,
...globals.node,
},
},
}];
module.exports = [{
languageOptions: {
globals: {
...globals.jquery,
...globals.node,
},
},
plugins: ["prettier"],
extends: ["plugin:prettier/recommended"],
}];

Co-authored-by: Aaron Perez <aperez0295@gmail.com>
@JoshuaSBrown JoshuaSBrown requested a review from AronPerez January 2, 2025 18:32
@JoshuaSBrown JoshuaSBrown merged commit 0fe9096 into devel Jan 2, 2025
14 checks passed
@JoshuaSBrown JoshuaSBrown deleted the 1200-feature-github-action-javascript-linter-formatter branch January 2, 2025 20:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Component: Build Related to the build system

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[CI, Build] - Feature, we need a linter and formatter for all the JavaScript code

4 participants