commit 1ddd9d55d5c5f0e3df1e0f102ebbd8c9b420a0fb from: Stefan Sperling date: Fri May 10 20:45:13 2024 UTC display abbreviated commit/tag IDs in email notification subject lines This should make it somewhat easier to keep track of discussion threads when someone replies to a commit notification to discuss the changes. commit - eec627068f6ed6729b1a075b6052d0e076367838 commit + 1ddd9d55d5c5f0e3df1e0f102ebbd8c9b420a0fb blob - 4625d7a4c51cb7790551d703c3a82fc9cce4d620 blob + c21d1c02dd99282f345f37e8dc6e2cb64c1e65b5 --- gotd/session_write.c +++ gotd/session_write.c @@ -493,7 +493,7 @@ forward_notification(struct gotd_session_client *clien struct gotd_imsgev *iev = &gotd_session.notifier_iev; struct gotd_session_notif *notif; struct gotd_imsg_notification_content icontent; - char *refname = NULL; + char *refname = NULL, *id_str = NULL; size_t datalen; struct gotd_imsg_notify inotify; const char *action; @@ -548,12 +548,21 @@ forward_notification(struct gotd_session_client *clien switch (notif->action) { case GOTD_NOTIF_ACTION_CREATED: action = "created"; + err = got_object_id_str(&id_str, ¬if->new_id); + if (err) + goto done; break; case GOTD_NOTIF_ACTION_REMOVED: action = "removed"; + err = got_object_id_str(&id_str, ¬if->old_id); + if (err) + goto done; break; case GOTD_NOTIF_ACTION_CHANGED: action = "changed"; + err = got_object_id_str(&id_str, ¬if->new_id); + if (err) + goto done; break; default: err = got_error(GOT_ERR_PRIVSEP_MSG); @@ -564,8 +573,8 @@ forward_notification(struct gotd_session_client *clien sizeof(inotify.repo_name)); snprintf(inotify.subject_line, sizeof(inotify.subject_line), - "%s: %s %s %s", gotd_session.repo_cfg->name, - client->username, action, notif->refname); + "%s: %s %s %s: %.12s", gotd_session.repo_cfg->name, + client->username, action, notif->refname, id_str); inotify.username_len = strlen(client->username); wbuf = imsg_create(&iev->ibuf, GOTD_IMSG_NOTIFY, @@ -594,6 +603,7 @@ done: close(notif->fd); free(notif); free(refname); + free(id_str); return err; } blob - f95b00932a0932131a46023cbdd33283f82a5563 blob + 0f044fa5e9f2d09e6ac1d9c134d217185fe3fb57 --- regress/gotd/email_notification.sh +++ regress/gotd/email_notification.sh @@ -54,6 +54,7 @@ test_file_changed() { wait %1 # wait for nc -l + short_commit_id=`trim_obj_id 28 $commit_id` HOSTNAME=`hostname` printf "HELO localhost\r\n" > $testroot/stdout.expected printf "MAIL FROM:<${GOTD_USER}@${HOSTNAME}>\r\n" \ @@ -63,7 +64,7 @@ test_file_changed() { printf "From: ${GOTD_USER}@${HOSTNAME}\r\n" >> $testroot/stdout.expected printf "To: ${GOTD_DEVUSER}\r\n" >> $testroot/stdout.expected printf "Subject: $GOTD_TEST_REPO_NAME: " >> $testroot/stdout.expected - printf "${GOTD_DEVUSER} changed refs/heads/main\r\n" \ + printf "${GOTD_DEVUSER} changed refs/heads/main: $short_commit_id\r\n" \ >> $testroot/stdout.expected printf "\r\n" >> $testroot/stdout.expected printf "commit $commit_id\n" >> $testroot/stdout.expected @@ -133,6 +134,7 @@ test_many_commits_not_summarized() { wait %1 # wait for nc -l + short_commit_id=`trim_obj_id 28 $commit_id` HOSTNAME=`hostname` printf "HELO localhost\r\n" > $testroot/stdout.expected printf "MAIL FROM:<${GOTD_USER}@${HOSTNAME}>\r\n" \ @@ -143,7 +145,7 @@ test_many_commits_not_summarized() { >> $testroot/stdout.expected printf "To: ${GOTD_DEVUSER}\r\n" >> $testroot/stdout.expected printf "Subject: $GOTD_TEST_REPO_NAME: " >> $testroot/stdout.expected - printf "${GOTD_DEVUSER} changed refs/heads/main\r\n" \ + printf "${GOTD_DEVUSER} changed refs/heads/main: $short_commit_id\r\n" \ >> $testroot/stdout.expected printf "\r\n" >> $testroot/stdout.expected for i in `seq 1 24`; do @@ -219,6 +221,7 @@ test_many_commits_summarized() { wait %1 # wait for nc -l + short_commit_id=`trim_obj_id 28 $commit_id` HOSTNAME=`hostname` printf "HELO localhost\r\n" > $testroot/stdout.expected printf "MAIL FROM:<${GOTD_USER}@${HOSTNAME}>\r\n" \ @@ -229,7 +232,7 @@ test_many_commits_summarized() { >> $testroot/stdout.expected printf "To: ${GOTD_DEVUSER}\r\n" >> $testroot/stdout.expected printf "Subject: $GOTD_TEST_REPO_NAME: " >> $testroot/stdout.expected - printf "${GOTD_DEVUSER} changed refs/heads/main\r\n" \ + printf "${GOTD_DEVUSER} changed refs/heads/main: $short_commit_id\r\n" \ >> $testroot/stdout.expected printf "\r\n" >> $testroot/stdout.expected for i in `seq 1 51`; do @@ -294,6 +297,7 @@ test_branch_created() { wait %1 # wait for nc -l + short_commit_id=`trim_obj_id 28 $commit_id` HOSTNAME=`hostname` printf "HELO localhost\r\n" > $testroot/stdout.expected printf "MAIL FROM:<${GOTD_USER}@${HOSTNAME}>\r\n" \ @@ -303,7 +307,7 @@ test_branch_created() { printf "From: ${GOTD_USER}@${HOSTNAME}\r\n" >> $testroot/stdout.expected printf "To: ${GOTD_DEVUSER}\r\n" >> $testroot/stdout.expected printf "Subject: $GOTD_TEST_REPO_NAME: " >> $testroot/stdout.expected - printf "${GOTD_DEVUSER} created refs/heads/newbranch\r\n" \ + printf "${GOTD_DEVUSER} created refs/heads/newbranch: $short_commit_id\r\n" \ >> $testroot/stdout.expected printf "\r\n" >> $testroot/stdout.expected printf "commit $commit_id\n" >> $testroot/stdout.expected @@ -347,6 +351,7 @@ test_branch_removed() { | timeout 5 nc -l "$GOTD_TEST_SMTP_PORT" > $testroot/stdout) & local commit_id=`git_show_branch_head $testroot/repo-clone newbranch` + local short_commit_id=`trim_obj_id 28 $commit_id` got send -d newbranch -q -r $testroot/repo-clone ret=$? @@ -367,7 +372,7 @@ test_branch_removed() { printf "From: ${GOTD_USER}@${HOSTNAME}\r\n" >> $testroot/stdout.expected printf "To: ${GOTD_DEVUSER}\r\n" >> $testroot/stdout.expected printf "Subject: $GOTD_TEST_REPO_NAME: " >> $testroot/stdout.expected - printf "${GOTD_DEVUSER} removed refs/heads/newbranch\r\n" \ + printf "${GOTD_DEVUSER} removed refs/heads/newbranch: $short_commit_id\r\n" \ >> $testroot/stdout.expected printf "\r\n" >> $testroot/stdout.expected printf "Removed refs/heads/newbranch: $commit_id\n" \ @@ -402,6 +407,9 @@ test_tag_created() { got tag -r $testroot/repo-clone -m "new tag" 1.0 > /dev/null local commit_id=`git_show_head $testroot/repo-clone` local tagger_time=`git_show_tagger_time $testroot/repo-clone 1.0` + local tag_id=`got ref -r $testroot/repo-clone -l \ + | grep "^refs/tags/$tag" | tr -d ' ' | cut -d: -f2` + local short_tag_id=`trim_obj_id 28 $tag_id` (printf "220\r\n250\r\n250\r\n250\r\n354\r\n250\r\n221\r\n" \ | timeout 5 nc -l "$GOTD_TEST_SMTP_PORT" > $testroot/stdout) & @@ -425,7 +433,7 @@ test_tag_created() { printf "From: ${GOTD_USER}@${HOSTNAME}\r\n" >> $testroot/stdout.expected printf "To: ${GOTD_DEVUSER}\r\n" >> $testroot/stdout.expected printf "Subject: $GOTD_TEST_REPO_NAME: " >> $testroot/stdout.expected - printf "${GOTD_DEVUSER} created refs/tags/1.0\r\n" \ + printf "${GOTD_DEVUSER} created refs/tags/1.0: $short_tag_id\r\n" \ >> $testroot/stdout.expected printf "\r\n" >> $testroot/stdout.expected printf "tag refs/tags/1.0\n" >> $testroot/stdout.expected @@ -478,6 +486,9 @@ test_tag_changed() { got ref -r $testroot/repo-clone -d refs/tags/1.0 >/dev/null got tag -r $testroot/repo-clone -m "new tag" 1.0 > /dev/null local tagger_time=`git_show_tagger_time $testroot/repo-clone 1.0` + local tag_id=`got ref -r $testroot/repo-clone -l \ + | grep "^refs/tags/$tag" | tr -d ' ' | cut -d: -f2` + local short_tag_id=`trim_obj_id 28 $tag_id` (printf "220\r\n250\r\n250\r\n250\r\n354\r\n250\r\n221\r\n" \ | timeout 5 nc -l "$GOTD_TEST_SMTP_PORT" > $testroot/stdout) & @@ -501,7 +512,7 @@ test_tag_changed() { printf "From: ${GOTD_USER}@${HOSTNAME}\r\n" >> $testroot/stdout.expected printf "To: ${GOTD_DEVUSER}\r\n" >> $testroot/stdout.expected printf "Subject: $GOTD_TEST_REPO_NAME: " >> $testroot/stdout.expected - printf "${GOTD_DEVUSER} changed refs/tags/1.0\r\n" \ + printf "${GOTD_DEVUSER} changed refs/tags/1.0: $short_tag_id\r\n" \ >> $testroot/stdout.expected printf "\r\n" >> $testroot/stdout.expected printf "tag refs/tags/1.0\n" >> $testroot/stdout.expected