Skip to content

Commit 62fd6ee

Browse files
author
“Kirti
committed
Fix PR automation autoreview
1 parent 3c0983a commit 62fd6ee

5 files changed

Lines changed: 238 additions & 9 deletions

File tree

.github/workflows/ai-code-review.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,12 +67,12 @@ jobs:
6767
model: 'gpt-3.5-turbo',
6868
messages: [{
6969
role: 'system',
70-
content: 'You are an expert code reviewer. Review the code for: bugs, security issues, performance problems, best practices, and code quality. Be concise and specific. Focus on important issues only.'
70+
content: 'You are an expert code reviewer. For each issue found, provide: 1) Issue description, 2) Why it matters, 3) Specific code fix with BEFORE and AFTER examples. Format each issue clearly with the file line reference if possible. Focus on: bugs, security, performance, best practices, accessibility, and React-specific issues.'
7171
}, {
7272
role: 'user',
73-
content: 'Review this ' + file + ':\n\n```javascript\n' + content.slice(0, 3000) + '\n```'
73+
content: 'Review this code from ' + file + ' and provide specific fixes:\n\n```javascript\n' + content.slice(0, 3000) + '\n```\n\nFor each issue, show:\n- Issue: [description]\n- Why: [explanation]\n- Fix: [before/after code example]'
7474
}],
75-
max_tokens: 500,
75+
max_tokens: 1000,
7676
temperature: 0.3
7777
});
7878

src/App.js

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,33 @@
11
import React from 'react';
2-
import logo from './logo.svg';
32
import './App.css';
43
import UserProfile from './components/UserProfile';
4+
import UserList from './components/UserList';
5+
import TodoForm from './components/TodoForm';
6+
import ProductCard from './components/ProductCard';
57

68
function App() {
79
return (
810
<div className="App">
911
<header className="App-header">
10-
<img src={logo} className="App-logo" alt="logo" />
1112
<h1>GitHub Actions Practice</h1>
12-
<p>
13-
Testing AI Code Review and CI/CD workflows
14-
</p>
13+
<p>Testing AI Code Review with Multiple Components</p>
1514

16-
{/* UserProfile component with some props */}
1715
<UserProfile
1816
name="John Doe"
1917
email="john@example.com"
2018
avatar="https://via.placeholder.com/150"
2119
/>
20+
21+
<UserList />
22+
23+
<TodoForm />
24+
25+
<ProductCard
26+
name="Sample Product"
27+
price={99.99}
28+
imageUrl="https://via.placeholder.com/300"
29+
externalLink="https://example.com"
30+
/>
2231
</header>
2332
</div>
2433
);

src/components/ProductCard.js

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
import { useState, useEffect } from 'react';
2+
3+
// INTENTIONAL MISTAKES:
4+
// 1. React not imported (needed for JSX)
5+
// 2. Prop drilling
6+
// 3. No memoization
7+
// 4. Expensive calculations in render
8+
// 5. Security issues with external URLs
9+
// 6. Missing alt attributes
10+
// 7. No error boundaries
11+
// 8. Inefficient event handlers
12+
// 9. Missing cleanup
13+
// 10. Password in code
14+
15+
const API_KEY = 'sk-1234567890abcdef'; // Hardcoded secret!
16+
17+
function ProductCard(props) {
18+
const [price, setPrice] = useState(props.price);
19+
const [quantity, setQuantity] = useState(1);
20+
21+
// Expensive calculation on every render
22+
const discount = calculateComplexDiscount(price, quantity);
23+
24+
// No cleanup for interval
25+
useEffect(() => {
26+
const interval = setInterval(() => {
27+
// Fetching on interval without cleanup
28+
fetch(`https://api.example.com/price?key=${API_KEY}`)
29+
.then(r => r.json())
30+
.then(data => setPrice(data.price));
31+
}, 1000);
32+
// Missing return cleanup
33+
}, []);
34+
35+
// Inefficient - recreated on every render
36+
const handleQuantityChange = (delta) => {
37+
setQuantity(quantity + delta);
38+
};
39+
40+
// Expensive calculation not memoized
41+
const total = price * quantity - discount;
42+
43+
return (
44+
<div className="product-card">
45+
{/* Security: No validation of external URL */}
46+
<img src={props.imageUrl} /> {/* Missing alt */}
47+
48+
<h2>{props.name}</h2>
49+
50+
{/* Inline styles - should use CSS */}
51+
<p style={{ color: 'red', fontSize: '20px' }}>
52+
${total.toFixed(2)}
53+
</p>
54+
55+
{/* Inline arrow functions - performance issue */}
56+
<button onClick={() => handleQuantityChange(-1)}>-</button>
57+
<span>{quantity}</span>
58+
<button onClick={() => handleQuantityChange(1)}>+</button>
59+
60+
{/* External link without security */}
61+
<a href={props.externalLink} target="_blank">
62+
Learn More
63+
</a>
64+
65+
{/* Direct DOM manipulation - anti-pattern */}
66+
<button onClick={() => {
67+
document.getElementById('cart').innerHTML = 'Added!';
68+
}}>
69+
Add to Cart
70+
</button>
71+
72+
<div id="cart"></div>
73+
</div>
74+
);
75+
}
76+
77+
// Missing memoization
78+
function calculateComplexDiscount(price, quantity) {
79+
// Simulate expensive calculation
80+
let result = 0;
81+
for (let i = 0; i < 10000; i++) {
82+
result += Math.sqrt(price * quantity);
83+
}
84+
return result / 10000;
85+
}
86+
87+
// No PropTypes validation
88+
export default ProductCard;

src/components/TodoForm.js

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
import React from 'react';
2+
3+
// INTENTIONAL MISTAKES:
4+
// 1. No useState import
5+
// 2. Uncontrolled to controlled component issue
6+
// 3. No form validation
7+
// 4. Security: XSS vulnerability
8+
// 5. No accessibility labels
9+
// 6. Missing preventDefault
10+
// 7. Props drilling instead of context
11+
// 8. Async state updates not handled
12+
// 9. No error boundaries
13+
// 10. Hardcoded values
14+
15+
class TodoForm extends React.Component {
16+
constructor(props) {
17+
super(props);
18+
// Uncontrolled component
19+
this.state = {
20+
todo: undefined, // Should be empty string
21+
todos: [],
22+
count: 0
23+
};
24+
}
25+
26+
handleSubmit(e) {
27+
// Missing e.preventDefault()
28+
29+
// XSS vulnerability - dangerouslySetInnerHTML
30+
const newTodo = {
31+
id: Math.random(), // Should use proper ID generation
32+
text: this.state.todo,
33+
html: this.state.todo // Will be rendered as HTML
34+
};
35+
36+
// Async state update issue
37+
this.setState({
38+
todos: [...this.state.todos, newTodo],
39+
count: this.state.count + 1 // Race condition
40+
});
41+
42+
this.setState({
43+
count: this.state.count + 1 // Using stale state
44+
});
45+
}
46+
47+
render() {
48+
return (
49+
<form onSubmit={this.handleSubmit}>
50+
{/* No accessibility labels */}
51+
<input
52+
type="text"
53+
value={this.state.todo}
54+
onChange={(e) => this.setState({ todo: e.target.value })}
55+
/>
56+
57+
{/* Inline function - performance issue */}
58+
<button onClick={() => this.handleSubmit()}>Add</button>
59+
60+
{/* XSS vulnerability */}
61+
{this.state.todos.map((todo, index) => (
62+
<div
63+
key={index} // Using index as key
64+
dangerouslySetInnerHTML={{ __html: todo.html }}
65+
/>
66+
))}
67+
68+
{/* Not using setState properly */}
69+
<p onClick={() => this.state.count++}>
70+
Count: {this.state.count}
71+
</p>
72+
</form>
73+
);
74+
}
75+
}
76+
77+
export default TodoForm;

src/components/UserList.js

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
import React, { useState } from 'react';
2+
3+
// INTENTIONAL MISTAKES:
4+
// 1. useEffect not imported
5+
// 2. Memory leak - no cleanup
6+
// 3. No error handling
7+
// 4. No loading state
8+
// 5. Inefficient re-renders
9+
// 6. Missing key in map
10+
// 7. Inline function in map
11+
// 8. Direct state mutation
12+
// 9. No PropTypes
13+
// 10. Missing dependency in useEffect
14+
15+
function UserList() {
16+
const [users, setUsers] = useState([]);
17+
const [filter, setFilter] = useState('');
18+
19+
// Missing useEffect import - will cause error
20+
useEffect(() => {
21+
// No loading state
22+
fetch('https://jsonplaceholder.typicode.com/users')
23+
.then(response => response.json())
24+
.then(data => {
25+
// Direct mutation instead of spreading
26+
users.push(...data);
27+
setUsers(users);
28+
});
29+
// No cleanup, no error handling
30+
}, []); // Missing filter dependency
31+
32+
// Inefficient - should use useMemo
33+
const filteredUsers = users.filter(user =>
34+
user.name.toLowerCase().includes(filter.toLowerCase())
35+
);
36+
37+
return (
38+
<div>
39+
<input
40+
value={filter}
41+
onChange={(e) => setFilter(e.target.value)}
42+
/>
43+
44+
{/* Missing key prop, inline function */}
45+
{filteredUsers.map(user => (
46+
<div onClick={() => console.log(user)}>
47+
<h3>{user.name}</h3>
48+
<p>{user.email}</p>
49+
</div>
50+
))}
51+
</div>
52+
);
53+
}
54+
55+
export default UserList;

0 commit comments

Comments
 (0)