Skip to content

batches: fix output variables display

Administrator requested to merge aa/fix-output-variables into main

Created by: BolajiOlajide

When executing a batch spec that contains non-string output variables, the UI runs into an error. Context.

This happens because the batch spec output variable has a field value that is of type JSONValue!in the batches.graphql, however when the graphql-operations.ts file is generated, the concept of JSONValue! isn't known, so the compiler interprets it as unknown and this is why ESLINT / TS doesn't catch that issue.

image

When the value of the output variable is wrapped in a valid HTML tag, it returns an error and that's because React doesn't know how to handle children that are of type unknown. image

Test plan

  • Create a batch change using a spec that contains output that are not in string format
name: hello
description: Run `eslint --fix` in repositories with `eslintrc[.js]` files.

on:
  - repositoriesMatchingQuery: file:^.eslintrc[\.js|\.json]? -repo:^github\.com/sourcegraph/sourcegraph$ -repo:^github\.com/BolajiOlajide/*

steps:
  # Dynamically print a YAML object on standard out with information about
  # which package manager is used.
  # We can use this to execute different steps.
  - run: |
      echo "usesYarn: $(test -f yarn.lock && echo true || echo false)" &&
      echo "usesNPM: $(test -f package-lock.json && echo true || echo false)"
    container: alpine:3
    outputs:
      packageManagers:
        value: ${{ step.stdout }}
        format: yaml
  # Use yarn to run eslint --fix if we detected yarn before.
  # exit 0 in any case, because we want the fixes, even though there might
  # still be warnings/errors.
  - run: yarn && yarn run eslint --fix --ext .js,.jsx,.ts,.tsx . || exit 0
    if: ${{ outputs.packageManagers.usesYarn }}
    container: node:14.0
  # Use npm if we detected npm.
  - run: |
      npm config set package-lock false \
        && npm install \
        && npm run eslint --fix --ext .js,.jsx,.ts,.tsx . || exit 0
    if: ${{ outputs.packageManagers.usesNPM }}
    container: node:14.0
changesetTemplate:
  title: Run eslint --fix
  body: The changes here were produced by running `eslint --fix`
  commit:
    message: Run `eslint --fix` in the directories
  branch: batch-changes/eslint-fix
  published: false
  • Execute the batch spec and confirm the output variables are displayed correctly image

App preview:

Check out the client app preview documentation to learn more.

Merge request reports

Loading