@@ -3,13 +3,32 @@ import {
3
3
EmbedBuilder ,
4
4
TextChannel ,
5
5
ThreadChannel ,
6
+ VoiceChannel ,
6
7
Message ,
7
8
} from "discord.js"
8
9
import { Log , Robot } from "hubot"
9
10
import { LinearClient } from "@linear/sdk"
10
11
11
12
const { LINEAR_API_TOKEN } = process . env
12
13
14
+ function truncateToWords (
15
+ content : string | undefined ,
16
+ ifBlank : string ,
17
+ maxWords = 50 ,
18
+ ) : string {
19
+ if ( content === undefined || content . trim ( ) === "" ) {
20
+ return ifBlank
21
+ }
22
+
23
+ const truncatedContent = content . split ( " " ) . slice ( 0 , maxWords ) . join ( " " )
24
+
25
+ if ( truncatedContent !== content ) {
26
+ return `${ truncatedContent } ...`
27
+ }
28
+
29
+ return content
30
+ }
31
+
13
32
async function createLinearEmbed (
14
33
linearClient : LinearClient ,
15
34
issueId : string ,
@@ -36,7 +55,9 @@ async function createLinearEmbed(
36
55
. setURL (
37
56
`https://linear.app/${ teamName } /issue/${ issue . identifier } #comment-${ commentId } ` ,
38
57
)
39
- . setDescription ( comment . body || "No comment body available." )
58
+ . setDescription (
59
+ truncateToWords ( comment . body , "No comment body available." , 50 ) ,
60
+ )
40
61
. addFields (
41
62
{
42
63
name : "Issue" ,
@@ -60,7 +81,9 @@ async function createLinearEmbed(
60
81
embed
61
82
. setTitle ( `Issue: ${ issue . title } ` )
62
83
. setURL ( `https://linear.app/${ teamName } /issue/${ issue . identifier } ` )
63
- . setDescription ( issue . description || "No description available." )
84
+ . setDescription (
85
+ truncateToWords ( issue . description , "No description available." , 50 ) ,
86
+ )
64
87
. addFields (
65
88
{ name : "Status" , value : state ?. name || "No status" , inline : true } ,
66
89
{
@@ -79,7 +102,11 @@ async function createLinearEmbed(
79
102
if ( comments . nodes . length > 0 ) {
80
103
embed . addFields ( {
81
104
name : "Recent Comment" ,
82
- value : comments . nodes [ 0 ] . body ,
105
+ value : truncateToWords (
106
+ comments . nodes [ 0 ] . body ,
107
+ "No recent comment." ,
108
+ 25 ,
109
+ ) ,
83
110
} )
84
111
}
85
112
}
@@ -97,7 +124,7 @@ async function createLinearEmbed(
97
124
98
125
async function processLinearEmbeds (
99
126
message : string ,
100
- channel : TextChannel | ThreadChannel ,
127
+ channel : TextChannel | ThreadChannel | VoiceChannel ,
101
128
logger : Log ,
102
129
linearClient : LinearClient ,
103
130
) {
@@ -154,7 +181,8 @@ export default function linearEmbeds(discordClient: Client, robot: Robot) {
154
181
message . author . bot ||
155
182
! (
156
183
message . channel instanceof TextChannel ||
157
- message . channel instanceof ThreadChannel
184
+ message . channel instanceof ThreadChannel ||
185
+ message . channel instanceof VoiceChannel
158
186
)
159
187
) {
160
188
return
@@ -174,7 +202,8 @@ export default function linearEmbeds(discordClient: Client, robot: Robot) {
174
202
! newMessage . content ||
175
203
! (
176
204
newMessage . channel instanceof TextChannel ||
177
- newMessage . channel instanceof ThreadChannel
205
+ newMessage . channel instanceof ThreadChannel ||
206
+ newMessage . channel instanceof VoiceChannel
178
207
) ||
179
208
newMessage . author ?. bot
180
209
) {
0 commit comments