diff --git a/CHANGELOG.md b/CHANGELOG.md index 0a84cf11..7a30fc46 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/src/plugins/publish/__init__.py b/src/plugins/publish/__init__.py index 5c888bcb..51a34c98 100644 --- a/src/plugins/publish/__init__.py +++ b/src/plugins/publish/__init__.py @@ -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 ( @@ -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 @@ -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 执行时可能已经被关闭 @@ -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 diff --git a/tests/publish/events/issue-open.json b/tests/publish/events/issue-open.json index db985f9e..0d0588da 100644 --- a/tests/publish/events/issue-open.json +++ b/tests/publish/events/issue-open.json @@ -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, diff --git a/tests/publish/process/test_publish_check.py b/tests/publish/process/test_publish_check.py index 41c2464e..3d02448f 100644 --- a/tests/publish/process/test_publish_check.py +++ b/tests/publish/process/test_publish_check.py @@ -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", @@ -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}, @@ -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", @@ -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}, @@ -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", @@ -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", @@ -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 @@ -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) @@ -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", @@ -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},