Skip to content

Commit 33331db

Browse files
Copilotcommjoen
andcommitted
Fix pre-commit formatting issues and enhance pre-commit setup
- Remove trailing whitespace from .github/copilot-instructions.md - Add missing newline at end of file - Create setup script at .github/scripts/setup-precommit.sh - Update CONTRIBUTING.md with comprehensive pre-commit guide - Ensure all pre-commit checks pass before committing Co-authored-by: commjoen <[email protected]>
1 parent 6badb8c commit 33331db

File tree

3 files changed

+86
-16
lines changed

3 files changed

+86
-16
lines changed

.github/copilot-instructions.md

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -47,24 +47,24 @@ wrongsecrets/
4747
```java
4848
@Component
4949
public class Challenge[Number] extends FixedAnswerChallenge {
50-
50+
5151
private final RuntimeEnvironment runtimeEnvironment;
52-
52+
5353
public Challenge[Number](RuntimeEnvironment runtimeEnvironment) {
5454
this.runtimeEnvironment = runtimeEnvironment;
5555
}
56-
56+
5757
@Override
5858
public String getAnswer() {
5959
// Return the secret that users need to find
6060
return "the-secret-value";
6161
}
62-
62+
6363
@Override
6464
public boolean canRunInCTFMode() {
6565
return true; // Set to false if challenge can't run in CTF mode
6666
}
67-
67+
6868
@Override
6969
public RuntimeEnvironment.Environment supportedRuntimeEnvironments() {
7070
return RuntimeEnvironment.Environment.DOCKER; // or ALL, K8S, etc.
@@ -77,17 +77,17 @@ public class Challenge[Number] extends FixedAnswerChallenge {
7777
```java
7878
@Component
7979
public class Challenge[Number] implements Challenge {
80-
80+
8181
@Override
8282
public Spoiler spoiler() {
8383
return new Spoiler(calculateAnswer());
8484
}
85-
85+
8686
@Override
8787
public boolean answerCorrect(String answer) {
8888
return Objects.equals(calculateAnswer(), answer);
8989
}
90-
90+
9191
private String calculateAnswer() {
9292
// Complex logic here
9393
}
@@ -101,25 +101,25 @@ public class Challenge[Number] implements Challenge {
101101
```java
102102
@ExtendWith(MockitoExtension.class)
103103
class Challenge[Number]Test {
104-
104+
105105
@Mock
106106
private RuntimeEnvironment runtimeEnvironment;
107-
107+
108108
@InjectMocks
109109
private Challenge[Number] challenge;
110-
110+
111111
@Test
112112
void answerCorrect() {
113113
// Test the correct answer
114114
assertTrue(challenge.answerCorrect(challenge.spoiler().solution()));
115115
}
116-
116+
117117
@Test
118118
void answerIncorrect() {
119119
// Test incorrect answers
120120
assertFalse(challenge.answerCorrect("wrong-answer"));
121121
}
122-
122+
123123
@Test
124124
void canRunInCTFMode() {
125125
// Test CTF mode support
@@ -133,7 +133,7 @@ class Challenge[Number]Test {
133133
### Java Conventions
134134

135135
- **Package naming**: Follow existing structure under `org.owasp.wrongsecrets`
136-
- **Class naming**:
136+
- **Class naming**:
137137
- Challenges: `Challenge[Number]` (e.g., `Challenge1`, `Challenge42`)
138138
- Tests: `Challenge[Number]Test`
139139
- **Formatting**: Use standard Spring Boot/Google Java style
@@ -266,4 +266,4 @@ Common environment variables used in challenges:
266266
- **GitHub Issues**: Search existing issues and discussions
267267
- **OWASP Slack**: Join #project-wrongsecrets channel
268268

269-
Remember: This is an educational project teaching security through intentionally vulnerable examples. Balance realistic vulnerabilities with clear learning outcomes while keeping the framework itself secure and maintainable.
269+
Remember: This is an educational project teaching security through intentionally vulnerable examples. Balance realistic vulnerabilities with clear learning outcomes while keeping the framework itself secure and maintainable.

.github/scripts/setup-precommit.sh

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#!/bin/bash
2+
3+
# Setup pre-commit hooks for OWASP WrongSecrets contributors
4+
# This script ensures that all pre-commit checks are installed and configured
5+
6+
set -e
7+
8+
echo "🔧 Setting up pre-commit hooks for OWASP WrongSecrets..."
9+
10+
# Check if pre-commit is installed
11+
if ! command -v pre-commit &> /dev/null; then
12+
echo "📦 Installing pre-commit..."
13+
python3 -m pip install --user pre-commit
14+
fi
15+
16+
# Install pre-commit hooks
17+
echo "⚡ Installing pre-commit hooks..."
18+
pre-commit install
19+
20+
# Install commit-msg hook for commitlint
21+
echo "📝 Installing commit-msg hook..."
22+
pre-commit install --hook-type commit-msg
23+
24+
echo "✅ Pre-commit setup complete!"
25+
echo ""
26+
echo "📋 Available commands:"
27+
echo " pre-commit run --all-files # Run all hooks on all files"
28+
echo " pre-commit run <hook-name> # Run specific hook"
29+
echo " pre-commit autoupdate # Update hook versions"
30+
echo ""
31+
echo "💡 Pre-commit will now run automatically on every commit!"
32+
echo " To bypass pre-commit checks (not recommended): git commit --no-verify"

CONTRIBUTING.md

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,10 @@ cd wrongsecrets
3232
./mvnw clean compile
3333
./mvnw test -Dtest=ChallengesControllerTest
3434

35-
# 3. Run the application locally
35+
# 3. Setup pre-commit hooks (recommended)
36+
./.github/scripts/setup-precommit.sh
37+
38+
# 4. Run the application locally
3639
./mvnw spring-boot:run
3740
# Visit http://localhost:8080 to see the app running
3841
```
@@ -108,6 +111,41 @@ The minimum requirements for code contributions are:
108111

109112
And please note that this project has *three months* implementation windows. So once you've been assigned to a task/issue, try to make your PR accepted within this period.
110113

114+
### 🔧 Pre-commit Hooks Setup
115+
116+
**Important:** Always run pre-commit checks before submitting your PR to avoid CI failures.
117+
118+
#### Quick Setup
119+
```bash
120+
# Automated setup (recommended)
121+
./.github/scripts/setup-precommit.sh
122+
123+
# Manual setup
124+
pip install pre-commit
125+
pre-commit install
126+
pre-commit install --hook-type commit-msg
127+
```
128+
129+
#### Running Checks
130+
```bash
131+
# Check all files
132+
pre-commit run --all-files
133+
134+
# Check specific file
135+
pre-commit run --files path/to/your/file.md
136+
137+
# Check what will run on next commit
138+
pre-commit run
139+
```
140+
141+
#### Common Issues & Fixes
142+
- **Trailing whitespace**: Automatically fixed by pre-commit
143+
- **Missing newlines**: Automatically fixed by pre-commit
144+
- **Java formatting**: Run `./mvnw spotless:apply`
145+
- **Commit message format**: Follow [Conventional Commits](https://www.conventionalcommits.org/)
146+
147+
💡 **Tip**: Pre-commit hooks will run automatically on every commit after installation!
148+
111149
Additionally, the following guidelines can help:
112150

113151
### Keep your pull requests limited to a single issue

0 commit comments

Comments
 (0)