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:
- 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
- Apply it:
src campaign apply -f bug.campaign.yaml -namespace mrnugget - Two changesets in the two repositories should be created
- Change the
on:list of repositories from 2 to 1 repositories - Apply again.
- One changeset should be open, one closed (and detached from the campaign)
- Change the
on:list of repositories back to the 2 repositories we had before. - Apply again.
- 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.