Skip to content

Commit d0fc8d7

Browse files
committed
feat: init repo
1 parent a07adfc commit d0fc8d7

26 files changed

+1643
-0
lines changed
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# LeetCode Repository Rules
2+
3+
## Discussion Mode
4+
5+
- **Discussion Mode**: Prefix prompt with "D:" to enter read-only discussion mode
6+
- In discussion mode: NO code updates, only read files and provide analysis/suggestions
7+
- Always start responses with "[Discussion Mode]" header when in discussion mode
8+
- Never exit discussion mode automatically - only when user uses "XD:" prefix
9+
- If user seems to want code changes, remind them to use "XD:" to exit discussion mode
10+
- **Exit Discussion**: Use "XD:" prefix to exit discussion mode and resume normal operations
11+
12+
## Code Standards
13+
14+
- Use snake_case for Python method names (following Python convention)
15+
- Always include type hints for function parameters and return types
16+
- Add return statements to satisfy type checkers even if unreachable
17+
- Follow the project's linting rules (black, isort, ruff, mypy)
18+
19+
## Template Usage
20+
21+
- **When user copies LeetCode problem**: Use `leetcode/_template/` to structure the question
22+
- Copy template files to new question directory: `leetcode/{question_name}/`
23+
- Replace template placeholders with actual problem details:
24+
- `{method_name}` - snake_case method name (e.g., `two_sum`)
25+
- `{ClassName}` - PascalCase class name (e.g., `TwoSum`)
26+
- `{parameters}` - method parameters with types
27+
- `{return_type}` - return type annotation
28+
- Test case placeholders with actual examples
29+
- Always use the template structure for consistency
30+
31+
## File Structure
32+
33+
Each LeetCode problem should have:
34+
35+
- `README.md` - Problem description and examples
36+
- `solution.py` - Solution implementation
37+
- `tests.py` - Parametrized pytest tests with loguru logging
38+
- `__init__.py` - Empty file for Python package
39+
40+
## Testing
41+
42+
- Use `make test-question QUESTION=<question_name>` to run tests
43+
- Use `make test` to run all questions with coverage
44+
- Default question is set to `two_sum` in Makefile
45+
- Tests should cover all provided examples
46+
- Use loguru for beautiful logging in tests

.github/renovate.json5

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
$schema: "https://docs.renovatebot.com/renovate-schema.json",
3+
extends: ["config:recommended"],
4+
}

.github/workflows/cd.yml

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
name: cd
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
8+
permissions:
9+
contents: write
10+
issues: write
11+
pull-requests: write
12+
13+
jobs:
14+
versioning:
15+
name: versioning
16+
runs-on: ubuntu-latest
17+
outputs:
18+
new_release_version: ${{ steps.set-outputs.outputs.version }}
19+
new_release_published: ${{ steps.set-outputs.outputs.published }}
20+
steps:
21+
- name: Checkout
22+
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
23+
with:
24+
fetch-depth: 0
25+
26+
- name: Check existing release
27+
id: check-release
28+
run: |
29+
CURRENT_SHA=$(git rev-parse HEAD)
30+
EXISTING_TAG=$(git tag --points-at $CURRENT_SHA | grep '^v' | head -1)
31+
if [ -n "$EXISTING_TAG" ]; then
32+
echo "existing_tag=$EXISTING_TAG" >> $GITHUB_OUTPUT
33+
echo "existing_version=${EXISTING_TAG#v}" >> $GITHUB_OUTPUT
34+
echo "has_existing=true" >> $GITHUB_OUTPUT
35+
else
36+
echo "has_existing=false" >> $GITHUB_OUTPUT
37+
fi
38+
39+
- id: release
40+
name: Release
41+
if: steps.check-release.outputs.has_existing == 'false'
42+
uses: cycjimmy/semantic-release-action@16ca923e6ccbb50770c415a0ccd43709a8c5f7a4 # v4.2.2
43+
env:
44+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
45+
46+
- name: Set outputs
47+
id: set-outputs
48+
run: |
49+
if [ "${{ steps.check-release.outputs.has_existing }}" == "true" ]; then
50+
echo "version=${{ steps.check-release.outputs.existing_version }}" >> $GITHUB_OUTPUT
51+
echo "published=true" >> $GITHUB_OUTPUT
52+
echo "Using existing release: ${{ steps.check-release.outputs.existing_version }}"
53+
else
54+
echo "version=${{ steps.release.outputs.new_release_version }}" >> $GITHUB_OUTPUT
55+
echo "published=${{ steps.release.outputs.new_release_published }}" >> $GITHUB_OUTPUT
56+
echo "New release: ${{ steps.release.outputs.new_release_version }}"
57+
fi
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
name: ci
2+
3+
on:
4+
pull_request:
5+
types: [opened, synchronize, reopened]
6+
7+
jobs:
8+
pre-commit:
9+
runs-on: ubuntu-latest
10+
steps:
11+
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
12+
13+
- uses: actions/setup-python@a26af69be951a213d495a4c3e4e4022e16d87065 # v5.6.0
14+
with:
15+
python-version: "3.x"
16+
17+
- name: Install Poetry
18+
uses: snok/install-poetry@76e04a911780d5b312d89783f7b1cd627778900a # v1.4.1
19+
with:
20+
virtualenvs-create: true
21+
virtualenvs-in-project: true
22+
installer-parallel: true
23+
24+
- name: Load cached venv
25+
id: cached-poetry-dependencies
26+
uses: actions/cache@0400d5f644dc74513175e3cd8d07132dd4860809 # v4.2.4
27+
with:
28+
path: .venv
29+
key: venv-${{ runner.os }}-${{ steps.setup-python.outputs.python-version }}-${{ hashFiles('**/poetry.lock') }}
30+
31+
- name: Install dependencies
32+
run: poetry install --no-interaction --no-ansi
33+
34+
- name: Setup Node.js
35+
uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4.4.0
36+
with:
37+
node-version: "latest"
38+
39+
- name: Install Prettier
40+
run: npm install -g prettier
41+
42+
- uses: pre-commit/action@2c7b3805fd2a0fd8c1884dcaebf91fc102a13ecd # v3.0.1
43+
with:
44+
extra_args: --all-files

.github/workflows/ci-test.yml

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
name: ci
2+
3+
on:
4+
push:
5+
branches: [main]
6+
pull_request:
7+
branches: [main]
8+
9+
jobs:
10+
test:
11+
runs-on: ubuntu-latest
12+
13+
steps:
14+
- uses: actions/checkout@v4
15+
16+
- name: Set up Python
17+
uses: actions/setup-python@v5
18+
with:
19+
python-version: "3.13"
20+
21+
- name: Install Poetry
22+
uses: snok/install-poetry@v1
23+
with:
24+
virtualenvs-create: true
25+
virtualenvs-in-project: true
26+
installer-parallel: true
27+
28+
- name: Load cached venv
29+
id: cached-poetry-dependencies
30+
uses: actions/cache@v4
31+
with:
32+
path: .venv
33+
key: venv-${{ runner.os }}-${{ steps.setup-python.outputs.python-version }}-${{ hashFiles('**/poetry.lock') }}
34+
35+
- name: Install dependencies
36+
if: steps.cached-poetry-dependencies.outputs.cache-hit != 'true'
37+
run: poetry install --no-interaction --no-ansi
38+
39+
- name: Run tests
40+
run: make test

.github/workflows/security.yml

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
name: security
2+
on:
3+
push:
4+
workflow_dispatch:
5+
schedule:
6+
- cron: "0 4 * * *" # run once a day at 4 AM
7+
8+
jobs:
9+
trivy-scan:
10+
runs-on: ubuntu-latest
11+
12+
steps:
13+
- name: Checkout repository
14+
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
15+
16+
- name: Run Trivy dependency scan
17+
uses: aquasecurity/trivy-action@dc5a429b52fcf669ce959baa2c2dd26090d2a6c4 # v0.32.0
18+
with:
19+
scan-type: fs
20+
format: table
21+
exit-code: "1"
22+
vuln-type: "os,library"
23+
24+
gitleaks:
25+
name: gitleaks
26+
runs-on: ubuntu-latest
27+
28+
steps:
29+
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
30+
with:
31+
fetch-depth: 0
32+
33+
- uses: gitleaks/gitleaks-action@ff98106e4c7b2bc287b24eaf42907196329070c7 # v2.3.9
34+
env:
35+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
name: ci
2+
3+
on:
4+
pull_request:
5+
branches: [main]
6+
types: [opened, edited, synchronize, reopened]
7+
8+
permissions:
9+
pull-requests: read
10+
11+
jobs:
12+
semantic-pull-request:
13+
name: semantic-pull-request
14+
runs-on: ubuntu-latest
15+
steps:
16+
- uses: amannn/action-semantic-pull-request@48f256284bd46cdaab1048c3721360e808335d50 # v6.1.1
17+
name: Validate PR title
18+
env:
19+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

0 commit comments

Comments
 (0)