Update updates an pull request.
(ctx context.Context, session *auth.Session, repoRef string, pullreqNum int64, in *UpdateInput, )
| 50 | |
| 51 | // Update updates an pull request. |
| 52 | func (c *Controller) Update(ctx context.Context, |
| 53 | session *auth.Session, repoRef string, pullreqNum int64, in *UpdateInput, |
| 54 | ) (*types.PullReq, error) { |
| 55 | if err := in.Sanitize(); err != nil { |
| 56 | return nil, err |
| 57 | } |
| 58 | |
| 59 | targetRepo, err := c.getRepoCheckAccess(ctx, session, repoRef, enum.PermissionRepoPush) |
| 60 | if err != nil { |
| 61 | return nil, fmt.Errorf("failed to acquire access to target repo: %w", err) |
| 62 | } |
| 63 | |
| 64 | pr, err := c.pullreqStore.FindByNumber(ctx, targetRepo.ID, pullreqNum) |
| 65 | if err != nil { |
| 66 | return nil, fmt.Errorf("failed to get pull request by number: %w", err) |
| 67 | } |
| 68 | |
| 69 | if pr.SourceRepoID != pr.TargetRepoID { |
| 70 | var sourceRepo *types.RepositoryCore |
| 71 | |
| 72 | sourceRepo, err = c.repoFinder.FindByID(ctx, pr.SourceRepoID) |
| 73 | if err != nil { |
| 74 | return nil, fmt.Errorf("failed to get source repo by id: %w", err) |
| 75 | } |
| 76 | |
| 77 | if err = apiauth.CheckRepo(ctx, c.authorizer, session, sourceRepo, |
| 78 | enum.PermissionRepoView); err != nil { |
| 79 | return nil, fmt.Errorf("failed to acquire access to source repo: %w", err) |
| 80 | } |
| 81 | } |
| 82 | |
| 83 | titleOld := pr.Title |
| 84 | descriptionOld := pr.Description |
| 85 | |
| 86 | titleChanged := titleOld != in.Title |
| 87 | descriptionChanged := descriptionOld != in.Description |
| 88 | |
| 89 | if !titleChanged && !descriptionChanged { |
| 90 | return pr, nil |
| 91 | } |
| 92 | |
| 93 | needToWriteActivity := titleChanged |
| 94 | |
| 95 | pr, err = c.pullreqStore.UpdateOptLock(ctx, pr, func(pr *types.PullReq) error { |
| 96 | pr.Title = in.Title |
| 97 | pr.Description = in.Description |
| 98 | if needToWriteActivity { |
| 99 | pr.ActivitySeq++ |
| 100 | } |
| 101 | return nil |
| 102 | }) |
| 103 | if err != nil { |
| 104 | return pr, fmt.Errorf("failed to update pull request: %w", err) |
| 105 | } |
| 106 | |
| 107 | if needToWriteActivity { |
| 108 | payload := &types.PullRequestActivityPayloadTitleChange{ |
| 109 | Old: titleOld, |
nothing calls this directly
no test coverage detected