static async retrigger()

in ui/models/job.js [89:163]


  static async retrigger(
    jobs,
    currentRepo,
    notify,
    times = 1,
    decisionTaskIdMap = null,
    testMode = false,
  ) {
    const jobTerm = jobs.length > 1 ? 'jobs' : 'job';
    try {
      notify(`Attempting to retrigger/add ${jobTerm} via actions.json`);

      const pushIds = [...new Set(jobs.map((job) => job.push_id))];
      const taskIdMap =
        decisionTaskIdMap ||
        (await PushModel.getDecisionTaskMap(pushIds, notify));
      const uniquePerPushJobs = groupBy(jobs, (job) => job.push_id);

      for (const [key, value] of Object.entries(uniquePerPushJobs)) {
        const decisionTaskId = taskIdMap[key].id;

        TaskclusterModel.load(decisionTaskId, null, currentRepo, testMode)
          .then(async (results) => {
            const taskLabels = value.map((job) => job.job_type_name);

            let retriggerAction = results.actions.find(
              (action) => action.name === 'retrigger-multiple',
            );
            let actionInput = {
              requests: [{ tasks: taskLabels, times }],
            };
            if (!retriggerAction) {
              // The `retrigger-multiple` action as introduced in Bug 1521032, to all the action
              // to control whether new task are created, or existing ones re-run. We fall back
              // to `add-new-jobs` to support pushing old revision to try, where the duplicating
              // the release tasks impacted is unlikely to cause problems.
              retriggerAction = getAction(results.actions, 'add-new-jobs');
              actionInput = {
                tasks: taskLabels,
              };
            }

            await TaskclusterModel.submit({
              action: retriggerAction,
              decisionTaskId,
              taskId: null,
              task: null,
              input: actionInput,
              staticActionVariables: results.staticActionVariables,
              currentRepo,
              testMode,
            })
              .then((actionTaskId) =>
                notify(
                  `Request sent to retrigger/add new jobs via actions.json (${actionTaskId})`,
                ),
              )
              .catch((error) => {
                notify(
                  `Retrigger failed with Decision task: ${decisionTaskId}: ${error}`,
                  'danger',
                  { sticky: true },
                );
              });
          })
          .catch((error) => notify(error.message, 'danger', { sticky: true }));
      }
    } catch (e) {
      notify(
        `Unable to retrigger/add ${jobTerm}.  ${formatTaskclusterError(e)}`,
        'danger',
        { sticky: true },
      );
    }
  }