Skip to content

Commit 6acf224

Browse files
author
gitstart-crowddev
authored
Exclude bots from automations (#1414)
1 parent 827a689 commit 6acf224

File tree

2 files changed

+42
-1
lines changed

2 files changed

+42
-1
lines changed

backend/src/serverless/microservices/nodejs/automation/workers/__tests__/newActivityWorker.test.ts

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,9 @@ describe('New Activity Automation Worker tests', () => {
6565
default: true,
6666
custom: true,
6767
},
68+
isBot: {
69+
default: false,
70+
},
6871
},
6972
},
7073

@@ -86,7 +89,6 @@ describe('New Activity Automation Worker tests', () => {
8689
id: '1234',
8790
type: 'comment',
8891
platform: PlatformType.DISCORD,
89-
9092
body: 'Crowd.dev is awesome!',
9193
}
9294

@@ -129,6 +131,35 @@ describe('New Activity Automation Worker tests', () => {
129131
expect(await shouldProcessActivity(activity, automation)).toBeFalsy()
130132
})
131133

134+
it("Shouldn't process an activity that belongs to a bot", async () => {
135+
const automation = createAutomationData({
136+
platforms: [PlatformType.DEVTO],
137+
types: ['comment'],
138+
keywords: ['Crowd.dev'],
139+
teamMemberActivities: false,
140+
})
141+
142+
const activity = {
143+
id: '1234',
144+
type: 'comment',
145+
platform: PlatformType.DEVTO,
146+
member: {
147+
attributes: {
148+
isTeamMember: {
149+
default: false,
150+
custom: true,
151+
},
152+
isBot: {
153+
default: true,
154+
},
155+
},
156+
},
157+
body: 'Crowd.dev all awesome!',
158+
}
159+
160+
expect(await shouldProcessActivity(activity, automation)).toBeFalsy()
161+
})
162+
132163
it("Shouldn't process an activity that belongs to a team member", async () => {
133164
const automation = createAutomationData({
134165
platforms: [PlatformType.DEVTO],
@@ -147,6 +178,9 @@ describe('New Activity Automation Worker tests', () => {
147178
default: true,
148179
custom: true,
149180
},
181+
isBot: {
182+
default: false,
183+
},
150184
},
151185
},
152186
body: 'Crowd.dev all awesome!',

backend/src/serverless/microservices/nodejs/automation/workers/newActivityWorker.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,13 @@ export const shouldProcessActivity = async (
7979
process = false
8080
}
8181

82+
if (activity?.member?.attributes?.isBot && activity?.member?.attributes?.isBot.default) {
83+
log.warn(
84+
`Ignoring automation ${automation.id} - Activity ${activity.id} belongs to a bot, cannot be processed automaticaly!`,
85+
)
86+
process = false
87+
}
88+
8289
if (process) {
8390
const userContext = await SequelizeRepository.getDefaultIRepositoryOptions()
8491
const repo = new AutomationExecutionRepository(userContext)

0 commit comments

Comments
 (0)