Skip to content

Commit 56ccd91

Browse files
authored
Merged to main
2 parents 0379c44 + 6ea2f3e commit 56ccd91

File tree

2 files changed

+74
-17
lines changed

2 files changed

+74
-17
lines changed

git-commit-push-script.sh

Lines changed: 50 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,40 +5,73 @@
55
#!/bin/bash
66
source ~/.bash_profile
77

8+
# Pre-warm the model (optional - keeps it loaded)
9+
ollama run mistral-commit "test" > /dev/null 2>&1 &
10+
811
# Stage all changes
912
git add -A
1013

1114
# Get the branch name
1215
base_branch=$(git rev-parse --abbrev-ref HEAD)
16+
echo "Current branch: $base_branch"
17+
18+
# Get default branch or main branch
19+
default_branch=$(git rev-parse --abbrev-ref origin/HEAD | sed 's@^origin/@@')
20+
echo "Default branch: $default_branch"
1321

1422
# Extract Jira ticket number from current directory
1523
ticket=$(echo $base_branch | grep -o -E '([A-Za-z]+-[0-9]{3,}|[A-Za-z]+-[0-9]{3,})')
1624

17-
# Get the git diff
18-
diff=$(git diff --cached)
25+
# Get the git diff comparing the current branch with the default branch
26+
diff=$(git diff origin/$default_branch)
27+
# echo "Git diff:\n\n$diff"
28+
29+
# # Default model (change if desired)
30+
# MODEL="mistral-commit"
31+
32+
# # Prepare the prompt
33+
# PROMPT="$diff"
34+
35+
# # Run the model and capture output
36+
# COMMIT_MSG=$(ollama run "$MODEL" "$PROMPT")
1937

20-
# Default model (change if desired)
21-
MODEL="mistral"
38+
# # If the commit message is empty, exit with an error
39+
# if [ -z "$COMMIT_MSG" ]; then
40+
# echo "Error: Commit message is empty. Please check the diff and try again."
41+
# exit 1
42+
# fi
2243

23-
# Prepare the prompt
24-
PROMPT=$(printf "You are an expert software engineer.\n\nYour job is to generate a concise, descriptive commit message from the following git diff.\nThe commit message MUST be no more than 72 characters in length - this is a strict requirement.\nOnly return the commit message itself without quotes, explanations or additional text.\nDon't include phrases like 'It appears you have', 'I see that you', or 'You seem to have', 'It looks like' or similar in your response.\nThe response should be factual and focused on the changes made.\n\nGit diff:\n%s" "$diff")
44+
# Stringify the diff
45+
diff=$(echo $diff | sed 's/\\/\\\\/g' | sed 's/"/\\"/g' | sed 's/\n/\\n/g')
2546

26-
# Run the model and capture output
27-
COMMIT_MSG=$(echo "$PROMPT" | ollama run "$MODEL")
47+
# Prepare the Gemini API request
48+
gemini_request='{"contents":[{"parts":[{"text": "Write a git commit message title (no more than 72 characters total) for the following git diff: '"$diff"' Do not include any other text in the repsonse."}]}]}'
2849

29-
# If the commit message is empty, exit with an error
30-
if [ -z "$COMMIT_MSG" ]; then
31-
echo "Error: Commit message is empty. Please check the diff and try again."
50+
# Get commit message from Gemini API
51+
commit_message=$(curl -s \
52+
-H 'Content-Type: application/json' \
53+
-d "$gemini_request" \
54+
-X POST "https://generativelanguage.googleapis.com/v1beta/models/gemini-1.5-flash-latest:generateContent?key=${GEMINI_API_KEY}" \
55+
| jq -r '.candidates[0].content.parts[0].text'
56+
)
57+
58+
# Clean up commit message formatting - remove #, ```, "", '', ()), and period . at the end of response
59+
commit_message=$(echo $commit_message | sed 's/#//g' | sed 's/```//g' | sed 's/Commit message title://g' | sed 's/Commit message summary://g' | sed 's/\.//g' | sed 's/\"//g' | sed "s/'//g" | sed 's/())//g' | sed 's/()//g' | sed 's/Commit message://g' | sed 's/Commit message title: //g' | sed 's/Commit message summary: //g' | sed 's/Commit message body: //g' | sed 's/Commit message body://g')
60+
61+
echo $commit_message
62+
63+
if [ -z "$commit_message" ]; then
64+
echo "Error: API request for commit message failed. Please try again."
3265
exit 1
3366
fi
3467

35-
# Clean up commit message formatting - remove #, ```, "", '', and period . at the end of response
36-
commit_message=$(echo $COMMIT_MSG | sed 's/#//g' | sed 's/```//g' | sed 's/Commit message title://g' | sed 's/Commit message summary://g' | sed 's/\.//g' | sed 's/\"//g' | sed "s/'//g")
68+
# # Clean up commit message formatting - remove #, ```, "", '', ()), and period . at the end of response
69+
# commit_message=$(echo $COMMIT_MSG | sed 's/#//g' | sed 's/```//g' | sed 's/Commit message title://g' | sed 's/Commit message summary://g' | sed 's/\.//g' | sed 's/\"//g' | sed "s/'//g" | sed 's/())//g' | sed 's/()//g' | sed 's/Commit message://g' | sed 's/Commit message title: //g' | sed 's/Commit message summary: //g' | sed 's/Commit message body: //g' | sed 's/Commit message body://g')
3770

38-
# If the commit message is longer than 72 characters, truncate at the last word boundary
39-
if [ ${#commit_message} -gt 72 ]; then
40-
commit_message=$(echo $commit_message | cut -d' ' -f1-18)
41-
fi
71+
# # If the commit message is longer than 72 characters, truncate at the last word boundary
72+
# if [ ${#commit_message} -gt 72 ]; then
73+
# commit_message=$(echo $commit_message | cut -d' ' -f1-18)
74+
# fi
4275

4376
# Echo the commit message
4477
echo $commit_message

sonarqube_query.sh

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#!/bin/bash
2+
3+
# Set your token and SonarQube URL
4+
SONAR_TOKEN="your-token-here"
5+
SONAR_URL="https://sonar.staging.twmlabs.com/sonarqube"
6+
7+
# Function to make API calls
8+
query_sonar() {
9+
local endpoint=$1
10+
curl -s -u "${SONAR_TOKEN}:" "${SONAR_URL}${endpoint}"
11+
}
12+
13+
# Example: Get issues
14+
echo "Getting issues..."
15+
query_sonar "/api/issues/search?ps=10&severities=BLOCKER,CRITICAL"
16+
17+
# Example: Get hotspots
18+
echo -e "\n\nGetting hotspots..."
19+
query_sonar "/api/hotspots/search?ps=10"
20+
21+
# Example: Get measures/metrics for a project
22+
echo -e "\n\nGetting metrics for projects..."
23+
query_sonar "/api/measures/search?metricKeys=bugs,vulnerabilities,code_smells,reliability_rating,security_rating,sqale_rating&ps=10"
24+

0 commit comments

Comments
 (0)