1
1
using System ;
2
2
using System . Text ;
3
+ using Common . TableModels ;
3
4
4
5
namespace OpenPrFunction
5
6
{
@@ -8,7 +9,7 @@ public static class PullRequestBody
8
9
/*
9
10
* Convert the ImageStat[] into a markdown PR body
10
11
*/
11
- public static string Generate ( ImageStat [ ] imageStats )
12
+ public static string Generate ( ImageStat [ ] imageStats , Settings settings = null )
12
13
{
13
14
if ( imageStats == null || imageStats . Length == 0 )
14
15
{
@@ -17,61 +18,78 @@ public static string Generate(ImageStat[] imageStats)
17
18
}
18
19
19
20
var sb = new StringBuilder ( ) ;
20
- sb . AppendLine ( "## Beep boop. Your images are optimized!" ) ;
21
- sb . AppendLine ( ) ;
22
-
23
- if ( Math . Round ( imageStats [ 0 ] . Percent ) < 5 )
21
+ if ( settings ? . PrBody == null )
24
22
{
25
- sb . AppendLine ( "Your image file size has been reduced!" ) ;
23
+ sb . AppendLine ( "## Beep boop. Your images are optimized!" ) ;
24
+ sb . AppendLine ( ) ;
25
+
26
+ if ( Math . Round ( imageStats [ 0 ] . Percent ) < 5 )
27
+ {
28
+ sb . AppendLine ( "Your image file size has been reduced!" ) ;
29
+ }
30
+ else
31
+ {
32
+ sb . AppendLine ( $ "Your image file size has been reduced by **{ imageStats [ 0 ] . Percent : N0} %** 🎉") ;
33
+ }
26
34
}
27
35
else
28
36
{
29
- sb . AppendLine ( $ "Your image file size has been reduced by ** { imageStats [ 0 ] . Percent : N0 } %** 🎉" ) ;
37
+ sb . AppendLine ( settings . PrBody ) ;
30
38
}
31
39
32
40
sb . AppendLine ( ) ;
33
- sb . AppendLine ( "<details>" ) ;
41
+ if ( settings ? . PrDetails != false )
42
+ {
43
+ sb . AppendLine ( "<details>" ) ;
34
44
35
- sb . AppendLine ( "<summary>" ) ;
36
- sb . AppendLine ( "Details" ) ;
37
- sb . AppendLine ( "</summary>" ) ;
38
- sb . AppendLine ( ) ;
45
+ sb . AppendLine ( "<summary>" ) ;
46
+ sb . AppendLine ( "Details" ) ;
47
+ sb . AppendLine ( "</summary>" ) ;
48
+ sb . AppendLine ( ) ;
39
49
40
- sb . AppendLine ( "| File | Before | After | Percent reduction |" ) ;
41
- sb . AppendLine ( "|:--|:--|:--|:--|" ) ;
50
+ sb . AppendLine ( "| File | Before | After | Percent reduction |" ) ;
51
+ sb . AppendLine ( "|:--|:--|:--|:--|" ) ;
42
52
43
- if ( imageStats . Length == 1 )
44
- {
45
- sb . AppendLine ( $ "| { imageStats [ 0 ] . Name } | { imageStats [ 0 ] . Before } | { imageStats [ 0 ] . After } | { imageStats [ 0 ] . Percent : N2} % |") ;
46
- }
47
- else
48
- {
49
- // the zeroth item is the total; we print it at the bottom of the table
50
- for ( var i = 1 ; i < imageStats . Length ; i ++ )
53
+ if ( imageStats . Length == 1 )
54
+ {
55
+ sb . AppendLine (
56
+ $ "| { imageStats [ 0 ] . Name } | { imageStats [ 0 ] . Before } | { imageStats [ 0 ] . After } | { imageStats [ 0 ] . Percent : N2} % |") ;
57
+ }
58
+ else
51
59
{
52
- sb . AppendLine ( $ "| { imageStats [ i ] . Name } | { imageStats [ i ] . Before } | { imageStats [ i ] . After } | { imageStats [ i ] . Percent : N2} % |") ;
60
+ // the zeroth item is the total; we print it at the bottom of the table
61
+ for ( var i = 1 ; i < imageStats . Length ; i ++ )
62
+ {
63
+ sb . AppendLine (
64
+ $ "| { imageStats [ i ] . Name } | { imageStats [ i ] . Before } | { imageStats [ i ] . After } | { imageStats [ i ] . Percent : N2} % |") ;
65
+ }
66
+
67
+ sb . AppendLine ( "| | | | |" ) ;
68
+ sb . AppendLine (
69
+ $ "| **Total :** | **{ imageStats [ 0 ] . Before } ** | **{ imageStats [ 0 ] . After } ** | **{ imageStats [ 0 ] . Percent : N2} %** |") ;
53
70
}
54
71
55
- sb . AppendLine ( "| | | | | " ) ;
56
- sb . AppendLine ( $ "| **Total :** | ** { imageStats [ 0 ] . Before } ** | ** { imageStats [ 0 ] . After } ** | ** { imageStats [ 0 ] . Percent : N2 } %** |" ) ;
72
+ sb . AppendLine ( "</details> " ) ;
73
+ sb . AppendLine ( ) ;
57
74
}
58
75
59
- sb . AppendLine ( "</details>" ) ;
60
- sb . AppendLine ( ) ;
61
- sb . AppendLine ( "---" ) ;
62
- sb . AppendLine ( ) ;
76
+ if ( settings ? . PrBody == null )
77
+ {
78
+ sb . AppendLine ( "---" ) ;
79
+ sb . AppendLine ( ) ;
80
+ sb . Append ( "[📝 docs](https://imgbot.net/docs) | " ) ;
81
+ sb . Append ( "[:octocat: repo](https://github.com/imgbot/ImgBot) | " ) ;
82
+ sb . Append ( "[🙋🏾 issues](https://github.com/imgbot/ImgBot/issues) | " ) ;
83
+ sb . Append ( "[🏪 marketplace](https://github.com/marketplace/imgbot)" ) ;
63
84
64
- sb . Append ( "[📝 docs](https://imgbot.net/docs) | " ) ;
65
- sb . Append ( "[:octocat: repo](https://github.com/imgbot/ImgBot) | " ) ;
66
- sb . Append ( "[🙋🏾 issues](https://github.com/imgbot/ImgBot/issues) | " ) ;
67
- sb . Append ( "[🏪 marketplace](https://github.com/marketplace/imgbot)" ) ;
85
+ sb . AppendLine ( ) ;
86
+ sb . AppendLine ( ) ;
87
+ sb . Append ( "<i>" ) ;
88
+ sb . Append ( "~Imgbot - Part of [Optimole](https://optimole.com/) family" ) ;
89
+ sb . Append ( "</i>" ) ;
90
+ sb . AppendLine ( ) ;
91
+ }
68
92
69
- sb . AppendLine ( ) ;
70
- sb . AppendLine ( ) ;
71
- sb . Append ( "<i>" ) ;
72
- sb . Append ( "~Imgbot - Part of [Optimole](https://optimole.com/) family" ) ;
73
- sb . Append ( "</i>" ) ;
74
- sb . AppendLine ( ) ;
75
93
return sb . ToString ( ) ;
76
94
}
77
95
}
0 commit comments