a8n: Implement `createCampaign` for Campaigns with a CampaignPlan
Created by: mrnugget
This is part of RFC 42. Read this section details.
When the createCampaign
mutation is called with a CampaignPlan
ID the following needs to happen:
- The
Diff
s of theCampaignPlan
'sCampaignJobs
are turned into commits in their respective repositories - Commits are made by a Sourcegraph bot
- These newly created commits are pushed up to the codehost
- The newly created commits are turned into pull requests on the code hosts
- On the Sourcegraph side, these new pull requests are turned into
Changeset
s - While this is happening asynchronously, the user can query
campaignResolver.ChangesetCreationStatus
Technical Notes
(These do not cover everything in this issue, but are more of a braindump to help with the implementation)
The starting point is the CreateCampaign
resolver here.
This ticket is about the case where a CampaignPlanID
is given in the arguments. If none is given, the existing code is executed.
If a CampaignPlan is given, we need to:
- load the
CampaignPlan
- check that it's finished executing its
CampaignJob
- load all
CampaignJobs
- create commits from
CampaignJobs
Diff to commit
The Diff
, RepoID
, Rev
fields on CampaignJob
should be enough create a commit by talking to gitserver
. Maybe we can use CreateCommitFromPatch
on the gitserver.Client
for this. Maybe it needs to be extended.
Commits should probably all be created under sourcegraph/*
branches or any other naming scheme that's explicit.
After the commit is created, we need functionality in gitserver
to push the newly-created branch.
We also need to make sure that the newly-created branch/commit is not cleaned up by gitserver'
s GC processes before we push it.
Creating Pull Requests
Once the commit/branch have been pushed, we need to use a CreatePullRequest
method on the code host clients to create a pull request from branch/commit.
At the time of writing, these have not been implemented yet.
Pull requests to Changesets
Each created pull request needs to be turned into a Changeset
and added to the Campaign
.
Retrying
Keep in mind that Creating Pull Requests
and PUll requests to Changesets
might fail and that the whole process of CampaignJobs -> Pull Requests & Changesets
need to be idempotently retryable. This issue here does not cover the retry-functionality, but it is something to keep in mind.
Clean up?
After the CampaignJobs
have been successfully turned into Changesets
, we probably want to "freeze" (or even clean up?) the CampaignJobs
.