{"record":{"id":"87cd82197b6713e5","repo":"theonedev/onedev","slug":"pull-request-has-merge-conflicts","errorCode":null,"errorMessage":"Pull request has merge conflicts","messagePattern":"Pull request has merge conflicts","errorType":"http","errorClass":"ValidationException","httpStatus":400,"severity":"error","filePath":"server-core/src/main/java/io/onedev/server/rest/resource/JobRunResource.java","lineNumber":102,"sourceCode":"\t\t\tif (!gitService.isMergedInto(project, null, commitId, refCommit)) \n\t\t\t\tthrow new ValidationException(\"Specified commit is not reachable from specified ref\");\n\t\t\t\n\t\t\trefName = jobRunOnCommit.getRefName();\n\t\t\trequest = null;\n\t\t} else {\n\t\t\tJobRunOnPullRequest jobRunOnPullRequest = (JobRunOnPullRequest) jobRun;\n\t\t\trequest = pullRequestService.load(jobRunOnPullRequest.getPullRequestId());\n\t\t\trefName = request.getMergeRef();\n\t\t\tproject = request.getProject();\n\t\t\t\n\t\t\tif (!SecurityUtils.canRunJob(subject, request.getProject(), jobRun.getJobName()))\t\t\n\t\t\t\tthrow new UnauthorizedException();\n\n\t\t\tMergePreview preview = request.checkMergePreview();\n\t\t\tif (preview == null)\n\t\t\t\tthrow new ValidationException(\"Pull request merge preview not calculated yet\");\n\t\t\tif (preview.getMergeCommitHash() == null)\n\t\t\t\tthrow new ValidationException(\"Pull request has merge conflicts\");\n\t\t\t\n\t\t\tcommitId = ObjectId.fromString(preview.getMergeCommitHash());\n\t\t}\n\t\t\n\t\tBuild build = jobService.submit(user, project, commitId, jobRun.getJobName(), \n\t\t\t\tjobRun.getParams(), refName, request, null, jobRun.getReason());\n\t\tif (build.isFinished())\n\t\t\tjobService.resubmit(user, build, jobRun.getReason());\n\t\treturn build.getId();\n    }\n\n\t@Api(order=200)\n    @Path(\"/rebuild\")\n    @POST\n    public Response rebuild(@NotNull @Valid JobRerun jobRerun) {\n    \tBuild  build = buildService.load(jobRerun.buildId);\n\t\tvar subject = SecurityUtils.getSubject();\n\t\tvar user = SecurityUtils.getUser(subject);","sourceCodeStart":84,"sourceCodeEnd":120,"githubUrl":"https://github.com/theonedev/onedev/blob/d44925c47c37992c828ea673a5f9620539bc3ff2/server-core/src/main/java/io/onedev/server/rest/resource/JobRunResource.java#L84-L120","documentation":"For job runs on a pull request, OneDev builds the computed merge commit. If the merge preview exists but its mergeCommitHash is null, the PR has merge conflicts and no merge commit can be built, so runBuild throws a ValidationException (HTTP 400).","triggerScenarios":"Submitting a job run on a pull request whose source and target branches conflict (merge preview calculated but conflict detected).","commonSituations":"Target branch advanced with overlapping changes; long-lived PRs that drifted from main; automation triggering builds without checking PR mergeable status.","solutions":["Resolve merge conflicts in the PR branch (rebase/merge target into source and push)","Check the PR's merge/conflict status in the UI or API before submitting the job run","Have automation skip or flag conflicted PRs instead of requesting job runs"],"exampleFix":"// before\nrunJobOnPullRequest(prId); // 400: Pull request has merge conflicts\n// after\nif (getPullRequest(prId).mergePreview.mergeCommitHash != null)\n  runJobOnPullRequest(prId);","handlingStrategy":"validation","validationCode":"const preview = getPullRequest(id).mergePreview;\nif (preview && preview.mergeCommitHash == null) skip('PR has merge conflicts');","typeGuard":null,"tryCatchPattern":"try { runBuild(pr); } catch (WebApplicationException e) { if (msg contains 'merge conflicts') notifyAuthorsToResolve(); else throw e; }","preventionTips":["Check PR mergeability before triggering builds","Keep PR branches rebased on target","Route conflicted PRs to a manual triage path in automation"],"tags":["rest","pull-request","merge-conflict"],"backgroundTag":"merge-conflict","analyzedSha":"d44925c47c37992c828ea673a5f9620539bc3ff2","analyzedAt":"2026-09-06T07:18:27.995Z","contentChangedAt":"2026-09-06T07:18:27.995Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}