MCPcopy Create free account
hub / github.com/github/gh-aw / createCountGatedHandler

Function createCountGatedHandler

actions/setup/js/handler_scaffold.cjs:34–56  ·  view source on GitHub ↗

* Creates a handler factory with shared max-count gating and processedCount state. * * This eliminates the duplicated scaffolding across safe-output handlers: * - Extracts maxCount from config (default 10) * - Resolves staged mode from config * - Maintains processedCount in closure * - Gates e

({ handlerType, setup })

Source from the content-addressed store, hash-verified

32 * @returns {HandlerFactoryFunction} Handler factory function compatible with the handler manager
33 */
34function createCountGatedHandler({ handlerType, setup }) {
35 return async function main(config = {}) {
36 const maxCount = config.max || 10;
37 const isStaged = isStagedMode(config);
38 let processedCount = 0;
39
40 const handleItem = await setup(config, maxCount, isStaged);
41
42 /** @type {MessageHandlerFunction} */
43 return async function handler(message, resolvedTemporaryIds) {
44 if (processedCount >= maxCount) {
45 core.warning(`Skipping ${handlerType}: max count of ${maxCount} reached`);
46 return {
47 success: false,
48 error: `Max count of ${maxCount} reached`,
49 };
50 }
51
52 processedCount++;
53 return handleItem(message, resolvedTemporaryIds);
54 };
55 };
56}
57
58module.exports = { createCountGatedHandler };

Callers 6

remove_labels.cjsFile · 0.85
assign_to_user.cjsFile · 0.85
replace_label.cjsFile · 0.85
add_labels.cjsFile · 0.85

Calls 2

isStagedModeFunction · 0.85
setupFunction · 0.85

Tested by

no test coverage detected