# shellcheck shell=dash disable=SC2034,SC2154

# https://gitea.com/api/swagger#/repository/repoCreatePullRequest
___x_cmd_fjo_repo_pr_create() {
    param:scope     ___x_cmd_fjo
    param:dsl       '
options:
    --repo|-r       "<owner_path>/<repo_path>"                                          <>:RepoName
    --title         "pr title"                                                          <>
    --head          "source branch. Format: [username:]<branch>"                        <>:name
    --base          "target branch. Format: [username:]<branch>"                        <>:name
    --body          "pull request content"                                              <>=""
    --due_date      "due date"                                                          <>=""
    --assignee      "User responsible for this pull request"                            <>=""
    --assignees     "User responsible for this pull request"                            <>:Array=""
    --milestone     "ID of the milestone"                                               <>:Number=""
    --labels        "Label IDs"                                                         <>:Array=""

    --json|-j       "output json data"
'
    param:run
    local tmp_assignees
    tmp_assignees="$(x jo "[$assignees]")"
    local tmp
    tmp="$(x jo "[$labels]")"
    local gen_fjo_json
    gen_fjo_json="$(param:option2json -repo -assignees -labels ${assignees+"assignees=tmp_assignees"} ${labels+"labels=tmp"})"

    ___x_cmd_fjo_param_init_owner_repo
    ___x_cmd_fjo_curl post "/repos/$owner_repo/pulls" "gen_fjo_json" | ___x_cmd_fjo_pr____ui_handler Creating
}
