export async function retrigger()

in src/logic/taskcluster.ts [193:248]


export async function retrigger(retriggerJobConfig: {
  rootUrl: string;
  jobInfo: JobInformation;
  decisionTaskId: string;
  times: number;
}): Promise<string | null> {
  const { rootUrl, jobInfo, decisionTaskId, times } = retriggerJobConfig;

  if (!times) return null;

  const actionsResponse = await fetchActionsFromDecisionTask(
    rootUrl,
    decisionTaskId,
  );

  const retriggerAction = actionsResponse.actions.find(
    (action) => action.name === 'retrigger-multiple',
  );

  if (retriggerAction?.kind !== 'hook') {
    throw new Error('Missing hook kind for action');
  }

  // submit retrigger action to Taskcluster
  const context = Object.assign(
    {},
    {
      taskGroupId: decisionTaskId,
      taskId: jobInfo.task_id,
      input: {
        requests: [{ tasks: [jobInfo.job_type_name], times }],
      },
    },
    actionsResponse.variables,
  );

  const hookPayload = jsone(
    retriggerAction.hookPayload as Record<string, unknown>,
    context,
  ) as unknown;
  const { hookId, hookGroupId } = retriggerAction;
  const userCredentials = retrieveUserCredentials(rootUrl);
  const accessToken = userCredentials?.credentials.accessToken;

  if (!accessToken) {
    throw new Error('Missing access token for retriggering action.');
  }
  const hooks = new Hooks({
    rootUrl,
    credentials: userCredentials.credentials,
  });

  const response = await hooks.triggerHook(hookGroupId, hookId, hookPayload);

  return response.taskId;
}