convert to draft on branch updates when there is a diff with base

This commit is contained in:
Peter Evans 2024-08-18 22:37:10 +00:00
parent c64379e4f4
commit 8f92797560
6 changed files with 44 additions and 41 deletions

View file

@ -249,6 +249,11 @@ export async function createPullRequest(inputs: Inputs): Promise<void> {
outputs.set('pull-request-operation', 'created')
} else if (result.action == 'updated') {
outputs.set('pull-request-operation', 'updated')
// The pull request was updated AND the branch was updated.
// Convert back to draft if 'draft: always-true' is set.
if (inputs.draft.always && pull.draft !== undefined && !pull.draft) {
await ghPull.convertToDraft(pull.node_id)
}
}
core.endGroup()
} else {

View file

@ -215,28 +215,9 @@ export class GitHubHelper {
}
}
// Convert back to draft if 'draft: always-true' is set
if (inputs.draft.always && pull.draft !== undefined && !pull.draft) {
await this.convertToDraft(pull.node_id)
}
return pull
}
private async convertToDraft(id: string): Promise<void> {
core.info(`Converting pull request to draft`)
await this.octokit.graphql({
query: `mutation($pullRequestId: ID!) {
convertPullRequestToDraft(input: {pullRequestId: $pullRequestId}) {
pullRequest {
isDraft
}
}
}`,
pullRequestId: id
})
}
async pushSignedCommits(
branchCommits: Commit[],
baseSha: string,
@ -368,4 +349,18 @@ export class GitHubHelper {
})
}
}
async convertToDraft(id: string): Promise<void> {
core.info(`Converting pull request to draft`)
await this.octokit.graphql({
query: `mutation($pullRequestId: ID!) {
convertPullRequestToDraft(input: {pullRequestId: $pullRequestId}) {
pullRequest {
isDraft
}
}
}`,
pullRequestId: id
})
}
}