1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
|
#ifndef GIT_H
#define GIT_H
#include <git2.h>
#include <stdint.h>
#include <time.h>
#include "index.h"
#include "keyword.h"
typedef struct pull_request pull_request;
typedef struct file file;
typedef struct comment comment;
typedef struct git_branch git_branch;
struct file {
char *name;
char *buf;
};
struct comment {
char *author;
char *desc;
time_t date;
int id;
comment *reply;
};
struct git_branch {
char *name;
char *repo;
};
struct pull_request {
char *title;
char *desc;
char *author;
comment **comments;
time_t date;
uint8_t pr_type;
union {
file **patches;
git_branch *branch;
};
git_branch *merge_branch;
};
extern void cleanup_git(git_repository **repos);
extern git_repository **init_git(config *cfg);
extern pull_request *get_pull_request(index_t *idx, const char *root);
extern int add_comment(comment *comment, const char *pr_root);
extern int create_pull_request_dir(pull_request *pr, index_t *idx, const char *root);
int parse_patch_list(void *ctx, void *ret, const keyword *key, keyword_val val);
int parse_comment_reply(void *ctx, void *ret, const keyword *key, keyword_val val);
#define offset_list(...) (size_t []){__VA_ARGS__, -1}
static const keyword *info_keywords[] = {
&(const keyword){"title", "Title of Pull Request.", NULL, TYPE_STRING, offset_list(offsetof(pull_request, title)), NULL},
&(const keyword){"author", "Author of Pull Request.", NULL, TYPE_STRING, offset_list(offsetof(pull_request, author)), NULL},
&(const keyword){"date", "Date of Pull Request's creation.", "%a %b %e %H:%M:%S %Y %z", TYPE_TIME, offset_list(offsetof(pull_request, date)), NULL},
&(const keyword){"description", "Description of Pull Request.", NULL, TYPE_STRING, offset_list(offsetof(pull_request, desc)), NULL},
&(const keyword){"type", "Type of Pull Request (0 = patch files, 1 = remote repo).", NULL, TYPE_INT, offset_list(offsetof(pull_request, pr_type)), NULL},
&(const keyword){"branch", "Branch of remote repo.", NULL, TYPE_STRING, offset_list(offsetof(pull_request, branch), offsetof(git_branch, name)), NULL},
&(const keyword){"repo", "URL of remote repo.", NULL, TYPE_STRING, offset_list(offsetof(pull_request, branch), offsetof(git_branch, repo)), NULL},
&(const keyword){"patches", "Patch file(s) of Pull Request.", NULL, TYPE_STRING, offset_list(offsetof(pull_request, patches), offsetof(file, name)), parse_patch_list},
NULL,
};
static const keyword *comment_keywords[] = {
&(const keyword){"id", "ID of Comment.", NULL, TYPE_INT, offset_list(offsetof(comment, id)), NULL},
&(const keyword){"author", "Author of Comment.", NULL, TYPE_STRING, offset_list(offsetof(comment, author)), NULL},
&(const keyword){"date", "Date of Comment's creation.", "%a %b %e %H:%M:%S %Y %z", TYPE_TIME, offset_list(offsetof(comment, date)), NULL},
&(const keyword){"reply-to", "ID of replied Comment.", NULL, TYPE_INT, offset_list(offsetof(comment, reply), offsetof(comment, id)), parse_comment_reply},
&(const keyword){"reply-author", "Author of replied Comment.", NULL, TYPE_STRING, offset_list(offsetof(comment, reply), offsetof(comment, author)), parse_comment_reply},
&(const keyword){"reply-date", "Date of replied Comment's creation", "%a %b %e %H:%M:%S %Y %z", TYPE_TIME, offset_list(offsetof(comment, reply), offsetof(comment, date)), parse_comment_reply},
&(const keyword){"description", "Message of Comment.", NULL, TYPE_STRING, offset_list(offsetof(comment, desc)), NULL},
NULL,
};
#undef offset_list
#endif
|