-
Notifications
You must be signed in to change notification settings - Fork 396
github: make the review link in the PR-body stack footer configurable #1410
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
netproteus
wants to merge
1
commit into
facebook:main
Choose a base branch
from
netproteus:footer-config
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+352
−12
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,92 @@ | ||
| # Copyright (c) Meta Platforms, Inc. and affiliates. | ||
| # | ||
| # This software may be used and distributed according to the terms of the | ||
| # GNU General Public License version 2. | ||
|
|
||
| from sapling import extensions | ||
| from sapling.ext.github import github_gh_cli, submit | ||
| from sapling.ext.github.consts import GITHUB_HOSTNAME | ||
| from sapling.ext.github.mock_utils import ( | ||
| mock_run_git_command, | ||
| MockGitHubServer, | ||
| OWNER, | ||
| REPO_NAME, | ||
| ) | ||
| from sapling.ext.github.pull_request_body import ( | ||
| _format_review_url, | ||
| DEFAULT_REVIEW_TOOL_NAME, | ||
| DEFAULT_REVIEW_URL_TEMPLATE, | ||
| title_and_body, | ||
| ) | ||
|
|
||
| # An extension to mock network requests for `sl pr submit` with customized | ||
| # github.pull-request-review-url-template / github.pull-request-review-tool-name | ||
| # configs. The expected review link is computed from the same configs the test | ||
| # sets, so the mock server only matches if the customized footer was produced. | ||
|
|
||
|
|
||
| def setup_mock_github_server(ui) -> MockGitHubServer: | ||
| """Setup mock GitHub Server for testing `sl pr submit` with a custom review link.""" | ||
| github_server = MockGitHubServer() | ||
|
|
||
| github_server.expect_get_repository_request().and_respond() | ||
|
|
||
| github_server.expect_guess_next_pull_request_number().and_respond() | ||
|
|
||
| url_template = ( | ||
| ui.config("github", "pull-request-review-url-template") | ||
| or DEFAULT_REVIEW_URL_TEMPLATE | ||
| ) | ||
| review_tool = ( | ||
| ui.config("github", "pull-request-review-tool-name") | ||
| or DEFAULT_REVIEW_TOOL_NAME | ||
| ) | ||
|
|
||
| prs = [ | ||
| (42, "one\n"), | ||
| (43, "two\n"), | ||
| ] | ||
|
|
||
| for num, msg in prs: | ||
| title, body = title_and_body(msg) | ||
| head = f"pr{num}" | ||
| base = "main" | ||
|
|
||
| github_server.expect_create_pr_request( | ||
| body=body, | ||
| title=title, | ||
| head=head, | ||
| base=base, | ||
| ).and_respond(number=num) | ||
|
|
||
| pr_id = f"PR_id_{num}" | ||
| github_server.expect_get_pr_details_request(num).and_respond(pr_id) | ||
|
|
||
| review_url = _format_review_url( | ||
| url_template, owner=OWNER, repo=REPO_NAME, number=num, hostname=GITHUB_HOSTNAME | ||
| ) | ||
|
|
||
| github_server.expect_update_pr_request( | ||
| pr_id, | ||
| num, | ||
| msg, | ||
| base=base, | ||
| stack_pr_ids=[pr[0] for pr in prs], | ||
| review_url=review_url, | ||
| review_tool=review_tool, | ||
| ).and_respond() | ||
|
|
||
| github_server.expect_get_username_request().and_respond() | ||
|
|
||
| head = "1a67244b0a776bfcc3be6bf811e98c993d78ce47" | ||
| github_server.expect_merge_into_branch(head).and_respond() | ||
|
|
||
| return github_server | ||
|
|
||
|
|
||
| def uisetup(ui): | ||
| mock_github_server = setup_mock_github_server(ui) | ||
| extensions.wrapfunction( | ||
| github_gh_cli, "_make_request", mock_github_server.make_request | ||
| ) | ||
| extensions.wrapfunction(submit, "run_git_command", mock_run_git_command) |
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you help add a comment for this logic?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added — it mirrors
get_upstream_owner_and_name()just above: PRs live in the upstream repository, so{hostname}expands from the upstream when submitting from a fork; for non-fork clones it's the same host.