static async load()

in ui/models/taskcluster.js [84:144]


  static async load(decisionTaskID, job, currentRepo, testMode = false) {
    if (!decisionTaskID) {
      throw Error("No decision task, can't find taskcluster actions");
    }
    const rootUrl = checkRootUrl(currentRepo.tc_root_url);
    const queue = await taskcluster.getQueue(rootUrl, testMode);

    const actionsUrl = queue.buildUrl(
      queue.getLatestArtifact,
      decisionTaskID,
      'public/actions.json',
    );
    const knownKinds = ['task', 'hook'];

    let originalTaskId;
    let originalTaskPromise = Promise.resolve(null);

    if (job) {
      originalTaskId = job.task_id;
      const queue = await taskcluster.getQueue(rootUrl, testMode);
      originalTaskPromise = queue.task(originalTaskId);
    }

    return Promise.all([fetch(actionsUrl), originalTaskPromise]).then(
      async ([response, originalTask]) => {
        const jsonData = await response.json();

        if (!jsonData) {
          throw Error('Unable to load actions.json');
        }

        if (jsonData.version !== 1) {
          throw Error('Wrong version of actions.json, unable to continue');
        }

        // The filter in the value of the actions key is an implementation
        // of the specification for action context in
        // https://docs.taskcluster.net/docs/manual/design/conventions/actions/spec
        // It decides if the specific action is applicable for this task.
        return {
          originalTask,
          originalTaskId,
          staticActionVariables: jsonData.variables,
          actions: jsonData.actions.reduce((actions, action) => {
            if (
              knownKinds.includes(action.kind) &&
              !actions.some(({ name }) => name === action.name) &&
              ((!action.context.length && !originalTask) ||
                (originalTask &&
                  originalTask.tags &&
                  this.taskInContext(action.context, originalTask.tags)))
            ) {
              return actions.concat(action);
            }

            return actions;
          }, []),
        };
      },
    );
  }