draft always-true

This commit is contained in:
Peter Evans 2024-08-18 21:54:43 +00:00
parent 10454726b6
commit c64379e4f4
5 changed files with 73 additions and 6 deletions

View file

@ -32,7 +32,10 @@ export interface Inputs {
reviewers: string[]
teamReviewers: string[]
milestone: number
draft: boolean
draft: {
value: boolean
always: boolean
}
maintainerCanModify: boolean
}

View file

@ -20,6 +20,8 @@ interface Repository {
interface Pull {
number: number
html_url: string
node_id: string
draft?: boolean
created: boolean
}
@ -78,7 +80,7 @@ export class GitHubHelper {
head_repo: headRepository,
base: inputs.base,
body: inputs.body,
draft: inputs.draft,
draft: inputs.draft.value,
maintainer_can_modify: inputs.maintainerCanModify
})
core.info(
@ -87,6 +89,8 @@ export class GitHubHelper {
return {
number: pull.number,
html_url: pull.html_url,
node_id: pull.node_id,
draft: pull.draft,
created: true
}
} catch (e) {
@ -127,6 +131,8 @@ export class GitHubHelper {
return {
number: pull.number,
html_url: pull.html_url,
node_id: pull.node_id,
draft: pull.draft,
created: false
}
}
@ -209,9 +215,28 @@ 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,

View file

@ -3,6 +3,14 @@ import {Inputs, createPullRequest} from './create-pull-request'
import {inspect} from 'util'
import * as utils from './utils'
function getDraftInput(): {value: boolean; always: boolean} {
if (core.getInput('draft') === 'always-true') {
return {value: true, always: true}
} else {
return {value: core.getBooleanInput('draft'), always: false}
}
}
async function run(): Promise<void> {
try {
const inputs: Inputs = {
@ -28,7 +36,7 @@ async function run(): Promise<void> {
reviewers: utils.getInputAsArray('reviewers'),
teamReviewers: utils.getInputAsArray('team-reviewers'),
milestone: Number(core.getInput('milestone')),
draft: core.getBooleanInput('draft'),
draft: getDraftInput(),
maintainerCanModify: core.getBooleanInput('maintainer-can-modify')
}
core.debug(`Inputs: ${inspect(inputs)}`)