Skip to content

Commit

Permalink
change: 通过议题标签判断商店发布类型 (#137)
Browse files Browse the repository at this point in the history
  • Loading branch information
he0119 authored Jun 12, 2023
1 parent e17b8e4 commit e6367e5
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 57 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/lang/zh-CN/

## [Unreleased]

### Changed

- 通过议题标签判断商店发布类型

## [2.4.0] - 2023-06-11

### Added
Expand Down
12 changes: 2 additions & 10 deletions src/plugins/publish/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
get_related_issue_number,
get_repo_info,
get_type_by_labels,
get_type_by_title,
)
from .models import PublishType, RepoInfo
from .utils import (
Expand Down Expand Up @@ -112,7 +111,7 @@ async def handle_pr_close(

async def check_rule(
event: IssuesOpened | IssuesReopened | IssuesEdited | IssueCommentCreated,
publish_type: PublishType | None = Depends(get_type_by_title),
publish_type: PublishType | None = Depends(get_type_by_labels),
) -> bool:
if isinstance(
event, IssueCommentCreated
Expand Down Expand Up @@ -141,7 +140,7 @@ async def handle_publish_check(
installation_id: int = Depends(get_installation_id),
repo_info: RepoInfo = Depends(get_repo_info),
issue_number: int = Depends(get_issue_number),
publish_type: PublishType = Depends(get_type_by_title),
publish_type: PublishType = Depends(get_type_by_labels),
) -> None:
async with bot.as_installation(installation_id):
# 因为 Actions 会排队,触发事件相关的议题在 Actions 执行时可能已经被关闭
Expand All @@ -156,13 +155,6 @@ async def handle_publish_check(
logger.info("议题未开启,已跳过")
await publish_check_matcher.finish()

# 自动给议题添加标签
await bot.rest.issues.async_add_labels(
**repo_info.dict(),
issue_number=issue_number,
labels=[publish_type.value],
)

# 是否需要跳过插件测试
plugin_config.skip_plugin_test = await should_skip_plugin_test(
bot, repo_info, issue_number
Expand Down
12 changes: 11 additions & 1 deletion tests/publish/events/issue-open.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,17 @@
"events_url": "https://api.github.com/repos/he0119/action-test/issues/80/events",
"html_url": "https://github.com/he0119/action-test/issues/80",
"id": 1518188444,
"labels": [],
"labels": [
{
"color": "2A2219",
"default": false,
"description": "",
"id": 2798075966,
"name": "Bot",
"node_id": "MDU6TGFiZWwyNzk4MDc1OTY2",
"url": "https://api.github.com/repos/he0119/action-test/labels/Bot"
}
],
"labels_url": "https://api.github.com/repos/he0119/action-test/issues/80/labels{/name}",
"locked": false,
"milestone": null,
Expand Down
48 changes: 2 additions & 46 deletions tests/publish/process/test_publish_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ async def test_process_publish_check(
event_path = Path(__file__).parent.parent / "events" / "issue-open.json"
event = Adapter.payload_to_event("1", "issues", event_path.read_bytes())
assert isinstance(event, IssuesOpened)
event.payload.issue.title = "Bot: test"

ctx.should_call_api(
"rest.apps.async_get_repo_installation",
Expand All @@ -90,16 +89,6 @@ async def test_process_publish_check(
{"owner": "he0119", "repo": "action-test", "issue_number": 80},
mock_issues_resp,
)
ctx.should_call_api(
"rest.issues.async_add_labels",
{
"owner": "he0119",
"repo": "action-test",
"issue_number": 80,
"labels": ["Bot"],
},
True,
)
ctx.should_call_api(
"rest.issues.async_list_comments",
{"owner": "he0119", "repo": "action-test", "issue_number": 80},
Expand Down Expand Up @@ -271,7 +260,6 @@ async def test_edit_title(
event_path = Path(__file__).parent.parent / "events" / "issue-open.json"
event = Adapter.payload_to_event("1", "issues", event_path.read_bytes())
assert isinstance(event, IssuesOpened)
event.payload.issue.title = "Bot: test"

ctx.should_call_api(
"rest.apps.async_get_repo_installation",
Expand All @@ -283,16 +271,6 @@ async def test_edit_title(
{"owner": "he0119", "repo": "action-test", "issue_number": 80},
mock_issues_resp,
)
ctx.should_call_api(
"rest.issues.async_add_labels",
{
"owner": "he0119",
"repo": "action-test",
"issue_number": 80,
"labels": ["Bot"],
},
True,
)
ctx.should_call_api(
"rest.issues.async_list_comments",
{"owner": "he0119", "repo": "action-test", "issue_number": 80},
Expand Down Expand Up @@ -468,7 +446,6 @@ async def test_process_publish_check_not_pass(
event_path = Path(__file__).parent.parent / "events" / "issue-open.json"
event = Adapter.payload_to_event("1", "issues", event_path.read_bytes())
assert isinstance(event, IssuesOpened)
event.payload.issue.title = "Bot: test"

ctx.should_call_api(
"rest.apps.async_get_repo_installation",
Expand All @@ -480,16 +457,6 @@ async def test_process_publish_check_not_pass(
{"owner": "he0119", "repo": "action-test", "issue_number": 80},
mock_issues_resp,
)
ctx.should_call_api(
"rest.issues.async_add_labels",
{
"owner": "he0119",
"repo": "action-test",
"issue_number": 80,
"labels": ["Bot"],
},
True,
)
# 检查是否需要跳过插件测试
ctx.should_call_api(
"rest.issues.async_list_comments",
Expand Down Expand Up @@ -622,7 +589,7 @@ async def test_not_publish_issue(
) -> None:
"""测试议题与发布无关
议题的标题不以 "Bot/Adapter/Plugin" 开头
议题的标签不是 "Bot/Adapter/Plugin"
"""
from src.plugins.publish import publish_check_matcher

Expand All @@ -641,7 +608,7 @@ async def test_not_publish_issue(
event_path = Path(__file__).parent.parent / "events" / "issue-open.json"
event = Adapter.payload_to_event("1", "issues", event_path.read_bytes())
assert isinstance(event, IssuesOpened)
event.payload.issue.title = "test"
event.payload.issue.labels = []

ctx.receive_event(bot, event)

Expand Down Expand Up @@ -734,7 +701,6 @@ async def test_skip_plugin_check(
event_path = Path(__file__).parent.parent / "events" / "issue-comment-skip.json"
event = Adapter.payload_to_event("1", "issue_comment", event_path.read_bytes())
assert isinstance(event, IssueCommentCreated)
event.payload.issue.title = "Plugin: project_link"

ctx.should_call_api(
"rest.apps.async_get_repo_installation",
Expand All @@ -746,16 +712,6 @@ async def test_skip_plugin_check(
{"owner": "he0119", "repo": "action-test", "issue_number": 70},
mock_issues_resp,
)
ctx.should_call_api(
"rest.issues.async_add_labels",
{
"owner": "he0119",
"repo": "action-test",
"issue_number": 70,
"labels": ["Plugin"],
},
True,
)
ctx.should_call_api(
"rest.issues.async_list_comments",
{"owner": "he0119", "repo": "action-test", "issue_number": 70},
Expand Down

0 comments on commit e6367e5

Please sign in to comment.