* Main handler factory for create_pull_request * Returns a message handler function that processes individual create_pull_request messages * @type {HandlerFactoryFunction}
(config = {})
| 610 | * @type {HandlerFactoryFunction} |
| 611 | */ |
| 612 | async function main(config = {}) { |
| 613 | // Extract configuration |
| 614 | const rawBranchPrefix = config.branch_prefix || ""; |
| 615 | const normalizedBranchPrefix = normalizeBranchName(rawBranchPrefix); |
| 616 | if (rawBranchPrefix && normalizedBranchPrefix !== rawBranchPrefix) { |
| 617 | const branchPrefixWarning = [ |
| 618 | `Branch prefix "${rawBranchPrefix}" contains characters that are invalid in a git ref.`, |
| 619 | `Using normalized prefix: "${normalizedBranchPrefix}".`, |
| 620 | "Update branch-prefix in the workflow configuration to avoid this warning.", |
| 621 | ].join(" "); |
| 622 | core.warning(branchPrefixWarning); |
| 623 | } |
| 624 | const branchPrefix = normalizedBranchPrefix; |
| 625 | const titlePrefix = config.title_prefix || ""; |
| 626 | const envLabels = parseStringListConfig(config.labels); |
| 627 | const configFallbackLabels = parseStringListConfig(config.fallback_labels); |
| 628 | const configReviewers = parseStringListConfig(config.reviewers); |
| 629 | const configTeamReviewers = parseStringListConfig(config.team_reviewers); |
| 630 | const rawAssignees = parseStringListConfig(config.assignees); |
| 631 | const hasCopilotInAssignees = rawAssignees.some(a => a.toLowerCase() === "copilot"); |
| 632 | const configAssignees = sanitizeFallbackAssignees(rawAssignees); |
| 633 | const draftDefault = parseBoolTemplatable(config.draft, true); |
| 634 | const ifNoChanges = config.if_no_changes || "warn"; |
| 635 | const allowEmpty = parseBoolTemplatable(config.allow_empty, false); |
| 636 | const autoMerge = parseBoolTemplatable(config.auto_merge, false); |
| 637 | const preserveBranchName = config.preserve_branch_name === true; |
| 638 | const recreateRef = config.recreate_ref === true; |
| 639 | const signedCommits = config.signed_commits !== false; |
| 640 | const expiresHours = config.expires ? parseInt(String(config.expires), 10) : 0; |
| 641 | const maxCount = config.max || 1; // PRs are typically limited to 1 |
| 642 | const maxSizeKb = parsePositiveInteger(config.max_patch_size) ?? 4096; |
| 643 | const maxFiles = parsePositiveInteger(config.max_patch_files) ?? MAX_FILES; |
| 644 | const { defaultTargetRepo, allowedRepos } = resolveTargetRepoConfig(config); |
| 645 | const allowedBaseBranches = parseAllowedBaseBranches(config.allowed_base_branches); |
| 646 | const githubClient = await createAuthenticatedGitHubClient(config); |
| 647 | let allowedMentionAliases = []; |
| 648 | if (Array.isArray(config.allowedMentionAliases)) { |
| 649 | allowedMentionAliases = config.allowedMentionAliases; |
| 650 | } else if (config.mentions != null) { |
| 651 | allowedMentionAliases = await resolveAllowedMentionsFromPayload(context, githubClient, core, config.mentions); |
| 652 | } |
| 653 | |
| 654 | // Check if copilot assignment is enabled for fallback issues |
| 655 | const assignCopilot = process.env.GH_AW_ASSIGN_COPILOT === "true"; |
| 656 | |
| 657 | // Lazily-initialised client for copilot assignment (only allocated when needed). |
| 658 | // Uses GH_AW_ASSIGN_TO_AGENT_TOKEN (agent token preference chain) when available, |
| 659 | // otherwise falls back to the step-level github object. |
| 660 | /** @type {Object|null} */ |
| 661 | let copilotClient = null; |
| 662 | |
| 663 | /** |
| 664 | * Assigns copilot to a fallback issue using agent helpers, if copilot was requested |
| 665 | * in the assignees config and the GH_AW_ASSIGN_COPILOT env var is set. |
| 666 | * A no-op when either condition is false. The copilotClient is initialised lazily |
| 667 | * on the first call and reused for subsequent issues. |
| 668 | * @param {string} owner - Repository owner |
| 669 | * @param {string} repo - Repository name |
nothing calls this directly
no test coverage detected