feat(git): add pull-request generation from CMS UI - #511
Open
TotomInc wants to merge 2 commits into
Open
Conversation
Contributor
|
@TotomInc is attempting to deploy a commit to the Nuxt Team on Vercel. A member of the Team first needs to authorize it. |
commit: |
Contributor
Author
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.


Closes nuxt-content/nuxt-studio#366.
Problem
Content teams often work on a staging branch (preview environment) and promote changes to production via a pull request (GitHub) or merge request (GitLab). Before this change, Nuxt Studio could commit to a configured branch but left the PR/MR step entirely manual.
Solution
Add opt-in
repository.pullRequestoptions. WhenpullRequest.baseis set:repository.branch(unchanged behavior).pullRequest.base.When
pullRequest.baseis omitted, behavior is unchanged: direct commit only.Optionally,
pullRequest.namesets a custom title for newly created PR/MR. When omitted, the commit message is used.Configuration
Runtime override (Nuxt public runtime config):
NUXT_PUBLIC_STUDIO_REPOSITORY_PULL_REQUEST_BASE=main NUXT_PUBLIC_STUDIO_REPOSITORY_PULL_REQUEST_NAME="Content updates from Studio"repository.branchrepository.pullRequest.baserepository.pullRequest.nameUser-facing docs:
docs/content/2.setup.md,docs/content/3.git-providers.md,docs/content/9.advanced.md.Publish flow
sequenceDiagram participant Review as HeaderReview participant Ctx as useContext.PublishBranch participant Provider as GitProviderAPI participant Remote as GitHub / GitLab API participant Success as /success Review->>Ctx: commitMessage Ctx->>Provider: commitFiles(rawFiles, message) Provider->>Remote: commit to repository.branch Remote-->>Provider: CommitResult alt pullRequest.base set and differs from branch Ctx->>Provider: ensureReviewRequest({ head, base, title, commitUrl }) Provider->>Remote: GET open PR/MR alt none exists Provider->>Remote: POST PR/MR end Remote-->>Provider: ReviewRequestResult end Ctx->>Ctx: clear drafts (always after successful commit) Ctx-->>Review: PublishBranchResult Review->>Success: query params (changeCount, commitUrl, review request metadata)Behavior matrix
pullRequest.basebase≠branchstate: 'existing')base===branch/errorensureReviewRequestreturnsnullPartial failure is intentional: once content is on the staging branch, drafts are cleared even if PR/MR creation fails. The user can open the commit from the success screen and create the review request manually if needed.
Architecture notes
commitFiles:ofetchfrom the Studio app using the user's OAuth token or PAT. No new server routes.PublishBranchinuseContext.tschains commit → optional review request → draft cleanup.GitProviderAPI.ensureReviewRequest()with provider-neutralReviewRequestResult(kind,state,url,head,base).PublishBranchResultcarriescommit, optionalreviewRequest, and optionalreviewRequestErrorback to the UI.pullRequest.namewhen configured, otherwise the commit message. Only applied when creating a new PR/MR; existing open requests are reused as-is.GitHub (
ensureReviewRequest)GET /repos/{owner}/{repo}/pulls?state=open&head={owner}:{branch}&base={base}state: 'existing'POST /pullswithpullRequest.nameor commit message as titleGitLab (
ensureReviewRequest)GET /projects/{id}/merge_requests?state=opened&source_branch={head}&target_branch={base}state: 'existing'POST /merge_requestswithpullRequest.nameor commit message as titleKey files
src/module/src/module.ts—repository.pullRequest.base,repository.pullRequest.namesrc/app/src/types/git.ts,src/app/src/types/context.tssrc/app/src/composables/useContext.tssrc/app/src/utils/providers/github.tssrc/app/src/utils/providers/gitlab.tssrc/app/src/utils/providers/null.tssrc/app/src/components/header/HeaderReview.vuesrc/app/src/pages/success.vuesrc/app/src/locales/en.json,fr.json(studio.publishSuccess.reviewRequest.*)Tests
src/app/test/integration/publish.test.tspullRequest.name, partial failure (throw), null result,base === branchskip, existing request reusesrc/app/test/unit/utils/providers/github.test.tssrc/app/test/unit/utils/providers/gitlab.test.tssrc/app/test/mocks/git.tsensureReviewRequestmockRun:
Manual QA checklist
pullRequest.base— no PR/MR step, standard successbranch: staging,pullRequest.base: mainon GitHub — PR link on successpullRequest.nameset — newly created PR/MR uses the configured titlepullRequest.baseequal tobranch— commit only, no PR attemptOut of scope (by design)
headrefs (same-repo staging → production only)