sourcegraph / sourcegraph-public-snapshot

Code AI platform with Code Search & Cody
https://sourcegraph.com
Other
10.1k stars 1.28k forks source link

a8n: Implement `createCampaign` for Campaigns with a CampaignPlan #6403

Closed mrnugget closed 4 years ago

mrnugget commented 4 years ago

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:


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:

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.

tsenart commented 4 years ago

check that it's finished executing its CampaignJobs

If this is not true at the time the client calls createCampaign with a CampaignPlan id, we can't proceed in creating branches in git-server and everything that follows, which makes me think this needs to be processed, again, as some sort of background job pulled from a durable queue.

I'm thinking that repo-updater can periodically load all pending campaign jobs that have an associated campaign (via a campaign plan) and process them then.

tsenart commented 4 years ago

Well, actually, the documentation in the schema says the mutation should error if the plan hasn't completed yet, so I guess that makes things simpler.

https://github.com/sourcegraph/sourcegraph/blob/b2a844dc7762146c9cf0ccdac2172bbfdbbb9259/cmd/frontend/graphqlbackend/schema.graphql#L436