Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions .github/workflows/ping_reviewers.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: Ping Reviewers
on:
schedule:
- cron: "0/15 * * * *"
workflow_dispatch:

concurrency:
group: ping
cancel-in-progress: true

jobs:
ping:
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v2
- name: Ping reviewers
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
set -eux
python tests/scripts/ping_reviewers.py --wait-time-minutes 1440
8 changes: 8 additions & 0 deletions docs/contribute/code_review.rst
Original file line number Diff line number Diff line change
Expand Up @@ -220,3 +220,11 @@ To do so -- please click on changes tab in the pull request, then select approve
or comment on the code and click request changes.
Code owner can decide if the code can be merged in case by case if some of the reviewers
did not respond in time(e.g. a week) and existing reviews are sufficient.

Reviewers
~~~~~~~~~
Reviewers should strive to leave timely feedback on pull requests for which their
review was requested. Reviewing code is an important part of the project's health
and should be considered a regular responsibility for contributors. Automated
tooling helps out in this regard, as PRs with no activity for a set amount of
time will get a bot comment pinging the relevant parties.
134 changes: 133 additions & 1 deletion tests/python/unittest/test_ci.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ def test(commands, should_skip, pr_title, why):
git.run(*command)
pr_number = "1234"
proc = subprocess.run(
[str(skip_ci_script), "--pr", pr_number, "--pr-title", pr_title], cwd=git.cwd # dir
[str(skip_ci_script), "--pr", pr_number, "--pr-title", pr_title], cwd=git.cwd
)
expected = 0 if should_skip else 1
assert proc.returncode == expected, why
Expand Down Expand Up @@ -161,5 +161,137 @@ def test(commands, should_skip, pr_title, why):
)


def test_ping_reviewers(tmpdir_factory):
reviewers_script = REPO_ROOT / "tests" / "scripts" / "ping_reviewers.py"

def run(pr, check):
git = TempGit(tmpdir_factory.mktemp("tmp_git_dir"))
# Jenkins git is too old and doesn't have 'git init --initial-branch'
git.run("init")
git.run("checkout", "-b", "main")
git.run("remote", "add", "origin", "https://github.com/apache/tvm.git")

data = {
"data": {
"repository": {
"pullRequests": {
"nodes": [pr],
"edges": [],
}
}
}
}
proc = subprocess.run(
[
str(reviewers_script),
"--dry-run",
"--wait-time-minutes",
"1",
"--cutoff-pr-number",
"5",
"--allowlist",
"user",
"--pr-json",
json.dumps(data),
"--now",
"2022-01-26T17:54:19Z",
],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
encoding="utf-8",
cwd=git.cwd,
)
if proc.returncode != 0:
raise RuntimeError(f"Process failed:\nstdout:\n{proc.stdout}\n\nstderr:\n{proc.stderr}")

assert check in proc.stdout

run(
{
"isDraft": True,
},
"Checking 0 PRs",
)

run(
{
"isDraft": False,
"number": 2,
},
"Checking 0 PRs",
)

run(
{
"number": 123,
"url": "https://github.com/apache/tvm/pull/123",
"body": "cc @someone",
"isDraft": False,
"author": {"login": "user"},
"reviews": {"nodes": []},
"publishedAt": "2022-01-18T17:54:19Z",
"comments": {"nodes": []},
},
"Pinging reviewers ['someone'] on https://github.com/apache/tvm/pull/123",
)

# Check allowlist functionality
run(
{
"number": 123,
"url": "https://github.com/apache/tvm/pull/123",
"body": "cc @someone",
"isDraft": False,
"author": {"login": "user2"},
"reviews": {"nodes": []},
"publishedAt": "2022-01-18T17:54:19Z",
"comments": {
"nodes": [
{"updatedAt": "2022-01-19T17:54:19Z", "bodyText": "abc"},
]
},
},
"Checking 0 PRs",
)

# Old comment, ping
run(
{
"number": 123,
"url": "https://github.com/apache/tvm/pull/123",
"body": "cc @someone",
"isDraft": False,
"author": {"login": "user"},
"reviews": {"nodes": []},
"publishedAt": "2022-01-18T17:54:19Z",
"comments": {
"nodes": [
{"updatedAt": "2022-01-19T17:54:19Z", "bodyText": "abc"},
]
},
},
"Pinging reviewers ['someone'] on https://github.com/apache/tvm/pull/123",
)

# New comment, don't ping
run(
{
"number": 123,
"url": "https://github.com/apache/tvm/pull/123",
"body": "cc @someone",
"isDraft": False,
"author": {"login": "user"},
"reviews": {"nodes": []},
"publishedAt": "2022-01-18T17:54:19Z",
"comments": {
"nodes": [
{"updatedAt": "2022-01-27T17:54:19Z", "bodyText": "abc"},
]
},
},
"Not pinging PR 123",
)


if __name__ == "__main__":
sys.exit(pytest.main([__file__] + sys.argv[1:]))
Loading