Download raw body.
http notifications: add repo field
This adds the missing metadata about the repository name in the http
notifications. Mail notifications have this info in the subject.
adding a flag for it can be ok?
diff /home/op/w/got
commit - 813645df7b21d54ae779e80fc6e7ad9c913b67d6
path + /home/op/w/got
blob - a496fde3da3e6887293b606aae85015172b8a382
file + gotd/gotd.conf.5
--- 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 - 2b04222ed9896664bd3fd8b05fc126ae38feb27a
file + gotd/libexec/got-notify-http/got-notify-http.c
--- gotd/libexec/got-notify-http/got-notify-http.c
+++ gotd/libexec/got-notify-http/got-notify-http.c
@@ -42,7 +42,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);
}
@@ -190,7 +190,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;
@@ -209,6 +209,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);
@@ -217,7 +218,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;
@@ -240,6 +241,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);
@@ -250,7 +252,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;
@@ -278,6 +280,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) {
@@ -544,7 +547,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;
@@ -566,6 +569,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) {
@@ -674,7 +678,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;
@@ -694,25 +698,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;
}
@@ -764,6 +768,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;
@@ -778,7 +783,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;
@@ -789,6 +794,9 @@ main(int argc, char **argv)
case 'p':
port = optarg;
break;
+ case 'r':
+ repo = optarg;
+ break;
default:
usage();
}
@@ -796,7 +804,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";
@@ -826,7 +834,7 @@ main(int argc, char **argv)
if (tmpfp == NULL)
err(1, "opentemp");
- jsonify(tmpfp);
+ jsonify(tmpfp, repo);
paylen = ftello(tmpfp);
if (paylen == -1)
blob - 130421d61e42a690b8ee37a09bbf38b3bc2da092
file + gotd/notify.c
--- gotd/notify.c
+++ gotd/notify.c
@@ -253,15 +253,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";
@@ -309,7 +311,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
file + regress/gotd/http_notification.sh
--- 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",
http notifications: add repo field