pact-foundation / pact-js-cli

The Broker CLI for Pact, but available to your node scripts
MIT License
2 stars 1 forks source link

Extend 'canDeploy" and add "record-deployment" for full pact-broker CLI typescript support #11

Closed stefanhalbritterpdg closed 4 months ago

stefanhalbritterpdg commented 4 months ago

Feature description

As a developer, I would like to see next to publishPacts

Use case

Hi folks,

personally I like it more to use the pact-cli programatically directly in our node projects as code.

pact-publish.mjs

function publishPacts() {
  // doing some fetching token stuff with fetch
  const token = ....

  await pact.publishPacts({
    ...
    pactBrokerToken: token
  })
}
publishPacts()
pact-canDeploy.mjs

fucntion canDeploy() {
  // doing some fetching token stuff with fetch
  const token = ....
  ...

  await pact.canDeploy({
    ...
    environment: 'production'
    pactBrokerToken: token
    ...
  })
}
canDeploy()
pact-recordDeployment.mjs

fucntion recordDeployment() {
  // doing some fetching token stuff with fetch
  const token = ....

  await pact.recordDeployment({
    ...
    environment: 'production'
    pactBrokerToken: token
    ...
  })
}
recordDeployment()
package.json

   ...
  "scripts": {
      "pact:can-i-deploy": "node pact-can-i-deploy.mjs",
      "pact:publish": "node pact-publish.mjs",
      "pact:record-deployment": "node pact-record-deployment.mjs"
      ...
  }

Maybe you already planned to implement this in the future but there was no capacity (yet). If it sounds like a good idea, maybe we can talk about a contribution.

Kind regards

YOU54F commented 4 months ago

Hey Stefan,

we generally recommend installing the cli tools directly, as a user would get the latest corresponding changes without needing to wait for them to be implemented in client language wrappers.

We also lack visibility into who are using the cli tools directly or via wrappers, so often the additional flags are not added until people request them.

more broadly, i think i would like to replace the ruby implementation with rust

my wip is here https://github.com/YOU54F/pact_cli

your proposals sound good, and I’d be more than happy to accept contributions to extend the current func to be in line with the cli tools, and for any enhancements that make it easier for programmatic use

stefanhalbritterpdg commented 4 months ago

Thank you for the quick response @YOU54F!

when it is recommended using the cli tools directly, then we probably wrap the pact-broker CLI calls with typescript this way and we would renounce to extend the language wrapper for typescript

execSync(
            `pact-broker publish  pacts --branch ..... --broker-base-url .....`,
            { stdio: 'inherit' },
        )

Kind regards Stefan