跳转到内容
EN

Push a unit's branch

Code Mode: praxis.devops.units.push

HTTP: POST /devops/v1/units/{id}:push

Publish the unit’s local commits to the remote for the change: the machine itself holds no git credential and cannot reach the remote, so this verb is the way work done on a unit lands. ref says what to push — branch for the change’s own branch, wip for this unit’s own refs/praxis/wip/<change>, or a full ref name; anything else (the default branch, another change’s branch, a tag, another unit’s wip ref) is refused with 400 PUSH_REF_FORBIDDEN and nothing is pushed. expectedHead is the commit you believe the remote branch is at now; DevOps checks it before signing anything, and a remote that has moved since answers 409 HEAD_MOVED with nothing pushed, naming the head it is at now in the message and in details.remoteHead. Read the starting value from the unit’s git.remoteHead (fetch first when someone else may have pushed). For branch the call also takes a lease on that head, so the push cannot silently overwrite work that landed in between; wip is this change’s own ref and is force-pushed. On success the answer is pushedSha, the commit that landed. Commit inside the machine first, through the sandbox instance API — this verb pushes commits, it does not create them. The unit must be available with a machine and a checkout, or the call answers 409 UNIT_INVALID_STATE; a push that git refuses inside the machine answers with the cause in the error message and in details.detail (the last 4000 characters of git’s output, credentials redacted) and details.exitCode (git’s exit code): 409 PUSH_REJECTED_BY_HOOK when a pre-push hook such as lefthook rejected it, so read the hook output, fix the content and push again, 409 PUSH_REJECTED_NON_FAST_FORWARD when the remote moved ahead, so fetch and reconcile, 409 HEAD_MOVED when the lease on expectedHead no longer holds, and 500 PUSH_FAILED for anything else. Do not retry the same push unchanged.

签名

praxis.devops.units.push(args:{path:{/** e.g. "wsu_01JQ8Z3M9K4V7B2N6C5X0YTRHW" */ id:string};body:{/** What to push: branch for the change's own branch, wip for this unit's own refs/praxis/wip/<change>, or a full ref name such as refs/heads/feat/run-page-v2. e.g. "branch" */ ref:string;/** The full commit the caller believes the change's branch is at on the remote now, read from the unit's git facts or a prior push answer; a remote that differs an e.g. "4f2a9c1d8e7b6a5c4d3e2f1a0b9c8d7e6f5a4b3c" */ expectedHead:string}}):Promise<{/** The full commit that was pushed, which the caller compares with the head it expected. e.g. "4f2a9c1d8e7b6a5c4d3e2f1a0b9c8d7e6f5a4b3c" */ pushedSha:string}>;

参数

名称位置类型必填说明
idpathstring是The unit identifier returned by the unit create answer or a unit list, such as wsu_…; not the id of the change it was opened for.

请求体

必填内容类型说明
是application/json

响应

状态码内容类型说明
200application/jsonThe commit that landed, as pushedSha; compare it with the head you sent.
400application/jsonPUSH_REF_FORBIDDEN means this unit is not allowed to push that ref: only the change’s own branch and this unit’s own refs/praxis/wip/<change> may be pushed. The default branch, another change’s branch, a tag and another unit’s wip ref are all refused, and nothing was pushed. Send ref branch or wip, or the exact branch ref of this unit.
401application/jsonThe API key is missing or invalid; send a valid Praxis API key in the Authorization header before retrying.
403application/jsonThe credential carries no organization, or that organization cannot reach this project; use a key belonging to the project’s organization. No cross-organization read is possible.
404application/jsonUNIT_NOT_FOUND means no unit with that id is visible to this organization — a unit belonging to another organization answers the same way, so its existence is not revealed; list the project’s units and use an id from that answer.
409application/jsonHEAD_MOVED means the change’s branch on the remote is no longer the expectedHead that was sent — someone pushed to it since — so nothing was pushed. The message says where the remote is (“remote is at <sha7> (<full sha>) on <ref>”) and details.remoteHead carries the full sha: send it as expectedHead after reconciling your checkout. PUSH_REJECTED_BY_HOOK means the machine’s git ran a pre-push hook (lefthook, for example) and the hook refused: details.detail holds the hook’s output and details.exitCode git’s exit code; fix what the hook names, commit, and push again. PUSH_REJECTED_NON_FAST_FORWARD means the remote branch has commits your checkout lacks; fetch, reconcile and push again. UNIT_INVALID_STATE means the unit is not available (no machine or no checkout yet, or another transition is in flight), so there is nothing to push; read the unit’s phase and retry once it has settled.
500application/jsonINTERNAL means the service could not complete the request; retry once, and if it repeats report the request id. A read is safe to repeat; a write that failed this way should be re-read before it is sent again.