bruno icon indicating copy to clipboard operation
bruno copied to clipboard

Feature/add execution context

Open tlaloc911 opened this issue 1 year ago • 3 comments

Description

In reference to https://github.com/usebruno/bruno/issues/1874 I have the need to now the execution context of the request:

  1. Name of the Request executed
  2. Path of the .bru name
  3. Execution mode: single, runner, cli
  4. Associated documentation of the request

This will allow me to take some decisions in scripts, such as how to name logs, where to find data associated to every request, apply or exclude some tests depending on the way it is launched, etc.

Pre Request script example

console.log("-------- executionMode ----------")
console.log(bru.getVar("executionMode"))
console.log("-------- pathname ----------")
console.log(bru.getVar("currentItem").pathname)
console.log("-------- filename ----------")
console.log(bru.getVar("currentItem").filename)

Outputs

image image image

Contribution Checklist:

  • [X] The pull request only addresses one issue or adds one feature.
  • [X] The pull request does not introduce any breaking changes
  • [X] I have added screenshots or gifs to help explain the change if applicable.
  • [X] I have read the contribution guidelines.
  • [X] Create an issue and link to the pull request.

Note: Keeping the PR small and focused helps make it easier to review and merge. If you have multiple changes you want to make, please consider submitting them as separate pull requests.

Publishing to New Package Managers

Please see here for more information.

tlaloc911 avatar Mar 21 '24 00:03 tlaloc911

Interesting idea! But I worry about potential name-conflicts with user-defined variables.

How about attaching this info to the bru object? Something like

bru.context.executionMode
bru.context.currentItem

In Postman, there was pm.request.name for the currentItem.fileName...

mjhcorporate avatar Mar 21 '24 09:03 mjhcorporate

hi @mjhcorporate, in fact, I wanted to include it in the request object, but I notice the req object is different depending on the context: single request, runner or cli and I prefer not to touch it because it can break somenone's script

tlaloc911 avatar Mar 21 '24 23:03 tlaloc911

Yes, I agree that we should not put it on the request object, and that we should not break existing scripts. I think attaching new properties to the bru object is the safest path forward.

mjhcorporate avatar Mar 22 '24 13:03 mjhcorporate