[PR #4275] [MERGED] feat(cli): add support for request variables #4733

Closed
opened 2026-03-17 02:14:35 +03:00 by kerem · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/hoppscotch/hoppscotch/pull/4275
Author: @jamesgeorge007
Created: 8/19/2024
Status: Merged
Merged: 8/26/2024
Merged by: @nivedin

Base: nextHead: feat/cli-request-variables


📝 Commits (1)

  • 89656fc feat: add support for request variables in the CLI

📊 Changes

8 files changed (+449 additions, -45 deletions)

View changed files

📝 packages/hoppscotch-cli/package.json (+1 -1)
📝 packages/hoppscotch-cli/src/__tests__/e2e/commands/test.spec.ts (+40 -0)
packages/hoppscotch-cli/src/__tests__/e2e/fixtures/collections/request-vars-coll.json (+188 -0)
packages/hoppscotch-cli/src/__tests__/e2e/fixtures/environments/request-vars-envs.json (+34 -0)
📝 packages/hoppscotch-cli/src/__tests__/unit/getters.spec.ts (+107 -9)
📝 packages/hoppscotch-cli/src/utils/getters.ts (+38 -9)
📝 packages/hoppscotch-cli/src/utils/pre-request.ts (+40 -25)
📝 packages/hoppscotch-cli/src/utils/request.ts (+1 -1)

📄 Description

Description

This PR adds support for request variables in the CLI. Request variables will have the topmost priority, meaning they will be preferred over any environment variables sharing the same name.

Closes HFE-552.

Changes

  • New getResolvedVariables() helper function added under ~/utils/getters.ts that takes in the list of request variables and environment variables for a session and returns a resolved list of variables where keys sharing the same name from environment variables are removed ensuring request variables take priority.
  • Relevant instances are updated to account for request variables, alongside environment variables via the above helper function.
  • Relevant test updates and associated fixture additions.
  • Bumps CLI version to 0.11.0.

Notes to reviewers

Steps to verify

Navigate to the hoppscotch-cli package path locally, and run pnpm build. Run the collection via:

secretBasicAuthPasswordEnvVar=password  bin/hopp.js test <collection_export_file_path> --env <environment_export_file_path>

secretBasicAuthPasswordEnvVar being a secret environment variable, can either be supplied along with environment variables for the session as above or specifying the value field in the environment export file.

The collection and environment export files added under test fixtures can be used to verify the behaviour comprising relevant tests covering various scenarios where a request variable comes into play:

  • Ignores inactive request variables.
  • Usage alongside environment variables where request variables take priority and ensure support for recursive resolution.

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/hoppscotch/hoppscotch/pull/4275 **Author:** [@jamesgeorge007](https://github.com/jamesgeorge007) **Created:** 8/19/2024 **Status:** ✅ Merged **Merged:** 8/26/2024 **Merged by:** [@nivedin](https://github.com/nivedin) **Base:** `next` ← **Head:** `feat/cli-request-variables` --- ### 📝 Commits (1) - [`89656fc`](https://github.com/hoppscotch/hoppscotch/commit/89656fcbe164b061a6a3567fdd63eb5c33b42d6f) feat: add support for request variables in the CLI ### 📊 Changes **8 files changed** (+449 additions, -45 deletions) <details> <summary>View changed files</summary> 📝 `packages/hoppscotch-cli/package.json` (+1 -1) 📝 `packages/hoppscotch-cli/src/__tests__/e2e/commands/test.spec.ts` (+40 -0) ➕ `packages/hoppscotch-cli/src/__tests__/e2e/fixtures/collections/request-vars-coll.json` (+188 -0) ➕ `packages/hoppscotch-cli/src/__tests__/e2e/fixtures/environments/request-vars-envs.json` (+34 -0) 📝 `packages/hoppscotch-cli/src/__tests__/unit/getters.spec.ts` (+107 -9) 📝 `packages/hoppscotch-cli/src/utils/getters.ts` (+38 -9) 📝 `packages/hoppscotch-cli/src/utils/pre-request.ts` (+40 -25) 📝 `packages/hoppscotch-cli/src/utils/request.ts` (+1 -1) </details> ### 📄 Description ### Description This PR adds support for request variables in the CLI. Request variables will have the topmost priority, meaning they will be preferred over any environment variables sharing the same name. Closes HFE-552. ### Changes - New `getResolvedVariables()` helper function added under [~/utils/getters.ts](https://github.com/hoppscotch/hoppscotch/pull/4275/files#diff-484af5d66255ca92b321d69e2ad27f54a0323413d566793f2a117e15cceb3261) that takes in the list of request variables and environment variables for a session and returns a resolved list of variables where keys sharing the same name from environment variables are removed ensuring request variables take priority. - Relevant instances are updated to account for request variables, alongside environment variables via the above helper function. - Relevant test updates and associated fixture additions. - Bumps CLI version to `0.11.0`. ### Notes to reviewers > Steps to verify Navigate to the `hoppscotch-cli` package path locally, and run `pnpm build`. Run the collection via: ```sh secretBasicAuthPasswordEnvVar=password bin/hopp.js test <collection_export_file_path> --env <environment_export_file_path> ``` > `secretBasicAuthPasswordEnvVar` being a secret environment variable, can either be supplied along with environment variables for the session as above or specifying the `value` field in the environment export file. The [collection](https://github.com/hoppscotch/hoppscotch/pull/4275/files#diff-b30c6de10a80e19976a7b4bd00765268a2270b14fdc633aefa4e561aca7f9de2) and [environment](https://github.com/hoppscotch/hoppscotch/pull/4275/files#diff-dab0020edfa6b4903699f6ae2b091df8f3ad261f8550ad2875011d5c74fa87cf) export files added under test fixtures can be used to verify the behaviour comprising relevant tests covering various scenarios where a request variable comes into play: - Ignores inactive request variables. - Usage alongside environment variables where request variables take priority and ensure support for recursive resolution. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
kerem 2026-03-17 02:14:35 +03:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/hoppscotch#4733
No description provided.