File tree Expand file tree Collapse file tree 2 files changed +39
-2
lines changed Expand file tree Collapse file tree 2 files changed +39
-2
lines changed Original file line number Diff line number Diff line change @@ -6,10 +6,23 @@ import (
6
6
"strings"
7
7
)
8
8
9
- // Slack returns github markdown converted to slack
10
- func Slack (markdown string ) string {
9
+ // SlackConvertOptions contains options to fine-toon GitHub to Slack markdown convert
10
+ type SlackConvertOptions struct {
11
+ // Headlines will define if GitHub headlines will be updated to be bold text in slack
12
+ // there is no headlines as sucks in Slack
13
+ Headlines bool
14
+ }
15
+
16
+ // Slack returns github markdown converted to Slack
17
+ func Slack (markdown string , options ... SlackConvertOptions ) string {
11
18
var re * regexp.Regexp
12
19
20
+ opt := SlackConvertOptions {}
21
+ if len (options ) > 0 {
22
+ opt = options [0 ]
23
+ }
24
+
25
+ // TODO: write proper regex
13
26
linkRegex := ".*"
14
27
15
28
// bold **TEXT** -> *TEXT*
@@ -55,5 +68,10 @@ func Slack(markdown string) string {
55
68
re = regexp .MustCompile (`(?m)((\n[ ]{0,})(\*))` )
56
69
markdown = re .ReplaceAllString (markdown , "$2•" )
57
70
71
+ if opt .Headlines {
72
+ re = regexp .MustCompile (`(?m)((^\t?[ ]{0,15}#{1,4}[ ]{1,})(.+))` )
73
+ markdown = re .ReplaceAllString (markdown , "*$3*" )
74
+ }
75
+
58
76
return markdown
59
77
}
Original file line number Diff line number Diff line change @@ -47,4 +47,23 @@ func TestSlack(t *testing.T) {
47
47
• remove DELETE /v1/message (<https://github.com/foo/boo/issues/121|#121>) (<https://github.com/foo/boo/commit/3523r42|3523r42>)`
48
48
49
49
assert .Equal (msgSlack , Slack (msgGithub ))
50
+
51
+ // test headlines parse
52
+ optWithHeadlines := SlackConvertOptions {
53
+ Headlines : true ,
54
+ }
55
+ assert .Equal ("*fooo*" , Slack ("### fooo" , optWithHeadlines ))
56
+ assert .Equal ("*Boo foo 123*" , Slack (" # Boo foo 123" , optWithHeadlines ))
57
+ assert .Equal (`
58
+ *Features*
59
+ ` , Slack (`
60
+ ### Features
61
+ ` , optWithHeadlines ))
62
+
63
+ msgSlackHeadlinesBold := `*<https://github.com/foo/boo/compare/v1.49.3...v1.50.0|1.50.0> (2015-02-12)*
64
+ *Features*
65
+ • add GET /v1/events (<https://github.com/foo/boo/issues/134|#134>) (<https://github.com/foo/boo/commit/1726806|1726806>)
66
+ • remove DELETE /v1/message (<https://github.com/foo/boo/issues/121|#121>) (<https://github.com/foo/boo/commit/3523r42|3523r42>)`
67
+
68
+ assert .Equal (msgSlackHeadlinesBold , Slack (msgGithub , optWithHeadlines ))
50
69
}
You can’t perform that action at this time.
0 commit comments