-
Notifications
You must be signed in to change notification settings - Fork 3
feat: support custom additional information in PR welcome message #1147
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
rnetser
wants to merge
10
commits into
main
Choose a base branch
from
feat/issue-1143-welcome-extra-info
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.
Open
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
309cf67
feat: support custom additional information in PR welcome message
rnetser 4a8d409
fix: address Qodo review findings
rnetser 4fa6345
fix: use byte-based size guard and verify schema definitions
rnetser 72ed9e4
fix: compute UTF-8 byte length once in size guard
rnetser eb57db7
fix: add log prefix to welcome-extra-info guard warnings
rnetser 91ec45a
fix: address human review comments on PR #1147
rnetser 7198a7b
fix: address review comments β stable interfaces + DRY test fixtures
rnetser 5513e10
fix: defer file loading until welcome comment is needed
rnetser 2c99e78
fix: extract welcome-extra-info to $defs/$ref in schema
rnetser 634d8f8
fix: skip file loading for reopened pull requests
rnetser 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
Some comments aren't visible on the classic Files Changed page.
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17,6 +17,7 @@ | |
| import httpx | ||
| from github import GithubException | ||
| from github.Commit import Commit | ||
| from github.GithubException import UnknownObjectException | ||
| from github.PullRequest import PullRequest | ||
| from github.Repository import Repository | ||
| from starlette.datastructures import Headers | ||
|
|
@@ -62,6 +63,8 @@ | |
| ) | ||
|
|
||
| _SHA_PATTERN = re.compile(r"^[0-9a-f]{40}$") | ||
| _WELCOME_EXTRA_INFO_MAX_BYTES: int = 10240 | ||
| _WELCOME_EXTRA_INFO_FILENAME: str = ".github-webhook-server-welcome-message.md" | ||
|
|
||
|
|
||
| class CountingRequester: | ||
|
|
@@ -142,6 +145,7 @@ def __init__(self, hook_data: dict[Any, Any], headers: Headers, logger: logging. | |
| self.github_api: github.Github | None = None | ||
| self.initial_rate_limit_remaining: int | None = None | ||
| self.requester_wrapper: CountingRequester | None = None | ||
| self.welcome_extra_info: str = "" | ||
|
|
||
| if not self.config.repository_data: | ||
| raise RepositoryNotFoundInConfigError(f"Repository {self.repository_name} not found in config file") | ||
|
|
@@ -689,6 +693,12 @@ async def process(self) -> Any: | |
| github_api_call(lambda: pull_request.head.sha, logger=self.logger, log_prefix=self.log_prefix), | ||
| ) | ||
|
|
||
| if self.github_event == "pull_request" and self.hook_data.get("action") in ( | ||
| "opened", | ||
| "ready_for_review", | ||
| ): | ||
| await self.load_welcome_extra_info_from_file() | ||
|
rnetser marked this conversation as resolved.
|
||
|
|
||
|
Comment on lines
+696
to
+701
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 1. Duplicate file fetch GithubWebhook.process() preloads .github-webhook-server-welcome-message.md on pull_request opened/ready_for_review, but PullRequestHandler.process_new_or_reprocess_pull_request() loads the same file again when creating the welcome comment. This causes an avoidable second get_contents() call on the common path where a welcome comment is created (including draftβready_for_review). Agent Prompt
|
||
| # Clone repository for local file processing (OWNERS, changed files) | ||
| # For check_run, status, and pull_request_review_thread events, | ||
| # cloning happens later only when needed (inside their respective handlers) | ||
|
|
@@ -1109,6 +1119,23 @@ def _sanitize_item(item: Any) -> str: | |
|
|
||
| self.mask_sensitive = self.config.get_value("mask-sensitive-data", return_on_none=True) | ||
|
|
||
| self.welcome_extra_info = self.config.get_value( | ||
| "welcome-extra-info", return_on_none="", extra_dict=repository_config | ||
| ) | ||
|
rnetser marked this conversation as resolved.
|
||
|
|
||
| _prefix = getattr(self, "log_prefix", "") | ||
| if not isinstance(self.welcome_extra_info, str): | ||
|
rnetser marked this conversation as resolved.
|
||
| _type = type(self.welcome_extra_info).__name__ | ||
| self.logger.warning(f"{_prefix} welcome-extra-info must be a string, got {_type}. Ignoring.") | ||
| self.welcome_extra_info = "" | ||
| else: | ||
| _byte_len = len(self.welcome_extra_info.encode("utf-8")) | ||
| if _byte_len > _WELCOME_EXTRA_INFO_MAX_BYTES: | ||
| _max = _WELCOME_EXTRA_INFO_MAX_BYTES | ||
| _msg = f"welcome-extra-info exceeds {_max}-byte limit ({_byte_len} bytes). Ignoring." | ||
| self.logger.warning(f"{_prefix} {_msg}") | ||
| self.welcome_extra_info = "" | ||
|
|
||
| async def _build_trusted_committers(self, api_users: list[str | None] | None = None) -> None: | ||
| """Add dynamic entries to trusted-committers list. | ||
|
|
||
|
|
@@ -1142,6 +1169,50 @@ async def _build_trusted_committers(self, api_users: list[str | None] | None = N | |
|
|
||
| self.logger.debug(f"{self.log_prefix} Trusted committers: {self.security_trusted_committers}") | ||
|
|
||
| async def load_welcome_extra_info_from_file(self) -> None: | ||
| """Load welcome extra info from the repo-level welcome message file. | ||
|
|
||
| This file takes priority over all config-based welcome-extra-info settings. | ||
| File must be UTF-8 and at most _WELCOME_EXTRA_INFO_MAX_BYTES bytes (10 KB). | ||
| """ | ||
| try: | ||
| _path = await github_api_call( | ||
| lambda: self.repository.get_contents(_WELCOME_EXTRA_INFO_FILENAME), | ||
| logger=self.logger, | ||
| log_prefix=self.log_prefix, | ||
| ) | ||
| content_file = _path[0] if isinstance(_path, list) else _path | ||
|
|
||
| file_size = await github_api_call(lambda: content_file.size, logger=self.logger, log_prefix=self.log_prefix) | ||
| if file_size > _WELCOME_EXTRA_INFO_MAX_BYTES: | ||
| self.logger.warning( | ||
| f"{self.log_prefix} {_WELCOME_EXTRA_INFO_FILENAME} is too large " | ||
| f"({file_size} bytes, max {_WELCOME_EXTRA_INFO_MAX_BYTES}). Skipping file, using config value." | ||
| ) | ||
| return | ||
|
|
||
| raw_content = await github_api_call( | ||
| lambda: content_file.decoded_content, logger=self.logger, log_prefix=self.log_prefix | ||
| ) | ||
| decoded = raw_content.decode("utf-8").strip() | ||
| self.welcome_extra_info = decoded | ||
|
rnetser marked this conversation as resolved.
|
||
| if decoded: | ||
| self.logger.info( | ||
| f"{self.log_prefix} Loaded welcome extra info from {_WELCOME_EXTRA_INFO_FILENAME} " | ||
| f"({len(decoded)} chars)" | ||
| ) | ||
| else: | ||
| self.logger.info( | ||
| f"{self.log_prefix} Empty {_WELCOME_EXTRA_INFO_FILENAME} found, " | ||
| "suppressing config-based welcome extra info" | ||
| ) | ||
| except UnknownObjectException: | ||
| self.logger.debug(f"{self.log_prefix} {_WELCOME_EXTRA_INFO_FILENAME} not found, using config value") | ||
| except UnicodeDecodeError: | ||
| self.logger.warning(f"{self.log_prefix} {_WELCOME_EXTRA_INFO_FILENAME} is not valid UTF-8, skipping file") | ||
| except Exception: | ||
| self.logger.exception(f"{self.log_prefix} Error loading {_WELCOME_EXTRA_INFO_FILENAME}, using config value") | ||
|
|
||
| async def get_pull_request(self, number: int | None = None) -> PullRequest | None: | ||
| if number: | ||
| self.logger.debug(f"{self.log_prefix} Attempting to get PR by number: {number}") | ||
|
|
||
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
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.
Uh oh!
There was an error while loading. Please reload this page.