-
Notifications
You must be signed in to change notification settings - Fork 0
Made changes to fix the head sha commit in diff comment #56
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -22,7 +22,6 @@ class Settings(ABC): | |
| ref: str | ||
| repository: str | ||
| base_ref: str | ||
| pr_num: str | None | ||
|
|
||
| # from step config including secrets | ||
| token: str | ||
|
|
@@ -32,6 +31,31 @@ class Settings(ABC): | |
| sigil_envvar: ClassVar[str] | ||
| """The envvar in this will always be present when this settings is valid.""" | ||
|
|
||
| _pr_lookup_service: PrLookupService | None = None | ||
|
|
||
| def set_pr_lookup_service(self, service: PrLookupService) -> None: | ||
| self._pr_lookup_service = service | ||
|
|
||
| _pr_num_cached: str = "" | ||
|
|
||
| @property | ||
| def pr_num(self) -> str | None: | ||
| if self._pr_num_cached: | ||
| return self._pr_num_cached | ||
|
|
||
| if self._pr_lookup_service is None: | ||
| logger.warning("PR lookup requested before service configured; returning None") | ||
| return None | ||
|
Comment on lines
+47
to
+48
Collaborator
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. issue (non-blocking): Can the rest of the process continue if the pr_num isn't available? If it can, this is fine. If it can't, then this should raise an exception.
Collaborator
Author
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. Yes. Wherever pr_num is called, we've a check to see whether it is None because it's not a blocker |
||
|
|
||
| logger.debug("Settings.pr_num looking up PR for branch {}", self.ref) | ||
| pr_num = self._pr_lookup_service.find_pr_for_branch(self.ref) | ||
| object.__setattr__(self, "_pr_num_cached", pr_num) | ||
| if pr_num: | ||
| logger.debug("Settings.pr_num found PR #{}", pr_num) | ||
| else: | ||
| logger.warning("Settings.pr_num found no open PR") | ||
| return pr_num | ||
|
|
||
| @classmethod | ||
| def matches_env(cls, env: dict[str, str]) -> bool: | ||
| """Check whether this CI's identifying env var is present.""" | ||
|
|
@@ -65,34 +89,15 @@ def __init__(self, **values: Any) -> None: # noqa: ANN401 | |
| logger.debug("VelaSettings ref={}", self.ref) | ||
| logger.debug("VelaSettings event_name={}", self.event_name) | ||
|
|
||
| def set_pr_lookup_service(self, service: PrLookupService) -> None: | ||
| self._pr_lookup_service = service | ||
|
Collaborator
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. thought: ☝️ like this was
Collaborator
Author
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. Updated to set it like how it did before |
||
|
|
||
| @property | ||
| def pr_num(self) -> str | None: # type: ignore[override] | ||
| if self._pr_num_cached: | ||
| return self._pr_num_cached | ||
|
|
||
| if self._pr_lookup_service is None: | ||
| logger.warning("PR lookup requested before service configured; returning None") | ||
| return None | ||
|
|
||
| logger.debug("VelaSettings.pr_num looking up PR for branch {}", self.ref) | ||
| pr_num = self._pr_lookup_service.find_pr_for_branch(self.ref) | ||
| self._pr_num_cached = pr_num | ||
| if pr_num: | ||
| logger.debug("VelaSettings.pr_num found PR #{}", pr_num) | ||
| else: | ||
| logger.warning("VelaSettings.pr_num found no open PR") | ||
| return pr_num | ||
|
|
||
|
|
||
| class GitHubActionsSettings(BaseSettings, Settings): | ||
| sigil_envvar: ClassVar[str] = "github_repository" | ||
| _pr_lookup_service: PrLookupService | None = PrivateAttr(default=None) | ||
| _pr_num_cached: str = PrivateAttr(default="") | ||
|
|
||
| # from CI | ||
| event_name: str = Field(env="github_event_name") # must be 'pull_request' | ||
| ref: str = Field(env="github_ref") | ||
| ref: str = Field(env="github_head_ref") | ||
| repository: str = Field(env="github_repository") | ||
| base_ref: str = Field(env="github_base_ref") | ||
|
|
||
|
|
@@ -120,12 +125,6 @@ def event_must_be_pull_request(cls, v: str) -> str: | |
| raise ValueError(msg) | ||
| return v | ||
|
|
||
| @property | ||
| # todo: Avoid this MyPy error by having Pydantic compute the field | ||
| def pr_num(self) -> str | None: # type: ignore[override] | ||
| # TODO: Validate early | ||
| return self.ref.split("/")[2] | ||
|
|
||
|
|
||
| _CI_SETTINGS_CANDIDATES: list[type[Settings]] = [GitHubActionsSettings, VelaSettings] | ||
|
|
||
|
|
||
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.
note: Ah, I see, this was promoted to the base class from VelaSettings…