Skip to content

Conversation

@devmaster-x
Copy link

@devmaster-x devmaster-x commented Jan 12, 2026

Related Issues

close #1201

What is updated

Notify about new issues/bounties to the slack channel using webhook.

Screentshot

image

Test

image

@dosubot dosubot bot added the slack trigger to slack channel label Jan 12, 2026
Copy link
Member

@alexanmtz alexanmtz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's doing great @devmaster-x 👌

Tested posting to the channel, and it's working well 🙏

Just need some small adjustment for the case of the issue imported is set to not_listed

I would recommend to add to the tasks tests a spy which checks if the Slack method is called, and it's not called in case for tasks with not_listed set.

if (userData.receiveNotifications) {
TaskMail.new(userData, taskData)
}
issueAddedComment(task)
Copy link
Member

@alexanmtz alexanmtz Jan 13, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should check here before calling issueAddedComment whether the issue is not_listed or private; in that case, it shouldn't be added to the channel.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@alexanmtz

Updated code to check not_listed and private issues before calling issueAddedComment().

 const isTaskPublic = !(taskData.not_listed === true || taskData.private === true)
  if (isTaskPublic) {
    issueAddedComment(task)
    notifyNewIssue(taskData, userData)
  }

const percentage = orderCreated.Plan?.feePercentage

// Notify Slack about new bounty
if (orderCreated.Task && orderCreated.User) {
Copy link
Member

@alexanmtz alexanmtz Jan 13, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't post on the channel if the related task is set to not_listed or private

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@alexanmtz

Updated code to check not_listed and private issues before notify about new bounty.

 const shouldNotifySlack =
    orderCreated.Task &&
    orderCreated.User &&
    !(
      orderCreated.Task.dataValues.not_listed === true ||
      orderCreated.Task.dataValues.private === true
    )

  if (shouldNotifySlack) {
    notifyNewBounty(
      orderCreated.Task.dataValues,
      orderCreated.dataValues,
      orderCreated.User.dataValues
    )
  }

@devmaster-x devmaster-x force-pushed the feat/post-slack-notifications branch from e1d86a3 to 4b1448e Compare January 14, 2026 16:21
@devmaster-x devmaster-x requested a review from alexanmtz January 14, 2026 16:45
Copy link
Member

@alexanmtz alexanmtz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @devmaster-x, some more improvements are needed to have everything in place to merge.

Comment on lines +25 to +41
.then(async (updatedOrder) => {
if (orderParameters.plan === 'full') {
PaymentMail.support(user, task, order)
}
PaymentMail.success(user, task, order.amount)

// Send Slack notification for new bounty payment
if (orderPayload.paid && orderPayload.status === 'succeeded') {
const orderData = {
amount: order.amount || orderParameters.amount,
currency: order.currency || orderParameters.currency || 'USD'
}
notifyNewBounty(task.dataValues, orderData, user).catch((e) => {
console.log('error on send slack notification for new bounty', e)
})
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@devmaster-x because you introduced async it should be something like this?

Suggested change
.then(async (updatedOrder) => {
if (orderParameters.plan === 'full') {
PaymentMail.support(user, task, order)
}
PaymentMail.success(user, task, order.amount)
// Send Slack notification for new bounty payment
if (orderPayload.paid && orderPayload.status === 'succeeded') {
const orderData = {
amount: order.amount || orderParameters.amount,
currency: order.currency || orderParameters.currency || 'USD'
}
notifyNewBounty(task.dataValues, orderData, user).catch((e) => {
console.log('error on send slack notification for new bounty', e)
})
}
.then(async (updatedOrder) => {
if (orderParameters.plan === 'full') {
PaymentMail.support(user, task, order)
}
PaymentMail.success(user, task, order.amount)
// Send Slack notification for new bounty payment
if (orderPayload.paid && orderPayload.status === 'succeeded') {
const orderData = {
amount: order.amount || orderParameters.amount,
currency: order.currency || orderParameters.currency || 'USD'
}
try {
await notifyNewBounty(task.dataValues, orderData, user)
} catch (e) {
console.log('error on send slack notification for new bounty', e)
}
}

Comment on lines +225 to +335
it('should not call Slack methods when task is created with not_listed set to true', async () => {
chai.use(spies)
const slackModule = require('../src/modules/slack')
const slackSpy = chai.spy.on(slackModule, 'notifyNewIssue')
const originalBotModule = require('../src/modules/bot/issueAddedComment')
const botSpy = chai.spy(originalBotModule)

try {
const user = await registerAndLogin(agent)
const task = await models.Task.create({
url: 'https://github.com/worknenjoy/gitpay/issues/999',
provider: 'github',
userId: user.body.id,
title: 'Test Task',
not_listed: true
})

const userData = await task.getUser()
const taskData = task.dataValues

// Test the actual logic from taskBuilds.js
const isTaskPublic = !(taskData.not_listed === true || taskData.private === true)
if (isTaskPublic) {
botSpy(task)
slackModule.notifyNewIssue(taskData, userData)
}

expect(slackSpy).to.not.have.been.called()
expect(botSpy).to.not.have.been.called()
} finally {
chai.spy.restore(slackModule, 'notifyNewIssue')
}
})

it('should not call Slack methods when task is created with private set to true', async () => {
chai.use(spies)
const slackModule = require('../src/modules/slack')
const slackSpy = chai.spy.on(slackModule, 'notifyNewIssue')
const originalBotModule = require('../src/modules/bot/issueAddedComment')
const botSpy = chai.spy(originalBotModule)

try {
const user = await registerAndLogin(agent)
const task = await models.Task.create({
url: 'https://github.com/worknenjoy/gitpay/issues/998',
provider: 'github',
userId: user.body.id,
title: 'Test Task',
private: true
})

const userData = await task.getUser()
const taskData = task.dataValues

// Test the actual logic from taskBuilds.js
const isTaskPublic = !(taskData.not_listed === true || taskData.private === true)
if (isTaskPublic) {
botSpy(task)
slackModule.notifyNewIssue(taskData, userData)
}

expect(slackSpy).to.not.have.been.called()
expect(botSpy).to.not.have.been.called()
} finally {
chai.spy.restore(slackModule, 'notifyNewIssue')
}
})

it('should call Slack methods when task is created as public', async () => {
chai.use(spies)

// Set up spies first
const slackModule = require('../src/modules/slack')
const slackSpy = chai.spy.on(slackModule, 'notifyNewIssue')

// For default export function, create a spy wrapper
delete require.cache[require.resolve('../src/modules/bot/issueAddedComment')]
const originalBotModule = require('../src/modules/bot/issueAddedComment')
const botSpy = chai.spy(originalBotModule)

try {
const user = await registerAndLogin(agent)
// Create task without explicitly setting not_listed/private (should default to false)
const task = await models.Task.create({
url: 'https://github.com/worknenjoy/gitpay/issues/997',
provider: 'github',
userId: user.body.id,
title: 'Test Task'
})

const userData = await task.getUser()
const taskData = task.dataValues

// Test the actual logic from taskBuilds.js
const isTaskPublic = !(taskData.not_listed === true || taskData.private === true)
if (isTaskPublic) {
// Use the spied version
botSpy(task)
slackModule.notifyNewIssue(taskData, userData)
}

expect(slackSpy).to.have.been.called()
expect(botSpy).to.have.been.called()
} finally {
chai.spy.restore(slackModule, 'notifyNewIssue')
// Restore cache
delete require.cache[require.resolve('../src/modules/slack')]
delete require.cache[require.resolve('../src/modules/bot/issueAddedComment')]
}
})

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess here is not the right approach to test the integration. This should be more like an API testing, check other tests in the file, like calling the agent to the endpoint to create a new task and check if the Slack is called, and instead of these spies, there's a good example of an approach using Stubs on userAuth.test:242, so you can check if your integration is called and the expected params

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

slack trigger to slack channel

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature] Post new issues imported to Gitpay or bounties to our Slack Channel

2 participants