diff --git a/lib/batches/changeset_spec.go b/lib/batches/changeset_spec.go index c50e22a4644..229ba191e19 100644 --- a/lib/batches/changeset_spec.go +++ b/lib/batches/changeset_spec.go @@ -103,6 +103,7 @@ func (c *ChangesetSpec) MarshalJSON() ([]byte, error) { Body string `json:"body,omitempty"` Commits []GitCommitDescription `json:"commits,omitempty"` Published *PublishedValue `json:"published,omitempty"` + Fork *bool `json:"fork,omitempty"` }{ BaseRepository: c.BaseRepository, ExternalID: c.ExternalID, @@ -113,6 +114,7 @@ func (c *ChangesetSpec) MarshalJSON() ([]byte, error) { Title: c.Title, Body: c.Body, Commits: c.Commits, + Fork: c.Fork, } if !c.Published.Nil() { v.Published = &c.Published diff --git a/lib/batches/changeset_spec_test.go b/lib/batches/changeset_spec_test.go index 5e513525126..a617cfb95b5 100644 --- a/lib/batches/changeset_spec_test.go +++ b/lib/batches/changeset_spec_test.go @@ -111,6 +111,26 @@ func TestParseChangesetSpec(t *testing.T) { }`, err: "2 errors occurred:\n\t* Must validate one and only one schema (oneOf)\n\t* commits: Array must have at most 1 items", }, + { + name: "with fork", + rawSpec: `{ + "baseRepository": "graphql-id", + "baseRef": "refs/heads/master", + "baseRev": "d34db33f", + "headRef": "refs/heads/my-branch", + "headRepository": "graphql-id", + "title": "my title", + "body": "my body", + "published": false, + "commits": [{ + "message": "commit message", + "diff": "the diff", + "authorName": "Mary McButtons", + "authorEmail": "mary@example.com" + }], + "fork": true + }`, + }, } for _, tc := range tests { diff --git a/lib/batches/schema/changeset_spec_stringdata.go b/lib/batches/schema/changeset_spec_stringdata.go index 5bb61dc3337..9ec47ef5326 100644 --- a/lib/batches/schema/changeset_spec_stringdata.go +++ b/lib/batches/schema/changeset_spec_stringdata.go @@ -60,6 +60,10 @@ const ChangesetSpecJSON = `{ "description": "The GraphQL ID of the repository that contains the branch with this changeset's changes. Fork repositories and cross-repository changesets are not yet supported. Therefore, headRepository must be equal to baseRepository.", "examples": ["UmVwb3NpdG9yeTo5Cg=="] }, + "fork": { + "type": "boolean", + "description": "Whether to publish the changeset to a fork of the target repository. If omitted, the changeset will be published to a branch directly on the target repository, unless the global ` + "`" + `batches.enforceFork` + "`" + ` setting is enabled. If set, this property will override any global setting." + }, "headRef": { "type": "string", "description": "The full name of the Git ref that holds the changes proposed by this changeset. This ref will be created or updated with the commits.", diff --git a/schema/changeset_spec.schema.json b/schema/changeset_spec.schema.json index eee14ee2725..dc3516d2f0f 100644 --- a/schema/changeset_spec.schema.json +++ b/schema/changeset_spec.schema.json @@ -55,6 +55,10 @@ "description": "The GraphQL ID of the repository that contains the branch with this changeset's changes. Fork repositories and cross-repository changesets are not yet supported. Therefore, headRepository must be equal to baseRepository.", "examples": ["UmVwb3NpdG9yeTo5Cg=="] }, + "fork": { + "type": "boolean", + "description": "Whether to publish the changeset to a fork of the target repository. If omitted, the changeset will be published to a branch directly on the target repository, unless the global `batches.enforceFork` setting is enabled. If set, this property will override any global setting." + }, "headRef": { "type": "string", "description": "The full name of the Git ref that holds the changes proposed by this changeset. This ref will be created or updated with the commits.", diff --git a/schema/schema.go b/schema/schema.go index 5d9c35502e4..2ef1c536cbf 100644 --- a/schema/schema.go +++ b/schema/schema.go @@ -478,6 +478,8 @@ type BranchChangesetSpec struct { Body string `json:"body"` // Commits description: The Git commits with the proposed changes. These commits are pushed to the head ref. Commits []*GitCommitDescription `json:"commits"` + // Fork description: Whether to publish the changeset to a fork of the target repository. If omitted, the changeset will be published to a branch directly on the target repository, unless the global `batches.enforceFork` setting is enabled. If set, this property will override any global setting. + Fork bool `json:"fork,omitempty"` // HeadRef description: The full name of the Git ref that holds the changes proposed by this changeset. This ref will be created or updated with the commits. HeadRef string `json:"headRef"` // HeadRepository description: The GraphQL ID of the repository that contains the branch with this changeset's changes. Fork repositories and cross-repository changesets are not yet supported. Therefore, headRepository must be equal to baseRepository.