-
Notifications
You must be signed in to change notification settings - Fork 1
feat: Add input field to select finished run state for triggers #56
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
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR adds a multiple choice dropdown input field for actor/task run triggers that allows filtering based on terminal run states. The key changes include updating test bundles to include a new "states" field, adding a new field in the trigger definitions with choices from ACTOR_RUN_TERMINAL_STATES, and modifying the webhook subscription helper to dynamically compute event types based on the selected states.
Reviewed Changes
Copilot reviewed 7 out of 8 changed files in this pull request and generated no comments.
Show a summary per file
File | Description |
---|---|
test/triggers/task_run_finished.js | Updated test input to include "states" using Object.keys(ACTOR_RUN_TERMINAL_STATES). |
test/triggers/actor_run_finished.js | Updated test input to include "states" using Object.keys(ACTOR_RUN_TERMINAL_STATES). |
src/triggers/task_run_finished.js | Added new "states" field (dropdown) for task run triggers. |
src/triggers/actor_run_finished.js | Added new "states" field (dropdown) for actor run triggers. |
src/consts.js | Defined ACTOR_RUN_TERMINAL_STATES with terminal state mappings. |
src/apify_helpers.js | Modified subscribeWebhook to compute eventTypes from filtered states. |
CHANGELOG.md | Documented the new feature in the changelog. |
Files not reviewed (1)
- package.json: Language not supported
Comments suppressed due to low confidence (2)
src/triggers/task_run_finished.js:48
- [nitpick] The helpText for the 'states' field in the task run trigger still refers to 'actor'. Consider updating the text to clarify that it applies to task runs or to use terminology consistent with the trigger's context.
{ label: 'States', helpText: 'Please select the terminal states of the actor.', key: 'states', required: true, list: true, choices: ACTOR_RUN_TERMINAL_STATES, },
src/apify_helpers.js:135
- [nitpick] Consider adding test cases for scenarios with duplicate states and for custom, potentially invalid state values in the input to ensure that subscribeWebhook handles these cases correctly.
const states = Array.from(new Set(bundle.inputData.states));
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good start :)
On top of my comments please:
- Update performList to use statuses for Actor/task see https://github.com/apify/apify-zapier-integration/pull/56/files#diff-d4fdc89364a70fd9a9f2a2b27eb9757764de197b2270aaf351f83bbe1894b3ffR58
- Add tests cover new code
src/consts.js
Outdated
@@ -270,6 +270,13 @@ const ALLOWED_MEMORY_MBYTES_LIST = Array.from( | |||
|
|||
const DEFAULT_ACTOR_MEMORY_MBYTES = 2048; | |||
|
|||
const ACTOR_RUN_TERMINAL_STATES = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As keys please use enums from apify consts
https://github.com/apify/apify-shared-js/blob/master/packages/consts/src/consts.ts#L30
src/triggers/actor_run_finished.js
Outdated
label: 'States', | ||
helpText: 'Please select the terminal states of the actor run.', | ||
key: 'states', | ||
required: true, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Please use the default values the same as in the previous version of the WEBHOOK_EVENT_TYPE_GROUPS.ACTOR_RUN_TERMINAL
- Make the field optional, and if the user did not fill any state use WEBHOOK_EVENT_TYPE_GROUPS.ACTOR_RUN_TERMINAL as fallback
If we do it like this we did not break, as we keep current behaviour
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Comment this behaviour in help text mainly the fact that if no value is provided we use all terminal state as fallback.
src/triggers/actor_run_finished.js
Outdated
@@ -40,6 +40,14 @@ module.exports = { | |||
required: true, | |||
dynamic: 'actors.id.name', | |||
}, | |||
{ | |||
label: 'States', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is status not state :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's update it everywhere
src/triggers/actor_run_finished.js
Outdated
@@ -40,6 +40,14 @@ module.exports = { | |||
required: true, | |||
dynamic: 'actors.id.name', | |||
}, | |||
{ | |||
label: 'States', | |||
helpText: 'Please select the terminal states of the actor run.', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actor always with a capital, please check writing guide.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And the helpText need some love, let's consult this with some copy writer where we will be done with code changes.
@drobnikj Thank you for the review. I believe that I've address most of your comments from the review. The only thing that I'm not sure how to update the Would this be a good solution or do you have any other ideas about this? |
@matyascimbulka There is already an issue on the platform to add support for this. But in the meantime let's make multiple requests, it is not nice workaround but it can work. |
@drobnikj I think I have managed to address all of your comments. As far as the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR adds a multiple‐choice dropdown input field to allow filtering of actor/task run triggers by terminal state. Key changes include new test cases to verify webhook creation with various status combinations, updates to the task and actor trigger implementations to use the selected statuses, and the addition of a new constant for terminal statuses.
Reviewed Changes
Copilot reviewed 8 out of 9 changed files in this pull request and generated 2 comments.
Show a summary per file
File | Description |
---|---|
test/triggers/create_webhook_with_status.js | New tests verifying webhook creation for actor/task triggers with terminal status filtering |
src/triggers/task_run_finished.js | Updated filtering logic and added the statuses field for task triggers |
src/triggers/actor_run_finished.js | Updated filtering logic and added the statuses field for actor triggers |
src/consts.js | Added constant ACTOR_RUN_TERMINAL_STATUSES for terminal statuses |
src/apify_helpers.js | Introduced getActorStatusesFromBundle and updated subscribeWebhook to support status mapping |
CHANGELOG.md | Updated changelog to document the new feature |
Files not reviewed (1)
- package.json: Language not supported
.post('/v2/webhooks', (payload) => { | ||
expect(payload).to.have.property('requestUrl', requestUrl); | ||
expect(payload).to.have.property('condition').that.has.property('actorId', testActorId); | ||
expect(payload).to.have.property('eventTypes') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The test expects WEBHOOK_EVENT_TYPES.ACTOR_RUN_TIMED_OUT to be both included (line 39) and excluded (line 41) from the eventTypes array. Please revisit the intended behavior and update the assertions accordingly.
Copilot uses AI. Check for mistakes.
src/apify_helpers.js
Outdated
// Process to subscribe to Apify webhook | ||
const subscribeWebhook = async (z, bundle, condition) => { | ||
const statuses = getActorStatusesFromBundle(bundle); | ||
|
||
const eventTypes = statuses.map((status) => status.replace('-', '_')).map((status) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mapping the statuses to event types may produce undefined values when no match is found. Consider filtering out these undefined values before using the array in webhookOpts.
Copilot uses AI. Check for mistakes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just last bits
src/triggers/task_run_finished.js
Outdated
@@ -45,6 +46,14 @@ module.exports = { | |||
required: true, | |||
dynamic: 'tasks.id.name', | |||
}, | |||
{ | |||
label: 'Statuses', | |||
helpText: 'Please select the terminal states of the task run. If no status is selected, all terminal statuses will be used.', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
helpText: 'Please select the terminal states of the task run. If no status is selected, all terminal statuses will be used.', | |
helpText: 'Select one or more terminal statuses for the run. If none are selected, all terminal statuses will be included by default.', |
src/apify_helpers.js
Outdated
// Process to subscribe to Apify webhook | ||
const subscribeWebhook = async (z, bundle, condition) => { | ||
const statuses = getActorStatusesFromBundle(bundle); | ||
|
||
const eventTypes = statuses.map((status) => status.replace('-', '_')).map((status) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wow, I have no idea that we designed it that bad :D mixing -
and _
.
src/apify_helpers.js
Outdated
|
||
const eventTypes = statuses.map((status) => status.replace('-', '_')).map((status) => { | ||
// eslint-disable-next-line no-restricted-syntax | ||
for (const eventType of Object.values(WEBHOOK_EVENT_TYPES)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not nice you need to loop every time.
What about doing a simple key-value object or Map where you map status to event time and use this?
You would not need to replace '-', '_'.
src/triggers/actor_run_finished.js
Outdated
@@ -40,6 +41,14 @@ module.exports = { | |||
required: true, | |||
dynamic: 'actors.id.name', | |||
}, | |||
{ | |||
label: 'Statuses', | |||
helpText: 'Please select the terminal statuses of the Actor run. If no status is selected, all terminal statuses will be used.', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
helpText: 'Please select the terminal statuses of the Actor run. If no status is selected, all terminal statuses will be used.', | |
helpText: 'Select one or more terminal statuses for the run. If none are selected, all terminal statuses will be included by default.', |
Thank you for the suggestions. I have implemented them and its ready for review again. The test version on Zapier is |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR adds a multiple choice dropdown for selecting terminal run statuses in actor/task triggers to enable free users to filter runs by terminal state. The key changes include updating trigger logic to filter runs based on selected statuses, adding new constants for terminal statuses/event types, and updating tests to validate the new behavior.
Reviewed Changes
Copilot reviewed 8 out of 9 changed files in this pull request and generated no comments.
Show a summary per file
File | Description |
---|---|
test/triggers/create_webhook_with_status.js | Added new test cases for multiple status selections and handling of invalid status values. |
src/triggers/task_run_finished.js | Updated run filtering logic to consider multiple terminal statuses from bundle input. |
src/triggers/actor_run_finished.js | Updated run filtering logic and added a new input field for selecting terminal statuses. |
src/consts.js | Introduced constants for ACTOR_RUN_TERMINAL_STATUSES and ACTOR_RUN_TERMINAL_EVENT_TYPES. |
src/apify_helpers.js | Added a helper function (getActorStatusesFromBundle) to deduplicate and validate status values and map them correctly. |
CHANGELOG.md | Documented the new feature and its behavior. |
Files not reviewed (1)
- package.json: Language not supported
Comments suppressed due to low confidence (2)
test/triggers/create_webhook_with_status.js:121
- [nitpick] The test description has a duplicate 'with'; consider renaming it to 'create webhook with wrong values' for clarity.
it('create webhook with with wrong values', async () => {
src/apify_helpers.js:140
- To ensure consistency with the new constants introduced in src/consts.js, consider using ACTOR_RUN_TERMINAL_STATUSES instead of ACTOR_JOB_TERMINAL_STATUSES as the fallback.
return filteredStatuses.length > 0 ? filteredStatuses : ACTOR_JOB_TERMINAL_STATUSES;
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just one nit, but approving anyway.
Let's add someone from content team to check helpText etc.
I added @TheoVasilis as he checked some content in the Zapier app in the past. |
Changing to @davidjohnbarton as Theo is off. |
Links to issue #16.
This change adds a multiple choice dropdown input field for actor / task run triggers which allows selection of specific terminal state for the trigger. As describe in #16 this change will allow free users to filter the runs based on the terminal status.
This solution has a few issues that mostly stem from imperfections in Zapier input UI and it's currently possible to select one state more then once and even enter a custom value to the dropdown. However, both cases are handled in the code and result in creation of correct web hooks.
For reference here is a screenshot of the resulting input UI on the Zapier platform:
