Skip to content

GitAuto: Listen jira issue webhook event on this Jira Forge App #19

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
7 changes: 7 additions & 0 deletions manifest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
20 changes: 20 additions & 0 deletions src/webhookHandlers.js
Original file line number Diff line number Diff line change
@@ -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;
27 changes: 27 additions & 0 deletions src/webhookHandlers.test.js
Original file line number Diff line number Diff line change
@@ -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();
});
});
Loading