Skip to content

Commit

Permalink
🐛 Fix: issue closed webhook render actor error (#80)
Browse files Browse the repository at this point in the history
  • Loading branch information
yanyongyu committed May 25, 2024
1 parent 57fb990 commit 1d2fe09
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 13 deletions.
5 changes: 3 additions & 2 deletions src/plugins/github/libs/renderer/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
@Author : yanyongyu
@Date : 2021-03-09 16:45:25
@LastEditors : yanyongyu
@LastEditTime : 2024-05-23 17:15:48
@LastEditTime : 2024-05-25 12:30:54
@Description : GitHub image renderer
@GitHub : https://github.com/yanyongyu
"""
Expand Down Expand Up @@ -164,9 +164,10 @@ async def issue_closed_to_image(
bot: GitHubBot | OAuthBot,
repo: models.RepositoryWebhooks,
issue: models.WebhookIssuesClosedPropIssue | models.PullRequestWebhook,
sender: models.SimpleUserWebhooks,
) -> bytes:
"""Render webhook event issue/closed to image"""
context = await IssueClosedContext.from_webhook(bot, repo, issue)
context = await IssueClosedContext.from_webhook(bot, repo, issue, sender)
context_hash = _context_hash(context)
if cached_image := await get_rendered_image("issue_closed", context_hash):
return cached_image
Expand Down
16 changes: 13 additions & 3 deletions src/plugins/github/libs/renderer/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
@Author : yanyongyu
@Date : 2023-10-18 16:20:28
@LastEditors : yanyongyu
@LastEditTime : 2024-05-16 15:29:39
@LastEditTime : 2024-05-25 12:40:07
@Description : None
@GitHub : https://github.com/yanyongyu
"""
Expand Down Expand Up @@ -953,7 +953,7 @@ class IssueClosedContext:
repo: RepoInfo
issue: IssueInfo | PullRequestInfo
labels: list[tuple[str, tuple[int, int, int, int, int, int]]]
merge_commit_sha: str | None
event: TimelineEventStateChange

@property
def is_pull_request(self) -> bool:
Expand All @@ -965,12 +965,15 @@ async def from_webhook(
bot: GitHubBot | OAuthBot,
repo: models.RepositoryWebhooks,
issue: models.WebhookIssuesClosedPropIssue | models.PullRequestWebhook,
sender: models.SimpleUserWebhooks,
) -> Self:
if isinstance(issue, models.PullRequestWebhook):
issue_info = PullRequestInfo.from_webhook(issue)
state_reason = None
merge_commit_sha = issue.merge_commit_sha
else:
issue_info = IssueInfo.from_webhook(issue)
state_reason = issue.state_reason if issue.state_reason else None
merge_commit_sha = None

labels: list[tuple[str, tuple[int, int, int, int, int, int]]] = []
Expand All @@ -982,5 +985,12 @@ async def from_webhook(
repo=RepoInfo.from_webhook(repo),
issue=issue_info,
labels=labels,
merge_commit_sha=merge_commit_sha,
event=TimelineEventStateChange(
event="closed",
actor=sender.login,
actor_avatar=sender.avatar_url,
created_at=issue.closed_at or issue.updated_at,
state_reason=state_reason,
commit_id=merge_commit_sha,
),
)
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* @Author : yanyongyu
* @Date : 2022-09-22 05:21:01
* @LastEditors : yanyongyu
* @LastEditTime : 2024-05-16 16:58:59
* @LastEditTime : 2024-05-25 12:44:04
* @Description : None
* @GitHub : https://github.com/yanyongyu
-->
Expand All @@ -15,7 +15,7 @@
actor: str
actor_avatar: str
created_at: datetime
state_reason: str
state_reason: str | None
is_pull_request: bool
#}
{% macro closed(actor, actor_avatar, created_at, state_reason, is_pull_request) %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* @Author : yanyongyu
* @Date : 2024-05-16 14:44:52
* @LastEditors : yanyongyu
* @LastEditTime : 2024-05-18 18:02:01
* @LastEditTime : 2024-05-25 12:42:23
* @Description : None
* @GitHub : https://github.com/yanyongyu
-->
Expand Down Expand Up @@ -66,13 +66,13 @@ ctx.repo.parent_full_name, ctx.repo.template_full_name, ctx.repo.forks_count, ct
{# show merged if pr merged #}
{% if ctx.is_pull_request and ctx.issue.merged %}
{{ merged(
ctx.issue.user, ctx.issue.user_avatar, ctx.issue.created_at,
ctx.merge_commit_sha, ctx.issue.base_ref
ctx.event.actor, ctx.event.actor_avatar, ctx.event.created_at,
ctx.event.commit_id, ctx.issue.base_ref
) }}
{% else %}
{{ closed(
ctx.issue.user, ctx.issue.user_avatar, ctx.issue.created_at,
ctx.issue.state_reason|default(none), ctx.is_pull_request
ctx.event.actor, ctx.event.actor_avatar, ctx.event.created_at,
ctx.event.state_reason, ctx.is_pull_request
) }}
{% endif %}
</div>
Expand Down
4 changes: 3 additions & 1 deletion src/plugins/github/webhooks/issue_closed.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,9 @@ async def handle_issue_closed_event(
try:
installation = cast(SimpleInstallation, event.payload.installation)
async with bot.as_installation(installation.id):
image = await issue_closed_to_image(bot, event.payload.repository, issue)
image = await issue_closed_to_image(
bot, event.payload.repository, issue, event.payload.sender
)
except (ActionTimeout, TimeoutError, Error):
pass
except Exception as e:
Expand Down

0 comments on commit 1d2fe09

Please sign in to comment.