-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcommit-agent.sh
More file actions
executable file
·54 lines (43 loc) · 1.46 KB
/
Copy pathcommit-agent.sh
File metadata and controls
executable file
·54 lines (43 loc) · 1.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#!/bin/bash
# CommitAgent verification and commit script
# This script ensures that all changes are valid before committing.
# It runs cargo fmt, cargo check, and cargo test.
# If all checks pass, it executes git commit with a co-author trailer.
set -e
# Colors for output
GREEN='\033[0;32m'
RED='\033[0;31m'
NC='\033[0m' # No Color
echo "Starting CommitAgent verification..."
# 1. Check if the code is well-formatted
echo "Running cargo fmt --all -- --check..."
if ! cargo fmt --all -- --check; then
echo -e "${RED}Error: Code is not well-formatted. Run 'cargo fmt --all' to fix.${NC}"
exit 1
fi
echo -e "${GREEN}Formatting check passed.${NC}"
# 2. Check if the code builds
echo "Running cargo check..."
if ! cargo check; then
echo -e "${RED}Error: Code does not build.${NC}"
exit 1
fi
echo -e "${GREEN}Build check passed.${NC}"
# 3. Run all tests
echo "Running cargo test..."
if ! cargo test; then
echo -e "${RED}Error: Some tests failed.${NC}"
exit 1
fi
echo -e "${GREEN}All tests passed.${NC}"
# 4. Perform git commit if all checks passed
if [ -z "$1" ]; then
echo -e "${RED}Error: No commit message provided.${NC}"
echo "Usage: $0 \"Your commit message\""
exit 1
fi
COMMIT_MSG="$1"
echo "All checks passed! Committing changes..."
# Using the co-author trailer as required by the guidelines
git commit -m "$COMMIT_MSG" --trailer "Co-authored-by: Junie <junie@jetbrains.com>"
echo -e "${GREEN}Changes committed successfully by CommitAgent!${NC}"