diff --git a/lib/modules/platform/github/index.spec.ts b/lib/modules/platform/github/index.spec.ts index d9a211a825ddc7b..c3dd9888bc87d19 100644 --- a/lib/modules/platform/github/index.spec.ts +++ b/lib/modules/platform/github/index.spec.ts @@ -2181,6 +2181,55 @@ describe('modules/platform/github/index', () => { expect(pr).toMatchObject({ number: 123 }); }); + it('should allow maintainer edits if enabled via options', async () => { + const scope = httpMock.scope(githubApiHost); + initRepoMock(scope, 'some/repo'); + scope + .post( + '/repos/some/repo/pulls', + // Ensure the `maintainer_can_modify` option is set in the REST API request. + (body) => body.maintainer_can_modify === true + ) + .reply(200, { + number: 123, + head: { repo: { full_name: 'some/repo' }, ref: 'some-branch' }, + }); + await github.initRepo({ repository: 'some/repo' }); + const pr = await github.createPr({ + sourceBranch: 'some-branch', + targetBranch: 'main', + prTitle: 'PR title', + prBody: 'PR can be edited by maintainers.', + labels: null, + allowMaintainerEdits: true, + }); + expect(pr).toMatchObject({ number: 123 }); + }); + + it('should not allow maintainer edits if not explicitly set', async () => { + const scope = httpMock.scope(githubApiHost); + initRepoMock(scope, 'some/repo'); + scope + .post( + '/repos/some/repo/pulls', + // Ensure the `maintainer_can_modify` option is unset in the REST API request. + (body) => body.maintainer_can_modify === undefined + ) + .reply(200, { + number: 123, + head: { repo: { full_name: 'some/repo' }, ref: 'some-branch' }, + }); + await github.initRepo({ repository: 'some/repo' }); + const pr = await github.createPr({ + sourceBranch: 'some-branch', + targetBranch: 'main', + prTitle: 'PR title', + prBody: 'PR *cannot* be edited by maintainers.', + labels: null, + }); + expect(pr).toMatchObject({ number: 123 }); + }); + describe('automerge', () => { const createdPrResp = { number: 123, diff --git a/lib/modules/platform/github/index.ts b/lib/modules/platform/github/index.ts index 1ce38129842978b..6a97d2de690360c 100644 --- a/lib/modules/platform/github/index.ts +++ b/lib/modules/platform/github/index.ts @@ -1479,6 +1479,7 @@ export async function createPr({ prBody: rawBody, labels, draftPR = false, + allowMaintainerEdits, platformOptions, }: CreatePRConfig): Promise { const body = sanitize(rawBody); @@ -1494,12 +1495,12 @@ export async function createPr({ base, body, draft: draftPR, + maintainer_can_modify: allowMaintainerEdits, }, }; // istanbul ignore if if (config.forkToken) { options.token = config.forkToken; - options.body.maintainer_can_modify = true; } logger.debug({ title, head, base, draft: draftPR }, 'Creating PR'); const ghPr = (