add maintainer-can-modify input
This commit is contained in:
parent
e7f5ea9fd9
commit
740d9850a7
6 changed files with 33 additions and 8 deletions
|
@ -75,6 +75,7 @@ All inputs are **optional**. If not set, sensible defaults will be used.
|
|||
| `team-reviewers` | A comma or newline-separated list of GitHub teams to request a review from. Note that a `repo` scoped [PAT](https://docs.github.com/en/github/authenticating-to-github/creating-a-personal-access-token), or equivalent [GitHub App permissions](docs/concepts-guidelines.md#authenticating-with-github-app-generated-tokens), are required. | |
|
||||
| `milestone` | The number of the milestone to associate this pull request with. | |
|
||||
| `draft` | Create a [draft pull request](https://docs.github.com/en/github/collaborating-with-issues-and-pull-requests/about-pull-requests#draft-pull-requests). It is not possible to change draft status after creation except through the web interface. | `false` |
|
||||
| `maintainer-can-modify` | Indicates whether [maintainers can modify](https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/working-with-forks/allowing-changes-to-a-pull-request-branch-created-from-a-fork) the pull request. | `true` |
|
||||
|
||||
#### commit-message
|
||||
|
||||
|
|
|
@ -77,6 +77,9 @@ inputs:
|
|||
draft:
|
||||
description: 'Create a draft pull request. It is not possible to change draft status after creation except through the web interface'
|
||||
default: false
|
||||
maintainer-can-modify:
|
||||
description: 'Indicates whether maintainers can modify the pull request.'
|
||||
default: true
|
||||
outputs:
|
||||
pull-request-number:
|
||||
description: 'The pull request number'
|
||||
|
|
15
dist/index.js
vendored
15
dist/index.js
vendored
|
@ -1169,7 +1169,9 @@ const core = __importStar(__nccwpck_require__(2186));
|
|||
const octokit_client_1 = __nccwpck_require__(5040);
|
||||
const p_limit_1 = __importDefault(__nccwpck_require__(3783));
|
||||
const utils = __importStar(__nccwpck_require__(918));
|
||||
const ERROR_PR_ALREADY_EXISTS = 'A pull request already exists for';
|
||||
const ERROR_PR_REVIEW_TOKEN_SCOPE = 'Validation Failed: "Could not resolve to a node with the global id of';
|
||||
const ERROR_PR_FORK_COLLAB = `Fork collab can't be granted by someone without permission`;
|
||||
const blobCreationLimit = (0, p_limit_1.default)(8);
|
||||
class GitHubHelper {
|
||||
constructor(githubServerHostname, token) {
|
||||
|
@ -1200,7 +1202,7 @@ class GitHubHelper {
|
|||
// Try to create the pull request
|
||||
try {
|
||||
core.info(`Attempting creation of pull request`);
|
||||
const { data: pull } = yield this.octokit.rest.pulls.create(Object.assign(Object.assign({}, this.parseRepository(baseRepository)), { title: inputs.title, head: headBranch, head_repo: headRepository, base: inputs.base, body: inputs.body, draft: inputs.draft }));
|
||||
const { data: pull } = yield this.octokit.rest.pulls.create(Object.assign(Object.assign({}, this.parseRepository(baseRepository)), { title: inputs.title, head: headBranch, head_repo: headRepository, base: inputs.base, body: inputs.body, draft: inputs.draft, maintainer_can_modify: inputs.maintainerCanModify }));
|
||||
core.info(`Created pull request #${pull.number} (${headBranch} => ${inputs.base})`);
|
||||
return {
|
||||
number: pull.number,
|
||||
|
@ -1209,9 +1211,15 @@ class GitHubHelper {
|
|||
};
|
||||
}
|
||||
catch (e) {
|
||||
if (utils.getErrorMessage(e).includes(`A pull request already exists for`)) {
|
||||
const errorMessage = utils.getErrorMessage(e);
|
||||
if (errorMessage.includes(ERROR_PR_ALREADY_EXISTS)) {
|
||||
core.info(`A pull request already exists for ${headBranch}`);
|
||||
}
|
||||
else if (errorMessage.includes(ERROR_PR_FORK_COLLAB)) {
|
||||
core.warning('An attempt was made to create a pull request using a token that does not have write access to the head branch.');
|
||||
core.warning(`For this case, set input 'maintainer-can-modify' to 'false' to allow pull request creation.`);
|
||||
throw e;
|
||||
}
|
||||
else {
|
||||
throw e;
|
||||
}
|
||||
|
@ -1419,7 +1427,8 @@ function run() {
|
|||
reviewers: utils.getInputAsArray('reviewers'),
|
||||
teamReviewers: utils.getInputAsArray('team-reviewers'),
|
||||
milestone: Number(core.getInput('milestone')),
|
||||
draft: core.getBooleanInput('draft')
|
||||
draft: core.getBooleanInput('draft'),
|
||||
maintainerCanModify: core.getBooleanInput('maintainer-can-modify')
|
||||
};
|
||||
core.debug(`Inputs: ${(0, util_1.inspect)(inputs)}`);
|
||||
if (!inputs.token) {
|
||||
|
|
|
@ -33,6 +33,7 @@ export interface Inputs {
|
|||
teamReviewers: string[]
|
||||
milestone: number
|
||||
draft: boolean
|
||||
maintainerCanModify: boolean
|
||||
}
|
||||
|
||||
export async function createPullRequest(inputs: Inputs): Promise<void> {
|
||||
|
|
|
@ -5,8 +5,10 @@ import {Octokit, OctokitOptions, throttleOptions} from './octokit-client'
|
|||
import pLimit from 'p-limit'
|
||||
import * as utils from './utils'
|
||||
|
||||
const ERROR_PR_ALREADY_EXISTS = 'A pull request already exists for'
|
||||
const ERROR_PR_REVIEW_TOKEN_SCOPE =
|
||||
'Validation Failed: "Could not resolve to a node with the global id of'
|
||||
const ERROR_PR_FORK_COLLAB = `Fork collab can't be granted by someone without permission`
|
||||
|
||||
const blobCreationLimit = pLimit(8)
|
||||
|
||||
|
@ -76,7 +78,8 @@ export class GitHubHelper {
|
|||
head_repo: headRepository,
|
||||
base: inputs.base,
|
||||
body: inputs.body,
|
||||
draft: inputs.draft
|
||||
draft: inputs.draft,
|
||||
maintainer_can_modify: inputs.maintainerCanModify
|
||||
})
|
||||
core.info(
|
||||
`Created pull request #${pull.number} (${headBranch} => ${inputs.base})`
|
||||
|
@ -87,10 +90,17 @@ export class GitHubHelper {
|
|||
created: true
|
||||
}
|
||||
} catch (e) {
|
||||
if (
|
||||
utils.getErrorMessage(e).includes(`A pull request already exists for`)
|
||||
) {
|
||||
const errorMessage = utils.getErrorMessage(e)
|
||||
if (errorMessage.includes(ERROR_PR_ALREADY_EXISTS)) {
|
||||
core.info(`A pull request already exists for ${headBranch}`)
|
||||
} else if (errorMessage.includes(ERROR_PR_FORK_COLLAB)) {
|
||||
core.warning(
|
||||
'An attempt was made to create a pull request using a token that does not have write access to the head branch.'
|
||||
)
|
||||
core.warning(
|
||||
`For this case, set input 'maintainer-can-modify' to 'false' to allow pull request creation.`
|
||||
)
|
||||
throw e
|
||||
} else {
|
||||
throw e
|
||||
}
|
||||
|
|
|
@ -28,7 +28,8 @@ async function run(): Promise<void> {
|
|||
reviewers: utils.getInputAsArray('reviewers'),
|
||||
teamReviewers: utils.getInputAsArray('team-reviewers'),
|
||||
milestone: Number(core.getInput('milestone')),
|
||||
draft: core.getBooleanInput('draft')
|
||||
draft: core.getBooleanInput('draft'),
|
||||
maintainerCanModify: core.getBooleanInput('maintainer-can-modify')
|
||||
}
|
||||
core.debug(`Inputs: ${inspect(inputs)}`)
|
||||
|
||||
|
|
Loading…
Reference in a new issue