Skip to content

Commit e62e7dc

Browse files
committed
chore: Add deps/deps-dev to commit lint rules
2 parents 88b74e0 + 58744fe commit e62e7dc

10 files changed

Lines changed: 173 additions & 143 deletions

File tree

.github/workflows/notify_slack.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ jobs:
1414
steps:
1515
- name: Send issue notification to Slack
1616
if: github.event_name == 'issues'
17-
uses: slackapi/slack-github-action@v2.1.1
17+
uses: slackapi/slack-github-action@v3.0.1
1818
with:
1919
webhook: ${{ secrets.SLACK_WEBHOOK_URL_ISSUE }}
2020
webhook-type: incoming-webhook
@@ -27,7 +27,7 @@ jobs:
2727
2828
- name: Send pull request notification to Slack
2929
if: github.event_name == 'pull_request_target'
30-
uses: slackapi/slack-github-action@v2.1.1
30+
uses: slackapi/slack-github-action@v3.0.1
3131
with:
3232
webhook: ${{ secrets.SLACK_WEBHOOK_URL_PR }}
3333
webhook-type: incoming-webhook

.github/workflows/pypi-publish.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ jobs:
6060

6161
steps:
6262
- name: Retrieve release distributions
63-
uses: actions/download-artifact@70fc10c6e5e1ce46ad2ea6f2b72d43f7d47b13c3 # v8.0.0
63+
uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
6464
with:
6565
name: release-dists
6666
path: dist/

.github/workflows/scorecard.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,6 @@ jobs:
7575
# Upload the results to GitHub's code scanning dashboard (optional).
7676
# Commenting out will disable upload of results to your repo's Code Scanning dashboard
7777
- name: "Upload to code-scanning"
78-
uses: github/codeql-action/upload-sarif@89a39a4e59826350b863aa6b6252a07ad50cf83e # v4.32.4
78+
uses: github/codeql-action/upload-sarif@c10b8064de6f491fea524254123dbe5e09572f13 # v4.35.1
7979
with:
8080
sarif_file: results.sarif

.github/workflows/test-parser.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@ on:
44
pull_request:
55
paths:
66
- 'ops/parse_sdk_branch.py'
7-
- 'ops/__tests__/**'
7+
- 'ops/tests/**'
88
push:
99
branches: [ main ]
1010
paths:
1111
- 'ops/parse_sdk_branch.py'
12-
- 'ops/__tests__/**'
12+
- 'ops/tests/**'
1313

1414
permissions:
1515
contents: read
@@ -21,4 +21,4 @@ jobs:
2121
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
2222

2323
- name: Run parser tests
24-
run: python ops/__tests__/test_parse_sdk_branch.py
24+
run: python ops/tests/test_parse_sdk_branch.py

ops/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+

ops/__tests__/test_lintcommit.py

Lines changed: 0 additions & 120 deletions
This file was deleted.

ops/lintcommit.py

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,10 @@
44
#
55
# To run tests:
66
#
7-
# python -m pytest ops/__tests__/test_lintcommit.py
7+
# python -m pytest ops/tests/test_lintcommit.py
88

99
from __future__ import annotations
1010

11-
import os
1211
import re
1312
import sys
1413

@@ -79,6 +78,9 @@ def validate_subject(subject_line: str) -> str | None:
7978
if subject.endswith("."):
8079
return "subject must not end with a period"
8180

81+
if subject != subject.lower():
82+
return "subject must be lowercase"
83+
8284
return None
8385

8486

@@ -110,28 +112,18 @@ def validate_message(message: str) -> tuple[str | None, list[str]]:
110112

111113
warnings: list[str] = []
112114
# Check for blank line between subject and body
115+
body_start: int = 2
113116
if len(lines) > 1 and lines[1].strip() != "":
114117
warnings.append("missing blank line between subject and body")
118+
body_start = 1
115119

116-
if len(lines) > 2:
117-
body: str = "\n".join(lines[2:])
120+
if len(lines) > body_start:
121+
body: str = "\n".join(lines[body_start:])
118122
warnings.extend(validate_body(body))
119123

120124
return (error, warnings)
121125

122126

123-
def _format_error(title: str, reason: str) -> str:
124-
valid_types: str = ", ".join(sorted(TYPES))
125-
return f"""Invalid commit message: `{title}`
126-
127-
* Problem: {reason}
128-
* Expected format: `type(scope): subject...`
129-
* type: one of ({valid_types})
130-
* scope: optional, lowercase, <{MAX_SCOPE_LENGTH} chars
131-
* subject: must be <{MAX_SUBJECT_LENGTH} chars
132-
"""
133-
134-
135127
def run_local() -> None:
136128
"""Validate local commit messages ahead of origin/main.
137129

ops/tests/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+

ops/tests/test_lintcommit.py

Lines changed: 156 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,156 @@
1+
#!/usr/bin/env python3
2+
3+
from ops.lintcommit import validate_message, validate_subject
4+
5+
6+
# region validate_subject: valid subjects
7+
8+
9+
def test_valid_feat() -> None:
10+
assert validate_subject("feat: add new feature") is None
11+
12+
13+
def test_valid_fix() -> None:
14+
assert validate_subject("fix: resolve issue") is None
15+
16+
17+
def test_valid_fix_with_scope() -> None:
18+
assert validate_subject("fix(sdk): resolve issue") is None
19+
20+
21+
def test_valid_build() -> None:
22+
assert validate_subject("build: update build process") is None
23+
24+
25+
def test_valid_chore() -> None:
26+
assert validate_subject("chore: update dependencies") is None
27+
28+
29+
def test_valid_ci() -> None:
30+
assert validate_subject("ci: configure ci/cd") is None
31+
32+
33+
def test_valid_deps() -> None:
34+
assert validate_subject("deps: bump aws-sdk group with 5 updates") is None
35+
36+
37+
def test_valid_docs() -> None:
38+
assert validate_subject("docs: update documentation") is None
39+
40+
41+
def test_valid_feat_with_scope() -> None:
42+
assert validate_subject("feat(sdk): add new feature") is None
43+
44+
45+
def test_valid_feat_scope_bar() -> None:
46+
assert validate_subject("feat(sdk): bar") is None
47+
48+
49+
def test_valid_feat_foo() -> None:
50+
assert validate_subject("feat: foo") is None
51+
52+
53+
def test_valid_fix_foo() -> None:
54+
assert validate_subject("fix: foo") is None
55+
56+
57+
# region validate_subject: invalid subjects
58+
59+
60+
def test_invalid_type() -> None:
61+
assert validate_subject("config: foo") == 'invalid type "config"'
62+
63+
64+
def test_missing_colon() -> None:
65+
assert validate_subject("invalid title") == "missing colon (:) char"
66+
67+
68+
def test_period_at_end() -> None:
69+
assert validate_subject("feat: add thing.") == "subject must not end with a period"
70+
71+
72+
def test_empty_subject() -> None:
73+
assert validate_subject("feat: ") == "empty subject"
74+
75+
76+
def test_subject_too_long() -> None:
77+
long_subject: str = "feat: " + "a" * 51
78+
result = validate_subject(long_subject)
79+
assert result is not None
80+
assert "invalid subject" in result
81+
82+
83+
def test_type_with_whitespace() -> None:
84+
assert validate_subject("fe at: foo") == 'type contains whitespace: "fe at"'
85+
86+
87+
def test_scope_not_closed() -> None:
88+
assert validate_subject("feat(sdk: foo") == "must be formatted like type(scope):"
89+
90+
91+
def test_scope_too_long() -> None:
92+
long_scope: str = "a" * 31
93+
result = validate_subject(f"feat({long_scope}): foo")
94+
assert result is not None
95+
assert "invalid scope" in result
96+
97+
98+
def test_scope_uppercase() -> None:
99+
result = validate_subject("feat(SDK): foo")
100+
assert result is not None
101+
assert "invalid scope" in result
102+
103+
104+
def test_subject_uppercase() -> None:
105+
assert (
106+
validate_subject("feat: Add new feature")
107+
== "subject must be lowercase"
108+
)
109+
110+
111+
def test_subject_uppercase_acronym_rejected() -> None:
112+
assert validate_subject("ci: configure CI/CD") == "subject must be lowercase"
113+
114+
115+
# region validate_message
116+
117+
118+
def test_valid_subject_only() -> None:
119+
error, warnings = validate_message("feat: add thing")
120+
assert error is None
121+
assert warnings == []
122+
123+
124+
def test_valid_with_body() -> None:
125+
error, warnings = validate_message("feat: add thing\n\nThis is the body.")
126+
assert error is None
127+
assert warnings == []
128+
129+
130+
def test_missing_blank_line() -> None:
131+
_, warnings = validate_message("feat: add thing\nNo blank line.")
132+
assert "missing blank line between subject and body" in warnings
133+
134+
135+
def test_missing_blank_line_body_still_checked() -> None:
136+
_, warnings = validate_message("feat: add thing\n" + "x" * 80)
137+
assert "missing blank line between subject and body" in warnings
138+
assert any("exceeds 72 chars" in w for w in warnings), (
139+
"body line length should be checked even without blank line"
140+
)
141+
142+
143+
def test_long_body_line() -> None:
144+
_, warnings = validate_message("feat: add thing\n\n" + "x" * 80)
145+
assert len(warnings) == 1
146+
assert "exceeds 72 chars" in warnings[0]
147+
148+
149+
def test_empty_message() -> None:
150+
error, _ = validate_message("")
151+
assert error == "empty commit message"
152+
153+
154+
def test_invalid_subject_in_message() -> None:
155+
error, _ = validate_message("invalid title")
156+
assert error == "missing colon (:) char"

0 commit comments

Comments
 (0)