Skip to content
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

Register custom handler to intercept URL of published report #1797

Open
aslakhellesoy opened this issue Sep 16, 2021 · 3 comments
Open

Register custom handler to intercept URL of published report #1797

aslakhellesoy opened this issue Sep 16, 2021 · 3 comments
Labels
✅ accepted The core team has agreed that it is a good idea to fix this ⚡ enhancement Request for new functionality

Comments

@aslakhellesoy
Copy link
Contributor

aslakhellesoy commented Sep 16, 2021

Is your feature request related to a problem? Please describe.

I would like to capture the URL of the published report so I can notify an external system with the report URL.

Describe the solution you'd like

I want to be able to register a function that will be called with the URL of the published report - something like this:

import { registerPublishListener } from '@cucumber/cucumber'

registerPublishListener(async function (reportUrl: string) {
   // Do something with the URL, for example send it to Slack
})

Describe alternatives you've considered

Redirecting STDERR to a file, then parse it with a shell script and send the message. That's quite a roundabout way of doing this.

Additional context

This is requested by a user of Cucumber Reports. See similar request here: cucumber/cucumber-jvm#2324

@aslakhellesoy aslakhellesoy added the ⚡ enhancement Request for new functionality label Sep 16, 2021
@tooky
Copy link
Member

tooky commented Sep 17, 2021

I thought I'd take a little look at this. I added a failing scenario in 2118d28.

As I started to dig into the code I think that the displayed banner is actually returned by the server receiving the HTTP message stream and then written as is to STDERR, see

const readerStream = new Writable({
objectMode: true,
write: function (responseBody: string, encoding, writeCallback) {
console.error(responseBody)
writeCallback()
},
})
.

@aslakhellesoy were you thinking that this resonse string should be parsed by Cucumber and the URL passed to the listener? This seems error prone.

Alternatively, we could send the entire response body to the listener and leave the parsing up to the listener implementation?

Should we consider changing the reports protocol to return more than just a message string?

@davidjgoss
Copy link
Contributor

davidjgoss commented Mar 3, 2022

I did some experimenting with this today and raised a draft #1950 with my progress.

As @tooky noted we don't have a definitive way to get the published URL. I did a scrappy implementation that takes the PUT URL and splits the identifier out of the path, but that's probably no better than parsing it out of the console message on balance.

@aslakhellesoy could we make a non-breaking change to the reports API so that with a Accept: application/json header in the initial GET request it will instead return a JSON representation something like:

{
  "url": "https://reports.cucumber.io/reports/XXXX-XXXX-XXXX-XXXX-XXXX",
  "message": "<terminal-formatted message as it is now>"
}

This would not break existing usages but would allow us to address this issue in newer ones.

@mattwynne
Copy link
Member

We could also send the report URL in a custom header.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
✅ accepted The core team has agreed that it is a good idea to fix this ⚡ enhancement Request for new functionality
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants