Sourcegraph: campaigns: applying `on: null`, `steps: null` throws error even though `on` and `steps` are not required

Created on 26 Oct 2020  ยท  3Comments  ยท  Source: sourcegraph/sourcegraph

When using a importChangesets campaign, omitting on and steps is legal: https://docs.sourcegraph.com/campaigns/how-tos/tracking_existing_changesets

If the keys are simply omitted in the YAML, applying the spec works without a hitch. However, when these are set to null:

โŒ Error:
   parsing campaign spec: 2 errors occurred:
        * on: Invalid type. Expected: array, given: null
        * steps: Invalid type. Expected: array, given: null

This is a bit of an edge case, because I'm not sure how many people will try to do this:

  1. make a graphql query for an existing spec - this returns a JSON spec with null in values that do not exist:
            query getCampaigns($namespace:String!) {
                organization(name:$namespace) {
                  campaigns(first:99) {
                    nodes { name currentSpec { parsedInput } }
                  }
                }
              }
  1. make changes to said campaign spec (e.g. append to importChangesets)
  2. turn this back into YAML and src campaign apply it. Without replacing null values, this attempts to apply something like:
name: release-sourcegraph-3.21.0
description: "[TEST] Track publishing of [email protected]"
on: null
steps: null
importChangesets:
  - ...
changesetTemplate:
  title: ""
  body: ""
  branch: ""
  commit:
    message: ""
  published: false

from the original spec:

name: release-sourcegraph-3.21.0
description: "[TEST] Track publishing of [email protected]"
importChangesets:
  - ...

and produces the error above

also see https://github.com/sourcegraph/sourcegraph/pull/15032

bug teacampaigns

All 3 comments

I think for updating the campaign spec, rawSpec instead of parsedInput should be used. I think we should still not add null fields, since it's not the same as not defined, from a yaml/json perspective.

originalInput (the correct spelling of rawSpec) worked nicely for the particular use-case described in the issue: https://github.com/sourcegraph/sourcegraph/pull/15032/commits/ea4f1a9777f12fa3fd25eeb3f9c8885ea5119f06

Sounds like moving to originalInput worked, so shall we close this issue? Or is there another part to this that I am missing?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

saveman71 picture saveman71  ยท  3Comments

felixfbecker picture felixfbecker  ยท  4Comments

attfarhan picture attfarhan  ยท  3Comments

beyang picture beyang  ยท  4Comments

dadlerj picture dadlerj  ยท  3Comments