Skip to content
This repository was archived by the owner on Sep 30, 2024. It is now read-only.

batch-changes: ensure PR is only approved after code owner review#53601

Merged
davejrt merged 11 commits into
mainfrom
dt/batch_codeowners
Jun 26, 2023
Merged

batch-changes: ensure PR is only approved after code owner review#53601
davejrt merged 11 commits into
mainfrom
dt/batch_codeowners

Conversation

@davejrt

@davejrt davejrt commented Jun 16, 2023

Copy link
Copy Markdown
Contributor

Attempts to address https://github.com/sourcegraph/sourcegraph/issues/50874

By getting the "ReviewDecision" from a PR which is only "APPROVED" once a codeowner (if required) has reviewed the PR, otherwise this field returns "REVIEW_REQUIRED" or "CHANGES_REQUSTED".

Given there is a no longer a requirement for events on github PRs, we don't need to calculate if the changeset is older than events before computing the state.

Test plan

CI passing, tested locally with a repo on ghe.sgdev.org with a codeowners file

@cla-bot cla-bot Bot added the cla-signed label Jun 16, 2023
@davejrt davejrt force-pushed the dt/batch_codeowners branch from 4a3db93 to dc59ea9 Compare June 16, 2023 12:27
@davejrt

davejrt commented Jun 16, 2023

Copy link
Copy Markdown
Contributor Author

Current issue is, the MergableState field on the pullrequest type is empty, despite it being populated when querying the pull request via the github api:

  "BaseRepository": {
    "ID": "MDEwOlJlcG9zaXRvcnk5Nzg=",
    "Name": "JetBrains-ideavim",
    "Owner": {
      "Login": "sourcegraph"
    }
  },
  "HeadRepository": {
    "ID": "MDEwOlJlcG9zaXRvcnk5Nzg=",
    "Name": "JetBrains-ideavim",
    "Owner": {
      "Login": "sourcegraph"
    }
  },
  "MergeableState": ""
}
  "author_association": "MEMBER",
  "auto_merge": null,
  "active_lock_reason": null,
  "merged": false,
  "mergeable": true,
  "rebaseable": true,
  "mergeable_state": "blocked",
  "merged_by": null,
  "comments": 0,
  "review_comments": 0,
  "maintainer_can_modify": false,
  "commits": 1,
  "additions": 1,
  "deletions": 0,
  "changed_files": 1
}```

@davejrt davejrt requested review from a team and eseliger June 16, 2023 13:38
@davejrt

davejrt commented Jun 16, 2023

Copy link
Copy Markdown
Contributor Author

Example of what is returned from createPullRequest where mergablestate is empty

pr: &{RepoWithOwner: 
ID:MDExOlB1bGxSZXF1ZXN0OTg1 
Title:Hello World 
Body:My first batch change!
[_Created by Sourcegraph batch change `admin/hello-world`._]
(https://sourcegraph.test:3443/users/admin/batch-changes/hello-world) 
State:OPEN URL:https://ghe.sgdev.org/sourcegraph/JetBrains-ideavim/pull/15 
HeadRefOid:d08b7c73844d4d97beafdba5def4b0cea6fd1639 
BaseRefOid:e44ea7ae691ee9004d0b0c9167a58af044e94ba9 
HeadRefName:hello-world-2 
BaseRefName:master 
Number:15 
MergeableState: 
Author:{AvatarURL:https://ghe.sgdev.org/avatars/u/3 
Login:milton 
URL:https://ghe.sgdev.org/milton} 
BaseRepository:{ID:MDEwOlJlcG9zaXRvcnk5Nzg= 
Name:JetBrains-ideavim Owner:{Login:sourcegraph}} 
HeadRepository:{ID:MDEwOlJlcG9zaXRvcnk5Nzg= 
Name:JetBrains-ideavim 
Owner:{Login:sourcegraph}} 
Participants:[] 
Labels:{Nodes:[]} 
TimelineItems:[] 
Commits:{Nodes:[{Commit:{OID:d08b7c73844d4d97beafdba5def4b0cea6fd1639 
CheckSuites:{Nodes:[]} 
Status:{State: 
Contexts:[]} 
CommittedDate:2023-06-16 15:00:13 +0000 UTC}}]} 
IsDraft:false 
CreatedAt:2023-06-16 15:00:33 +0000 UTC 
UpdatedAt:2023-06-16 15:00:33 +0000 UTC}

@davejrt davejrt marked this pull request as ready for review June 22, 2023 01:30
@sourcegraph-bot

sourcegraph-bot commented Jun 22, 2023

Copy link
Copy Markdown
Contributor

Codenotify: Notifying subscribers in CODENOTIFY files for diff 935a989...8c61612.

Notify File(s)
@eseliger enterprise/internal/batches/sources/github_test.go
enterprise/internal/batches/sources/testdata/golden/GithubSource_CloseChangeset_DeleteSourceBranch_success
enterprise/internal/batches/sources/testdata/golden/GithubSource_CloseChangeset_success
enterprise/internal/batches/sources/testdata/golden/GithubSource_CreateChangeset_already_exists
enterprise/internal/batches/sources/testdata/golden/GithubSource_CreateChangeset_success
enterprise/internal/batches/sources/testdata/golden/GithubSource_LoadChangeset_found
enterprise/internal/batches/sources/testdata/golden/GithubSource_ReopenChangeset_success
enterprise/internal/batches/sources/testdata/golden/GithubSource_UpdateChangeset_success
enterprise/internal/batches/sources/testdata/sources/GithubSource_CloseChangeset_DeleteSourceBranch_success.yaml
enterprise/internal/batches/sources/testdata/sources/GithubSource_CloseChangeset_success.yaml
enterprise/internal/batches/sources/testdata/sources/GithubSource_CreateChangeset_already_exists.yaml
enterprise/internal/batches/sources/testdata/sources/GithubSource_CreateChangeset_success.yaml
enterprise/internal/batches/sources/testdata/sources/GithubSource_LoadChangeset_found.yaml
enterprise/internal/batches/sources/testdata/sources/GithubSource_LoadChangeset_not-found.yaml
enterprise/internal/batches/sources/testdata/sources/GithubSource_ReopenChangeset_success.yaml
enterprise/internal/batches/sources/testdata/sources/GithubSource_UpdateChangeset_success.yaml
enterprise/internal/batches/state/state.go
enterprise/internal/batches/state/state_test.go
enterprise/internal/batches/types/changeset.go
internal/extsvc/github/common.go
internal/extsvc/github/testdata/golden/ClosePullRequest-0
internal/extsvc/github/testdata/golden/ClosePullRequest-1
internal/extsvc/github/testdata/golden/CreatePullRequest-0
internal/extsvc/github/testdata/golden/CreatePullRequest-3
internal/extsvc/github/testdata/golden/LoadPullRequest-2
internal/extsvc/github/testdata/golden/LoadPullRequest-3
internal/extsvc/github/testdata/golden/MarkPullRequestReadyForReview-0
internal/extsvc/github/testdata/golden/MarkPullRequestReadyForReview-1
internal/extsvc/github/testdata/golden/MergePullRequest-error
internal/extsvc/github/testdata/golden/MergePullRequest-success
internal/extsvc/github/testdata/golden/ReopenPullRequest-0
internal/extsvc/github/testdata/golden/ReopenPullRequest-1
internal/extsvc/github/testdata/vcr/ClosePullRequest.yaml
internal/extsvc/github/testdata/vcr/CreatePullRequest.yaml
internal/extsvc/github/testdata/vcr/CreatePullRequestComment.yaml
internal/extsvc/github/testdata/vcr/CreatePullRequest_Archived.yaml
internal/extsvc/github/testdata/vcr/LoadPullRequest.yaml
internal/extsvc/github/testdata/vcr/MarkPullRequestReadyForReview.yaml
internal/extsvc/github/testdata/vcr/ReopenPullRequest.yaml
internal/extsvc/github/testdata/vcr/TestMergePullRequest.yaml
internal/extsvc/github/v4_test.go
@sashaostrikov internal/extsvc/github/common.go
internal/extsvc/github/testdata/golden/ClosePullRequest-0
internal/extsvc/github/testdata/golden/ClosePullRequest-1
internal/extsvc/github/testdata/golden/CreatePullRequest-0
internal/extsvc/github/testdata/golden/CreatePullRequest-3
internal/extsvc/github/testdata/golden/LoadPullRequest-2
internal/extsvc/github/testdata/golden/LoadPullRequest-3
internal/extsvc/github/testdata/golden/MarkPullRequestReadyForReview-0
internal/extsvc/github/testdata/golden/MarkPullRequestReadyForReview-1
internal/extsvc/github/testdata/golden/MergePullRequest-error
internal/extsvc/github/testdata/golden/MergePullRequest-success
internal/extsvc/github/testdata/golden/ReopenPullRequest-0
internal/extsvc/github/testdata/golden/ReopenPullRequest-1
internal/extsvc/github/testdata/vcr/ClosePullRequest.yaml
internal/extsvc/github/testdata/vcr/CreatePullRequest.yaml
internal/extsvc/github/testdata/vcr/CreatePullRequestComment.yaml
internal/extsvc/github/testdata/vcr/CreatePullRequest_Archived.yaml
internal/extsvc/github/testdata/vcr/LoadPullRequest.yaml
internal/extsvc/github/testdata/vcr/MarkPullRequestReadyForReview.yaml
internal/extsvc/github/testdata/vcr/ReopenPullRequest.yaml
internal/extsvc/github/testdata/vcr/TestMergePullRequest.yaml
internal/extsvc/github/v4_test.go

@davejrt davejrt force-pushed the dt/batch_codeowners branch from d411fad to 082ffc4 Compare June 22, 2023 11:29

@BolajiOlajide BolajiOlajide left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the fix @davejrt !

Comment thread enterprise/internal/batches/types/changeset.go Outdated
HeadRefName string
BaseRefName string
Number int64
ReviewDecision string

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I noticed that the ReviewDecision field only exists in the GraphQL response for loading a pull request and not the response from the REST API.

CleanShot 2023-06-22 at 12 46 04@2x

I've checked and confirmed we only load pull requests using the v4 client.

@davejrt davejrt force-pushed the dt/batch_codeowners branch from 9e21cb3 to ebbbb58 Compare June 23, 2023 19:32
@davejrt davejrt force-pushed the dt/batch_codeowners branch from ebbbb58 to 74a5a60 Compare June 23, 2023 19:45
@davejrt davejrt merged commit 6ea307e into main Jun 26, 2023
@davejrt davejrt deleted the dt/batch_codeowners branch June 26, 2023 14:41
@davejrt davejrt added EE/paper cuts customer issues that will be worked on as part of EE rotation backport 5.1 labels Jun 26, 2023
github-actions Bot pushed a commit that referenced this pull request Jun 26, 2023
…3601)

Attempts to address
https://github.com/sourcegraph/sourcegraph/issues/50874

By getting the "ReviewDecision" from a PR which is only "APPROVED" once
a codeowner (if required) has reviewed the PR, otherwise this field
returns "REVIEW_REQUIRED" or "CHANGES_REQUSTED".

Given there is a no longer a requirement for events on github PRs, we
don't need to calculate if the changeset is older than events before
computing the state.

## Test plan

CI passing, tested locally with a repo on ghe.sgdev.org with a
codeowners file

(cherry picked from commit 6ea307e)
@davejrt davejrt mentioned this pull request Jun 26, 2023
davejrt referenced this pull request Jun 26, 2023
github-actions Bot referenced this pull request Jun 26, 2023
Add changelog entry for
https://github.com/sourcegraph/sourcegraph/pull/53601

## Test plan

CI

(cherry picked from commit c2478af)
keegancsmith pushed a commit that referenced this pull request Jun 27, 2023
…wner review (#54174)

Attempts to address
https://github.com/sourcegraph/sourcegraph/issues/50874

By getting the "ReviewDecision" from a PR which is only
"APPROVED" once a codeowner (if required) has reviewed the PR,
otherwise this field returns "REVIEW_REQUIRED" or
"CHANGES_REQUSTED".

Given there is a no longer a requirement for events on github PRs, we
don't need to calculate if the changeset is older than events before
computing the state.

## Test plan

CI passing, tested locally with a repo on ghe.sgdev.org with a
codeowners file <br> Backport 6ea307e
from #53601

Co-authored-by: Dave Try <davetry@gmail.com>
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

cla-signed EE/paper cuts customer issues that will be worked on as part of EE rotation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants