MCPcopy
hub / github.com/harness/harness / Create

Method Create

app/api/controller/pullreq/pr_create.go:77–315  ·  view source on GitHub ↗

Create creates a new pull request.

(
	ctx context.Context,
	session *auth.Session,
	repoRef string,
	in *CreateInput,
)

Source from the content-addressed store, hash-verified

75
76// Create creates a new pull request.
77func (c *Controller) Create(
78 ctx context.Context,
79 session *auth.Session,
80 repoRef string,
81 in *CreateInput,
82) (*types.PullReq, error) {
83 if err := in.Sanitize(); err != nil {
84 return nil, err
85 }
86
87 targetRepo, err := c.getRepoCheckAccess(ctx, session, repoRef, enum.PermissionRepoPush)
88 if err != nil {
89 return nil, fmt.Errorf("failed to acquire access to target repo: %w", err)
90 }
91
92 sourceRepo := targetRepo
93 if in.SourceRepoRef != "" {
94 sourceRepo, err = c.getRepoCheckAccess(ctx, session, in.SourceRepoRef, enum.PermissionRepoPush)
95 if err != nil {
96 return nil, fmt.Errorf("failed to acquire access to source repo: %w", err)
97 }
98 }
99
100 if sourceRepo.ID == targetRepo.ID && in.TargetBranch == in.SourceBranch {
101 return nil, usererror.BadRequest("target and source branch can't be the same")
102 }
103
104 var sourceSHA sha.SHA
105
106 if sourceSHA, err = c.verifyBranchExistence(ctx, sourceRepo, in.SourceBranch); err != nil {
107 return nil, err
108 }
109
110 if _, err = c.verifyBranchExistence(ctx, targetRepo, in.TargetBranch); err != nil {
111 return nil, err
112 }
113
114 if err = c.checkIfAlreadyExists(ctx, targetRepo.ID, sourceRepo.ID, in.TargetBranch, in.SourceBranch); err != nil {
115 return nil, err
116 }
117
118 targetWriteParams, err := controller.CreateRPCSystemReferencesWriteParams(
119 ctx, c.urlProvider, session, targetRepo,
120 )
121 if err != nil {
122 return nil, fmt.Errorf("failed to create RPC write params: %w", err)
123 }
124
125 mergeBaseResult, err := c.git.MergeBase(ctx, git.MergeBaseParams{
126 ReadParams: git.ReadParams{RepoUID: sourceRepo.GitUID},
127 Ref1: in.SourceBranch,
128 Ref2: in.TargetBranch,
129 })
130 if err != nil {
131 return nil, fmt.Errorf("failed to find merge base: %w", err)
132 }
133
134 mergeBaseSHA := mergeBaseResult.MergeBaseSHA

Callers

nothing calls this directly

Calls 15

getRepoCheckAccessMethod · 0.95
verifyBranchExistenceMethod · 0.95
checkIfAlreadyExistsMethod · 0.95
StringMethod · 0.95
prepareRuleReviewersMethod · 0.95
prepareLabelsMethod · 0.95
createReviewersMethod · 0.95
assignLabelsMethod · 0.95
BadRequestFunction · 0.92

Tested by

no test coverage detected