Commit Diff


commit - 914bfd3ddbdf1adc0adf828c7531b8174b6b2010
commit + d60570848cd614b529f720c17d37d54c77dd5949
blob - 7bd3f39814f8f94fc9ed5420279174e53e0d92a1
blob + ce42aab3943c0acfce6889c037c435bac0241964
--- gotd/libexec/got-notify-http/got-notify-http.c
+++ gotd/libexec/got-notify-http/got-notify-http.c
@@ -190,6 +190,33 @@ json_author(FILE *fp, const char *type, char *address,
 }
 
 static int
+jsonify_branch_rm(FILE *fp, char *line)
+{
+	char	*ref, *id;
+
+	line = strchr(line, ' ');
+	if (line == NULL)
+		errx(1, "invalid branch rm line");
+	line += strspn(line, " ");
+
+	ref = line;
+
+	line = strchr(line, ':');
+	if (line == NULL)
+		errx(1, "invalid branch rm line");
+	*line++ = '\0';
+	id = line + strspn(line, " ");
+
+	fputc('{', fp);
+	json_field(fp, "type", "branch-deleted", 1);
+	json_field(fp, "ref", ref, 1);
+	json_field(fp, "id", id, 0);
+	fputc('}', fp);
+
+	return 0;
+}
+
+static int
 jsonify_commit_short(FILE *fp, char *line)
 {
 	char	*t, *date, *id, *author, *message;
@@ -420,6 +447,12 @@ jsonify(FILE *fp)
 			fputc(',', fp);
 		needcomma = 1;
 
+		if (strncmp(line, "Removed refs/heads/", 19) == 0) {
+			if (jsonify_branch_rm(fp, line) == -1)
+				err(1, "jsonify_branch_rm");
+			continue;
+		}
+
 		if (strncmp(line, "commit ", 7) == 0) {
 			if (jsonify_commit(fp, &line, &linesize) == -1)
 				err(1, "jsonify_commit");
blob - 108cbb93e5ac5409668ac95f07850296d69a9b9c
blob + 8bf420b1b2ad5811471bcfd0160cda044cdb7cbf
--- regress/gotd/http_notification.sh
+++ regress/gotd/http_notification.sh
@@ -444,10 +444,61 @@ test_branch_created() {
 
 	test_done "$testroot" "$ret"
 }
+
+test_branch_removed() {
+	local testroot=`test_init branch_removed 1`
+
+	got clone -a -q ${GOTD_TEST_REPO_URL} $testroot/repo-clone
+	ret=$?
+	if [ $ret -ne 0 ]; then
+		echo "got clone failed unexpectedly" >&2
+		test_done "$testroot" 1
+		return 1
+	fi
 
+	timeout 5 ./http-server -p "$GOTD_TEST_HTTP_PORT" \
+	    > $testroot/stdout &
+
+	local commit_id=`git_show_branch_head $testroot/repo-clone newbranch`
+
+	got send -d newbranch -q -r $testroot/repo-clone
+	ret=$?
+	if [ $ret -ne 0 ]; then
+		echo "got send failed unexpectedly" >&2
+		test_done "$testroot" "1"
+		return 1
+	fi
+
+	wait %1 # wait for the http "server"
+
+	touch "$testroot/stdout.expected"
+	ed -s "$testroot/stdout.expected" <<-EOF
+	a
+	{"notifications":[{
+		"type":"branch-deleted",
+		"ref":"refs/heads/newbranch",
+		"id":"$commit_id"
+	}]}
+	.
+	,j
+	w
+	EOF
+
+	cmp -s $testroot/stdout.expected $testroot/stdout
+	ret=$?
+	if [ $ret -ne 0 ]; then
+		diff -u $testroot/stdout.expected $testroot/stdout
+		test_done "$testroot" "$ret"
+		return 1
+	fi
+
+	test_done "$testroot" "$ret"
+}
+
 test_parseargs "$@"
 run_test test_file_changed
 run_test test_bad_utf8
 run_test test_many_commits_not_summarized
 run_test test_many_commits_summarized
 run_test test_branch_created
+run_test test_branch_removed