aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorlookshe <github@lookshe.org>2016-02-26 10:35:57 +0100
committerlookshe <github@lookshe.org>2016-02-26 10:35:57 +0100
commit1c1f2a00d290598f050cb77ad4c846902a135f5b (patch)
treeeade990c622ab4992f2ab49d6a70ce71e1a4d63e
parent335423fb9ded67f3820f34793a7774d9f35d7c09 (diff)
implementation to link FS#[0-9]+ to flyspray (FS#141)
-rw-r--r--cgit.c1
-rw-r--r--cgit.h3
-rw-r--r--shared.c8
-rw-r--r--ui-commit.c4
-rw-r--r--ui-log.c4
-rw-r--r--ui-shared.c91
-rw-r--r--ui-shared.h8
7 files changed, 115 insertions, 4 deletions
diff --git a/cgit.c b/cgit.c
index 4eaa7ab..62e5e28 100644
--- a/cgit.c
+++ b/cgit.c
@@ -392,6 +392,7 @@ static void prepare_context(void)
ctx.cfg.summary_tags = 10;
ctx.cfg.max_atom_items = 10;
ctx.cfg.difftype = DIFF_UNIFIED;
+ ctx.cfg.issue_link = "https://bugs.thedevstack.de/task/";
ctx.env.cgit_config = getenv("CGIT_CONFIG");
ctx.env.http_host = getenv("HTTP_HOST");
ctx.env.https = getenv("HTTPS");
diff --git a/cgit.h b/cgit.h
index de5c94a..567bfec 100644
--- a/cgit.h
+++ b/cgit.h
@@ -270,6 +270,7 @@ struct cgit_config {
struct cgit_filter *email_filter;
struct cgit_filter *owner_filter;
struct cgit_filter *auth_filter;
+ char* issue_link;
};
struct cgit_page {
@@ -394,4 +395,6 @@ extern char *expand_macros(const char *txt);
extern char *get_mimetype_for_filename(const char *filename);
+extern char *sub_str(const char* text, int begin, int end);
+
#endif /* CGIT_H */
diff --git a/shared.c b/shared.c
index a078a27..b65e801 100644
--- a/shared.c
+++ b/shared.c
@@ -600,3 +600,11 @@ char *get_mimetype_for_filename(const char *filename)
fclose(file);
return NULL;
}
+
+char* sub_str(const char* text, int begin, int end)
+{
+ char* sub = (char*) malloc(sizeof(char) * ((end - begin) + 1));
+ strncpy(sub, text + begin, end - begin);
+ sub[end - begin] = '\0';
+ return sub;
+}
diff --git a/ui-commit.c b/ui-commit.c
index 0c3d740..d3f7922 100644
--- a/ui-commit.c
+++ b/ui-commit.c
@@ -115,13 +115,13 @@ void cgit_print_commit(char *hex, const char *prefix)
html("</table>\n");
html("<div class='commit-subject'>");
cgit_open_filter(ctx.repo->commit_filter);
- html_txt(info->subject);
+ cgit_check_text_for_issue_link(info->subject);
cgit_close_filter(ctx.repo->commit_filter);
show_commit_decorations(commit);
html("</div>");
html("<div class='commit-msg'>");
cgit_open_filter(ctx.repo->commit_filter);
- html_txt(info->msg);
+ cgit_check_text_for_issue_link(info->msg);
cgit_close_filter(ctx.repo->commit_filter);
html("</div>");
if (notes.len != 0) {
diff --git a/ui-log.c b/ui-log.c
index 19a9707..4cb93b3 100644
--- a/ui-log.c
+++ b/ui-log.c
@@ -234,8 +234,8 @@ static void print_commit(struct commit *commit, struct rev_info *revs)
strcpy(info->subject + i, wrap_symbol);
}
}
- cgit_commit_link(info->subject, NULL, NULL, ctx.qry.head,
- oid_to_hex(&commit->object.oid), ctx.qry.vpath);
+ cgit_commit_link2(info->subject, NULL, NULL, ctx.qry.head,
+ oid_to_hex(&commit->object.oid), ctx.qry.vpath, true);
show_commit_decorations(commit);
html("</td><td>");
cgit_open_filter(ctx.repo->email_filter, info->author_email, "log");
diff --git a/ui-shared.c b/ui-shared.c
index 15bcb3f..ea6d18b 100644
--- a/ui-shared.c
+++ b/ui-shared.c
@@ -356,7 +356,52 @@ void cgit_commit_link(char *name, const char *title, const char *class,
name[ctx.cfg.max_msg_len - 2] = '.';
name[ctx.cfg.max_msg_len - 3] = '.';
}
+ cgit_commit_link2(name, title, class, head, rev, path, false);
+}
+void cgit_commit_link2(char *name, const char *title, const char *class,
+ const char *head, const char *rev, const char *path, bool checkForIssueLink)
+{
+ if (checkForIssueLink) {
+ int last_match = 0;
+ for (;;) {
+ const char* sub = strstr(name + last_match, "FS#");
+ if (sub != NULL) {
+ const char* sub = strstr(name + last_match, "FS#");
+ int found_pos = (sub - (name + last_match));
+ if (found_pos > 0) {
+ char* left_part = sub_str(name, last_match, last_match + found_pos);
+ cgit_commit_link3(left_part, title, class, head, rev, path);
+ free(left_part);
+ }
+ sub += 3;
+ int numbercount = 0;
+ while (*sub >= '0' && *sub <= '9') {
+ numbercount++;
+ sub++;
+ }
+ char* issue_part = sub_str(name, last_match + found_pos, last_match + found_pos + 3 + numbercount);
+ if (numbercount)
+ cgit_issue_link(issue_part);
+ else
+ cgit_commit_link3(issue_part, title, class, head, rev, path);
+ free(issue_part);
+ last_match += found_pos + 3 + numbercount;
+ } else {
+ if (strlen(name + last_match)) {
+ cgit_commit_link3(name + last_match, title, class, head, rev, path);
+ }
+ break;
+ }
+ }
+ } else {
+ cgit_commit_link3(name, title, class, head, rev, path);
+ }
+}
+
+void cgit_commit_link3(char *name, const char *title, const char *class,
+ const char *head, const char *rev, const char *path)
+{
char *delim;
delim = repolink(title, class, "commit", head, path);
@@ -1117,3 +1162,49 @@ extern void cgit_author_link(const char *author, const char *head)
html_txt(author);
html("</a>");
}
+
+extern void cgit_check_text_for_issue_link(const char* text)
+{
+ int last_match = 0;
+ for (;;) {
+ const char* sub = strstr(text + last_match, "FS#");
+ if(sub != NULL) {
+ int found_pos = (sub - (text + last_match));
+ if (found_pos > 0) {
+ char* left_part = sub_str(text, last_match, last_match + found_pos);
+ html_txt(left_part);
+ free(left_part);
+ }
+ sub += 3;
+ int numbercount = 0;
+ while (*sub >= '0' && *sub <= '9') {
+ numbercount++;
+ sub++;
+ }
+ char* issue_part = sub_str(text, last_match + found_pos, last_match + found_pos + 3 + numbercount);
+ if (numbercount)
+ cgit_issue_link(issue_part);
+ else
+ html_txt(issue_part);
+ free(issue_part);
+ last_match += found_pos + 3 + numbercount;
+ } else {
+ if (strlen(text + last_match)) {
+ html_txt(text + last_match);
+ }
+ break;
+ }
+ }
+}
+
+extern void cgit_issue_link(const char* issue)
+{
+ html("<a href='");
+ htmlf(ctx.cfg.issue_link);
+ if (strlen(issue) > 3) {
+ htmlf(issue + 3);
+ }
+ html("' target='_blank'>");
+ html_txt(issue);
+ html("</a>");
+}
diff --git a/ui-shared.h b/ui-shared.h
index 369e33c..9b972b5 100644
--- a/ui-shared.h
+++ b/ui-shared.h
@@ -33,6 +33,12 @@ extern void cgit_log_link(const char *name, const char *title,
extern void cgit_commit_link(char *name, const char *title,
const char *class, const char *head,
const char *rev, const char *path);
+extern void cgit_commit_link2(char *name, const char *title,
+ const char *class, const char *head,
+ const char *rev, const char *path, bool checkForIssueLink);
+extern void cgit_commit_link3(char *name, const char *title,
+ const char *class, const char *head,
+ const char *rev, const char *path);
extern void cgit_patch_link(const char *name, const char *title,
const char *class, const char *head,
const char *rev, const char *path);
@@ -76,4 +82,6 @@ extern void cgit_print_snapshot_links(const char *repo, const char *head,
extern void cgit_add_hidden_formfields(int incl_head, int incl_search,
const char *page);
extern void cgit_author_link(const char *author, const char *head);
+extern void cgit_check_text_for_issue_link(const char* text);
+extern void cgit_issue_link(const char* issue);
#endif /* UI_SHARED_H */