From ed50197af9739364c4c962c48e5cfb40b209a7b0 Mon Sep 17 00:00:00 2001 From: Thanh Ha Date: Fri, 5 Jun 2020 17:57:37 -0400 Subject: [PATCH] Fix gerrit-push-patch Job key not in trailers Key-value pairs in Git should be appended to the Git trailers section (AKA footer). This patch fixes the commit message produced by gerrit-push-patch which currently creates a commit message where the Job key appears in the commit message body rather than the trailer. For example: An example commit message Job: builder-job/123 Change-Id: 1234567 Signed-off-by: Jenkins This fixes it to: An example commit with proper trailer Job: builder-job/123 Change-Id: 123457 Signed-off-by: Jenkins Signed-off-by: Thanh Ha Change-Id: I66c9b0813b36065c20adcf0e886eaa29354ca603 --- ...errit-push-patch-trailers-de47a4687471d0c8.yaml | 24 ++++++++++++++++++++++ shell/gerrit-push-patch.sh | 6 ++++-- 2 files changed, 28 insertions(+), 2 deletions(-) create mode 100644 releasenotes/notes/fix-gerrit-push-patch-trailers-de47a4687471d0c8.yaml diff --git a/releasenotes/notes/fix-gerrit-push-patch-trailers-de47a4687471d0c8.yaml b/releasenotes/notes/fix-gerrit-push-patch-trailers-de47a4687471d0c8.yaml new file mode 100644 index 00000000..28bd9c92 --- /dev/null +++ b/releasenotes/notes/fix-gerrit-push-patch-trailers-de47a4687471d0c8.yaml @@ -0,0 +1,24 @@ +--- +fixes: + - | + Fix Job key in commit message body rather than trailers section + (AKA footer). The commit message produced by gerrit-push-patch which + currently creates a commit message where the Job key appears in the commit + message body rather than the trailer. + + For example:: + + An example commit message + + Job: builder-job/123 + + Change-Id: 1234567 + Signed-off-by: Jenkins + + This fixes it to:: + + An example commit with proper trailer + + Job: builder-job/123 + Change-Id: 123457 + Signed-off-by: Jenkins diff --git a/shell/gerrit-push-patch.sh b/shell/gerrit-push-patch.sh index d075cdda..30663394 100644 --- a/shell/gerrit-push-patch.sh +++ b/shell/gerrit-push-patch.sh @@ -60,12 +60,14 @@ job=$JOB_NAME/$BUILD_NUMBER # If available, add change_id to commit message if change_id=$(echo "$query_result" | grep 'Change-Id:' | awk '{print $2}'); then echo "NOTE: Found gerrit review: $change_id" - message="Job: $job"$'\n\n'"Change-Id: $change_id" + message="Job: $job"$'\n'"Change-Id: $change_id" else echo "NOTE: No gerrit review found" message="Job: $job" fi -git commit -sm "$GERRIT_COMMIT_MESSAGE" -m "$message" +git commit -sm "$GERRIT_COMMIT_MESSAGE + +$message" git status git remote add gerrit "ssh://$GERRIT_USER@$GERRIT_HOST:29418/$PROJECT.git" -- 2.16.6