From 3889d16fa5696fef89cd473d38176c3db8efd39e Mon Sep 17 00:00:00 2001 From: "amazon-q-developer[bot]" <208079219+amazon-q-developer[bot]@users.noreply.github.com> Date: Sat, 10 May 2025 06:44:29 +0000 Subject: [PATCH 1/3] =?UTF-8?q?=F0=9F=9B=A0=EF=B8=8F=20Add=20trust-tools?= =?UTF-8?q?=20flags=20and=20non-interactive=20mode=20to=20git-qcommit?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Updated command flags for secure and automated operation --- git-qcommit | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/git-qcommit b/git-qcommit index d2e24a6..acbbc39 100644 --- a/git-qcommit +++ b/git-qcommit @@ -44,7 +44,14 @@ if ! git diff --cached --quiet; then TEMP_FILE=$(mktemp /tmp/git-qcommit-XXXXXX) # Generate commit message using Amazon Q and write to temporary file - echo -e "Based on the staged git changes, generate a descriptive git commit message and write it to $TEMP_FILE. Feel free to use appropriate gitmoji/emoji icons. Include what was changed and why. Don't include any markdown formatting or code blocks.\n\nPrompt: $PROMPT" | q chat -a + echo -e "Based on the staged git changes, generate a descriptive git commit message \ +and write it to $TEMP_FILE. Feel free to use appropriate gitmoji/emoji icons. \ +Include what was changed and why. Don't include any markdown formatting or code \ +blocks.\n\nPrompt: $PROMPT" | q chat -a \ + --no-interactive \ + --trust-tools=fs_read,fs_write,execute_bash,internal_command,thinking,\ +fetch___fetch,git___git_add,git___git_diff,git___git_diff_staged,\ +git___git_diff_unstaged,git___git_log,git___git_show,git___git_status # Check if the temporary file exists and has content if [ -s "$TEMP_FILE" ]; then From 22d1853e5b4486dab469738d7692ebdbdb0397c6 Mon Sep 17 00:00:00 2001 From: "amazon-q-developer[bot]" <208079219+amazon-q-developer[bot]@users.noreply.github.com> Date: Sat, 10 May 2025 07:59:40 +0000 Subject: [PATCH 2/3] refactor: extract trusted tools and initial prompt into constants Improves code maintainability by moving hardcoded values into dedicated variables. Separates the trusted tools list and chat prompt template into clearly defined constants. --- git-qcommit | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/git-qcommit b/git-qcommit index acbbc39..1a7d1db 100644 --- a/git-qcommit +++ b/git-qcommit @@ -9,6 +9,11 @@ set -e PROMPTS_FILE="$HOME/.commitprompts" +# Define trusted tools for Amazon Q +TRUSTED_TOOLS="fs_read,fs_write,execute_bash,git___git_add,git___git_diff,\ +git___git_diff_staged,git___git_diff_unstaged,git___git_log,git___git_show,\ +git___git_status" + # Check if there are staged changes if ! git diff --cached --quiet; then # If prompt is provided as argument, use it @@ -43,15 +48,16 @@ if ! git diff --cached --quiet; then # Create a temporary file for the commit message TEMP_FILE=$(mktemp /tmp/git-qcommit-XXXXXX) + # Define the initial prompt for Amazon Q + INITIAL_PROMPT="Based on the staged git changes, generate a descriptive git \ +commit message and write it to $TEMP_FILE. Feel free to use appropriate \ +gitmoji/emoji icons. Include what was changed and why. Don't include any \ +markdown formatting or code blocks. + +Prompt: $PROMPT" + # Generate commit message using Amazon Q and write to temporary file - echo -e "Based on the staged git changes, generate a descriptive git commit message \ -and write it to $TEMP_FILE. Feel free to use appropriate gitmoji/emoji icons. \ -Include what was changed and why. Don't include any markdown formatting or code \ -blocks.\n\nPrompt: $PROMPT" | q chat -a \ - --no-interactive \ - --trust-tools=fs_read,fs_write,execute_bash,internal_command,thinking,\ -fetch___fetch,git___git_add,git___git_diff,git___git_diff_staged,\ -git___git_diff_unstaged,git___git_log,git___git_show,git___git_status + echo -e "$INITIAL_PROMPT" | q chat --no-interactive --trust-tools="$TRUSTED_TOOLS" # Check if the temporary file exists and has content if [ -s "$TEMP_FILE" ]; then From 1f703422e5d04c29a69182d8f5f68381b3c4e89e Mon Sep 17 00:00:00 2001 From: "amazon-q-developer[bot]" <208079219+amazon-q-developer[bot]@users.noreply.github.com> Date: Sat, 10 May 2025 08:06:09 +0000 Subject: [PATCH 3/3] =?UTF-8?q?=F0=9F=94=A7=20refactor:=20inline=20configu?= =?UTF-8?q?ration=20variables=20in=20git-qcommit=20script?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- git-qcommit | 26 ++++++++++---------------- 1 file changed, 10 insertions(+), 16 deletions(-) diff --git a/git-qcommit b/git-qcommit index 1a7d1db..b550763 100644 --- a/git-qcommit +++ b/git-qcommit @@ -9,11 +9,6 @@ set -e PROMPTS_FILE="$HOME/.commitprompts" -# Define trusted tools for Amazon Q -TRUSTED_TOOLS="fs_read,fs_write,execute_bash,git___git_add,git___git_diff,\ -git___git_diff_staged,git___git_diff_unstaged,git___git_log,git___git_show,\ -git___git_status" - # Check if there are staged changes if ! git diff --cached --quiet; then # If prompt is provided as argument, use it @@ -48,22 +43,21 @@ if ! git diff --cached --quiet; then # Create a temporary file for the commit message TEMP_FILE=$(mktemp /tmp/git-qcommit-XXXXXX) - # Define the initial prompt for Amazon Q - INITIAL_PROMPT="Based on the staged git changes, generate a descriptive git \ -commit message and write it to $TEMP_FILE. Feel free to use appropriate \ -gitmoji/emoji icons. Include what was changed and why. Don't include any \ -markdown formatting or code blocks. - -Prompt: $PROMPT" - # Generate commit message using Amazon Q and write to temporary file - echo -e "$INITIAL_PROMPT" | q chat --no-interactive --trust-tools="$TRUSTED_TOOLS" + echo -e "Based on the staged git changes, generate a descriptive git commit \ +message and write it to $TEMP_FILE. Feel free to use appropriate gitmoji/emoji \ +icons. Include what was changed and why. Don't include any markdown formatting \ +or code blocks.\n\nPrompt: $PROMPT" | q chat \ + --no-interactive \ + --trust-tools=fs_read,fs_write,execute_bash,git___git_add,git___git_diff,\ +git___git_diff_staged,git___git_diff_unstaged,git___git_log,git___git_show,\ +git___git_status # Check if the temporary file exists and has content if [ -s "$TEMP_FILE" ]; then # Show the generated message and ask for confirmation - echo -e "\nGenerated commit message:" - cat "$TEMP_FILE" + echo -e "\nGenerated commit message:" && \ + cat "$TEMP_FILE" && \ echo "" read -p "Do you want to commit with this message? (y/n): " confirm