commit 23022bc04f3cdc9d7ed1ecdc30599b7e1515814d from: Omar Polo via: Thomas Adam date: Thu Apr 25 14:57:36 2024 UTC got-notify-http: add the repository name in the json ok stsp commit - 8ec83e5b6ebab7711854b45048771661a0f9ec98 commit + 23022bc04f3cdc9d7ed1ecdc30599b7e1515814d blob - a496fde3da3e6887293b606aae85015172b8a382 blob + 6b1e63e34c2c42b7aeff0c238e2a303c5efa7c2a --- gotd/gotd.conf.5 +++ gotd/gotd.conf.5 @@ -371,6 +371,8 @@ Except where noted, all are optional. Boolean, indicates whether the object has all the fields set. When several commits are batched in a single send operation, not all of the fields are available for each commit object. +.It Dv repo +The repository name as string. .It Dv id The commit ID as string, may be abbreviated. .It Dv committer @@ -444,6 +446,8 @@ which are the number of added and removed lines respec The branch deleted notifications has the following fields, all guaranteed to be set: .Bl -tag -compact -width Ds +.It Dv repo +The repository name as string. .It Dv ref The removed branch reference. .It Dv id @@ -452,6 +456,8 @@ The hash of the commit pointed by the deleted branch. .It Dv tag The tag notification has the following fields, all guaranteed to be set: .Bl -tag -width Ds +.It repo +The repository name as string. .It tag The tag reference. .It tagger blob - 48b3bbf945c1415462a67b74597cc92769fb4aae blob + 5e24a54dc48ff1d182da64b25032678630a6206e --- gotd/libexec/got-notify-http/got-notify-http.c +++ gotd/libexec/got-notify-http/got-notify-http.c @@ -44,7 +44,7 @@ static int http_timeout = 300; /* 5 minutes in secon __dead static void usage(void) { - fprintf(stderr, "usage: %s [-c] -h host -p port path\n", + fprintf(stderr, "usage: %s [-c] -r repo -h host -p port path\n", getprogname()); exit(1); } @@ -192,7 +192,7 @@ json_author(FILE *fp, const char *type, char *address, } static int -jsonify_branch_rm(FILE *fp, char *line) +jsonify_branch_rm(FILE *fp, char *line, const char *repo) { char *ref, *id; @@ -211,6 +211,7 @@ jsonify_branch_rm(FILE *fp, char *line) fputc('{', fp); json_field(fp, "type", "branch-deleted", 1); + json_field(fp, "repo", repo, 1); json_field(fp, "ref", ref, 1); json_field(fp, "id", id, 0); fputc('}', fp); @@ -219,7 +220,7 @@ jsonify_branch_rm(FILE *fp, char *line) } static int -jsonify_commit_short(FILE *fp, char *line) +jsonify_commit_short(FILE *fp, char *line, const char *repo) { char *t, *date, *id, *author, *message; @@ -242,6 +243,7 @@ jsonify_commit_short(FILE *fp, char *line) message = t; fprintf(fp, "{\"type\":\"commit\",\"short\":true,"); + json_field(fp, "repo", repo, 1); json_field(fp, "id", id, 1); json_author(fp, "committer", author, 1); json_field(fp, "date", date, 1); @@ -252,7 +254,7 @@ jsonify_commit_short(FILE *fp, char *line) } static int -jsonify_commit(FILE *fp, char **line, ssize_t *linesize) +jsonify_commit(FILE *fp, const char *repo, char **line, ssize_t *linesize) { const char *errstr; char *author = NULL; @@ -280,6 +282,7 @@ jsonify_commit(FILE *fp, char **line, ssize_t *linesiz l += 7; fprintf(fp, "{\"type\":\"commit\",\"short\":false,"); + json_field(fp, "repo", repo, 1); json_field(fp, "id", l, 1); while (!done) { @@ -546,7 +549,7 @@ jsonify_commit(FILE *fp, char **line, ssize_t *linesiz } static int -jsonify_tag(FILE *fp, char **line, ssize_t *linesize) +jsonify_tag(FILE *fp, const char *repo, char **line, ssize_t *linesize) { const char *errstr; char *l; @@ -568,6 +571,7 @@ jsonify_tag(FILE *fp, char **line, ssize_t *linesize) fputc('{', fp); json_field(fp, "type", "tag", 1); + json_field(fp, "repo", repo, 1); json_field(fp, "tag", l, 1); while (!done) { @@ -676,7 +680,7 @@ jsonify_tag(FILE *fp, char **line, ssize_t *linesize) } static int -jsonify(FILE *fp) +jsonify(FILE *fp, const char *repo) { char *line = NULL; size_t linesize = 0; @@ -696,25 +700,25 @@ jsonify(FILE *fp) needcomma = 1; if (strncmp(line, "Removed refs/heads/", 19) == 0) { - if (jsonify_branch_rm(fp, line) == -1) + if (jsonify_branch_rm(fp, line, repo) == -1) err(1, "jsonify_branch_rm"); continue; } if (strncmp(line, "commit ", 7) == 0) { - if (jsonify_commit(fp, &line, &linesize) == -1) + if (jsonify_commit(fp, repo, &line, &linesize) == -1) err(1, "jsonify_commit"); continue; } if (*line >= '0' && *line <= '9') { - if (jsonify_commit_short(fp, line) == -1) + if (jsonify_commit_short(fp, line, repo) == -1) err(1, "jsonify_commit_short"); continue; } if (strncmp(line, "tag ", 4) == 0) { - if (jsonify_tag(fp, &line, &linesize) == -1) + if (jsonify_tag(fp, repo, &line, &linesize) == -1) err(1, "jsonify_tag"); continue; } @@ -766,6 +770,7 @@ main(int argc, char **argv) const char *password; const char *timeoutstr; const char *errstr; + const char *repo = NULL; const char *host = NULL, *port = NULL, *path = NULL; char *auth, *line, *spc; size_t len; @@ -780,7 +785,7 @@ main(int argc, char **argv) err(1, "pledge"); #endif - while ((ch = getopt(argc, argv, "ch:p:")) != -1) { + while ((ch = getopt(argc, argv, "ch:p:r:")) != -1) { switch (ch) { case 'c': tls = 1; @@ -791,6 +796,9 @@ main(int argc, char **argv) case 'p': port = optarg; break; + case 'r': + repo = optarg; + break; default: usage(); } @@ -798,7 +806,7 @@ main(int argc, char **argv) argc -= optind; argv += optind; - if (host == NULL || argc != 1) + if (host == NULL || repo == NULL || argc != 1) usage(); if (tls && port == NULL) port = "443"; @@ -828,7 +836,7 @@ main(int argc, char **argv) if (tmpfp == NULL) err(1, "opentemp"); - jsonify(tmpfp); + jsonify(tmpfp, repo); paylen = ftello(tmpfp); if (paylen == -1) blob - 0cb6b9561ce3a96bb5682b9905a6b4e50de169a3 blob + 4967816730298c8bd6bdd1b4fff3b8aa31ad5c34 --- gotd/notify.c +++ gotd/notify.c @@ -251,15 +251,17 @@ notify_email(struct gotd_notification_target *target, } static void -notify_http(struct gotd_notification_target *target, int fd) +notify_http(struct gotd_notification_target *target, const char *repo, int fd) { - const char *argv[8]; + const char *argv[10]; int argc = 0; argv[argc++] = GOTD_PATH_PROG_NOTIFY_HTTP; if (target->conf.http.tls) argv[argc++] = "-c"; + argv[argc++] = "-r"; + argv[argc++] = repo; argv[argc++] = "-h"; argv[argc++] = target->conf.http.hostname; argv[argc++] = "-p"; @@ -307,7 +309,7 @@ send_notification(struct imsg *imsg, struct gotd_imsge notify_email(target, inotify.subject_line, fd); break; case GOTD_NOTIFICATION_VIA_HTTP: - notify_http(target, fd); + notify_http(target, repo->name, fd); break; } } blob - 4e4fcae3bf98da908b2d453065c14d86ec1cd55b blob + 38661743a189d324f50db59d65ebfb278ed84eff --- regress/gotd/http_notification.sh +++ regress/gotd/http_notification.sh @@ -62,6 +62,7 @@ test_file_changed() { {"notifications":[{ "type":"commit", "short":false, + "repo":"test-repo", "id":"$commit_id", "author":{ "full":"$GOT_AUTHOR", @@ -154,6 +155,7 @@ test_bad_utf8() { {"notifications":[{ "type":"commit", "short":false, + "repo":"test-repo", "id":"$commit_id", "author":{ "full":"$GOT_AUTHOR", @@ -254,6 +256,7 @@ test_many_commits_not_summarized() { { "type":"commit", "short":false, + "repo":"test-repo", "id":"$commit_id", "author":{ "full":"$GOT_AUTHOR", @@ -358,6 +361,7 @@ test_many_commits_summarized() { { "type":"commit", "short":true, + "repo":"test-repo", "id":"$commit_id", "committer":{ "user":"$GOT_AUTHOR_8" @@ -439,6 +443,7 @@ test_branch_created() { { "type":"commit", "short":false, + "repo":"test-repo", "id":"$commit_id", "author":{ "full":"$GOT_AUTHOR", @@ -516,6 +521,7 @@ test_branch_removed() { a {"notifications":[{ "type":"branch-deleted", + "repo":"test-repo", "ref":"refs/heads/newbranch", "id":"$commit_id" }]} @@ -570,6 +576,7 @@ test_tag_created() { a {"notifications":[{ "type":"tag", + "repo":"test-repo", "tag":"refs/tags/1.0", "tagger":{ "full":"$GOT_AUTHOR", @@ -650,6 +657,7 @@ test_tag_changed() { a {"notifications":[{ "type":"tag", + "repo":"test-repo", "tag":"refs/tags/1.0", "tagger":{ "full":"$GOT_AUTHOR",