Skip to content

Changesets are not re-opened and re-attached to a campaign if new apply adds them again

Created by: mrnugget

We need to re-open detached-and-closed-changesets when applying a new campaign spec. Otherwise we run into "changeset with same branch in other campaign exists".

How to reproduce this:

  1. Create a campaign spec that creates diffs in two repositories:
name: reproduce-bug
description: This results in a bug

on:
  - repository: github.com/sourcegraph/automation-testing
  - repository: bitbucket.sgdev.org/SOUR/automation-testing

steps:
  - run: echo "Hello World" > hello.md
    container: alpine:3

changesetTemplate:
  title: Hello
  body: Hello
  branch: bugs/hello
  commit:
    message: Hello
  published: true
  1. Apply it: src campaign apply -f bug.campaign.yaml -namespace mrnugget
  2. Two changesets in the two repositories should be created
  3. Change the on: list of repositories from 2 to 1 repositories
  4. Apply again.
  5. One changeset should be open, one closed (and detached from the campaign)
  6. Change the on: list of repositories back to the 2 repositories we had before.
  7. Apply again.
  8. The reconciler runs into an error because it tries to create a second changeset for the same repository on the same branch.

Idea: I think we need to also search for changesets where owned_by_campaign_id = campaign.id when we look for the campaigns current changesets in applyCampaign.

But then we also need to handle re-opening of changesets in the reconciler.