-
Notifications
You must be signed in to change notification settings - Fork 1.8k
[TRTLLM-6822][infra] Add PR-Checklist github action and modify PR template #6029
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
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
1635811
add checklist in pr template
venkywonka b833c3b
include action
venkywonka 2944a1e
use goggles_action for pr checklist enforcement
venkywonka 1c4fd92
run on pull_request_target
venkywonka 30f0a21
enforce existence of a checklist in pr
venkywonka 4fce2fd
reduce checking overhead
venkywonka 0f29718
use `on:pull_request` instead of `on:pull_request_target`
venkywonka d21348c
Refactor PR checklist workflow and add validation script
venkywonka fee1221
consolidate.
venkywonka dc1f9a3
add copyright, relocate script
venkywonka 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
#!/usr/bin/env python3 | ||
# SPDX-FileCopyrightText: Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. | ||
# SPDX-License-Identifier: Apache-2.0 | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
import os | ||
import re | ||
import sys | ||
from typing import List | ||
|
||
# Matches a Markdown checklist item in the PR body. | ||
# Expected format: "- [ ] Task description" or "* [x] Task description" | ||
# Group 1 captures the checkbox state: ' ' (unchecked), 'x' or 'X' (checked). | ||
# Group 2 captures the task content (the description of the checklist item). | ||
TASK_PATTERN = re.compile(r'^\s*[-*]\s+\[( |x|X)\]\s*(.*)') | ||
|
||
|
||
def find_all_tasks(pr_body: str) -> List[str]: | ||
"""Return list of all task list items (both resolved and unresolved).""" | ||
tasks: List[str] = [] | ||
for line in pr_body.splitlines(): | ||
match = TASK_PATTERN.match(line) | ||
if match: | ||
tasks.append(match.group(0).strip()) | ||
return tasks | ||
|
||
|
||
def find_unresolved_tasks(pr_body: str) -> List[str]: | ||
"""Return list of unresolved task list items. | ||
|
||
A task is considered resolved if it is checked (``[x]`` or ``[X]``) | ||
or if its text is struck through using ``~~`` markers. | ||
""" | ||
unresolved: List[str] = [] | ||
for line in pr_body.splitlines(): | ||
match = TASK_PATTERN.match(line) | ||
if not match: | ||
continue | ||
state, content = match.groups() | ||
if state.lower() == 'x': | ||
continue | ||
# Check if the entire content is struck through | ||
if content.strip().startswith('~~') and content.strip().endswith('~~'): | ||
continue | ||
unresolved.append(match.group(0).strip()) | ||
return unresolved | ||
|
||
|
||
def check_pr_checklist_section(pr_body: str) -> tuple[bool, str]: | ||
"""Check if the PR Checklist section exists with the required final checkbox. | ||
|
||
Returns: | ||
tuple: (is_valid, error_message) | ||
""" | ||
# Check if "## PR Checklist" header exists | ||
pr_checklist_pattern = re.compile(r'^##\s+PR\s+Checklist', | ||
re.IGNORECASE | re.MULTILINE) | ||
if not pr_checklist_pattern.search(pr_body): | ||
return False, "Missing '## PR Checklist' header. Please ensure you haven't removed the PR template section." | ||
|
||
# Check if the final checkbox exists (the one users must check) | ||
final_checkbox_pattern = re.compile( | ||
r'^\s*[-*]\s+\[( |x|X)\]\s+Please check this after reviewing the above items', | ||
re.MULTILINE) | ||
if not final_checkbox_pattern.search(pr_body): | ||
return False, "Missing the required final checkbox '- [ ] Please check this after reviewing the above items as appropriate for this PR.' Please ensure you haven't removed this from the PR template." | ||
|
||
return True, "" | ||
|
||
|
||
def main() -> None: | ||
pr_body = os.environ.get("PR_BODY", "") | ||
enforce_checklist = os.environ.get("ENFORCE_PR_HAS_CHECKLIST", | ||
"false").lower() == "true" | ||
|
||
# Always check for PR Checklist section when enforcement is enabled | ||
if enforce_checklist: | ||
is_valid, error_msg = check_pr_checklist_section(pr_body) | ||
if not is_valid: | ||
print(f"Error: {error_msg}") | ||
sys.exit(1) | ||
|
||
all_tasks = find_all_tasks(pr_body) | ||
unresolved = find_unresolved_tasks(pr_body) | ||
|
||
# Check if we need to enforce the presence of at least one checklist item | ||
if enforce_checklist and not all_tasks: | ||
print( | ||
"Error: PR body must contain at least one checklist item when ENFORCE_PR_HAS_CHECKLIST is enabled." | ||
) | ||
print( | ||
"Expected format: - [ ] Task description or * [ ] Task description") | ||
sys.exit(1) | ||
|
||
# If we have tasks, check if any are unresolved | ||
if unresolved: | ||
print("Unresolved checklist items found:") | ||
for item in unresolved: | ||
print(f"{item}") | ||
sys.exit(1) | ||
|
||
if all_tasks: | ||
print("All checklist items resolved.") | ||
else: | ||
print("No checklist items found in PR body.") | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
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
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.