diff --git a/README.md b/README.md index 7e400b2..031758d 100644 --- a/README.md +++ b/README.md @@ -19,6 +19,21 @@ See [Set up Forge](https://developer.atlassian.com/platform/forge/set-up-forge/) ```shell forge lint --fix forge deploy + +## Webhook Feature + +This app now supports listening to Jira issue webhook events, allowing it to respond in real-time to changes in Jira issues. This feature enables automated workflows, notifications, and enhanced interactivity for users. + +### Configuration + +1. **Webhook Subscription**: The app is configured to subscribe to Jira webhook events such as issue creation, updates, and deletions. This is set up in the `manifest.yml` file. + +2. **Event Handlers**: Event handlers are implemented in the `src/webhookHandlers.js` file. These handlers parse the event payloads and execute corresponding actions. + +3. **Permissions**: Ensure that the app has the necessary permissions by checking the `manifest.yml` file. The required scopes include `read:jira-work` and `manage:jira-webhook`. + +### Testing + ``` - Install your app in an Atlassian site by running: diff --git a/manifest.yml b/manifest.yml index fdc4e2f..e10c237 100644 --- a/manifest.yml +++ b/manifest.yml @@ -36,12 +36,19 @@ app: permissions: scopes: - read:jira-work + - manage:jira-webhook external: fetch: backend: - https://dkrxtcbaqzrodvsagwwn.supabase.co - https://awegqusxzsmlgxaxyyrq.supabase.co +modules: + jira:issueEvent: + - key: issue-created + events: + - avi:jira:created:issue + - key: issue-updated # https://developer.atlassian.com/platform/forge/manifest-reference/variables/ environment: variables: diff --git a/src/webhookHandlers.js b/src/webhookHandlers.js new file mode 100644 index 0000000..c15cbef --- /dev/null +++ b/src/webhookHandlers.js @@ -0,0 +1,20 @@ +import Resolver from '@forge/resolver'; + +const resolver = new Resolver(); + +resolver.define('issue-created', async ({ payload }) => { + console.log('Issue created:', payload); + // Add your logic for handling issue creation +}); + +resolver.define('issue-updated', async ({ payload }) => { + console.log('Issue updated:', payload); + // Add your logic for handling issue updates +}); + +resolver.define('issue-deleted', async ({ payload }) => { + console.log('Issue deleted:', payload); + // Add your logic for handling issue deletions +}); + +export default resolver; diff --git a/src/webhookHandlers.test.js b/src/webhookHandlers.test.js new file mode 100644 index 0000000..d6fb08f --- /dev/null +++ b/src/webhookHandlers.test.js @@ -0,0 +1,27 @@ +import resolver from './webhookHandlers'; + +describe('Webhook Handlers', () => { + it('should handle issue-created event', async () => { + const payload = { issue: { id: '1', key: 'TEST-1' } }; + const consoleSpy = jest.spyOn(console, 'log'); + await resolver.get('issue-created')({ payload }); + expect(consoleSpy).toHaveBeenCalledWith('Issue created:', payload); + consoleSpy.mockRestore(); + }); + + it('should handle issue-updated event', async () => { + const payload = { issue: { id: '1', key: 'TEST-1' } }; + const consoleSpy = jest.spyOn(console, 'log'); + await resolver.get('issue-updated')({ payload }); + expect(consoleSpy).toHaveBeenCalledWith('Issue updated:', payload); + consoleSpy.mockRestore(); + }); + + it('should handle issue-deleted event', async () => { + const payload = { issue: { id: '1', key: 'TEST-1' } }; + const consoleSpy = jest.spyOn(console, 'log'); + await resolver.get('issue-deleted')({ payload }); + expect(consoleSpy).toHaveBeenCalledWith('Issue deleted:', payload); + consoleSpy.mockRestore(); + }); +});