A Cloudflare Worker that integrates Devin.ai with JIRA and Slack, enabling automated ticket monitoring and one-way communication from JIRA to Slack. Devin handles all JIRA updates directly.
- Automated JIRA ticket monitoring
- Slack integration for ticket notifications
- One-way communication from JIRA to Slack
- Duplicate ticket prevention
- Thread-based conversations in Slack
- Cloudflare Workers account
- JIRA account with API access
- Slack workspace with bot integration
- Node.js (v18 or later)
- Wrangler CLI (v3 or later) - Install with
npx wrangler
-
Clone the repository:
git clone https://github.com/bradmb/d2j.git cd d2j
-
Install dependencies:
npm install
-
Configure environment variables: Create a
.dev.vars
file in the project root with the following variables:JIRA_URL=your-domain.atlassian.net JIRA_EMAIL=your-jira-email@example.com JIRA_API_TOKEN=your-jira-api-token JIRA_ACCOUNT_ID=your-jira-account-id SLACK_TOKEN=xoxb-your-slack-bot-token SLACK_SIGNING_SECRET=your-slack-signing-secret SLACK_CHANNEL=your-slack-channel-id DEVIN_USER_ID=your-devin-bot-user-id
-
Set up the D1 database:
# Create a new D1 database npx wrangler d1 create d2j # Update wrangler.toml with the database ID from the output above # Replace the "placeholder" value in the [[d1_databases]] section
-
Initialize the database schema:
# For local development npx wrangler d1 execute d2j --local --file=./schema.sql # For production deployment npx wrangler d1 execute d2j --remote --file=./schema.sql
Note: If you encounter a "no such table" error when running the worker:
- Verify that the schema was deployed successfully using:
# List tables in local development npx wrangler d1 execute d2j --local --command "SELECT name FROM sqlite_master WHERE type='table';" # List tables in production npx wrangler d1 execute d2j --command "SELECT name FROM sqlite_master WHERE type='table';"
- If tables are missing, re-run the schema deployment command for your environment
- For local development, you may need to restart the worker after schema changes
- Verify that the schema was deployed successfully using:
-
Run the development server:
npm run dev
-
Build the project:
npm run build
-
Deploy to Cloudflare Workers:
npm run deploy
The worker automatically monitors JIRA for:
- New tickets assigned to Devin
- Comments mentioning Devin (using
@mention
) - Ticket updates and status changes
The worker creates and manages Slack threads for each JIRA ticket:
- New tickets create new Slack messages
- JIRA comments are added to the corresponding Slack thread
- Devin receives notifications and instructions to update JIRA directly
-
JIRA Setup:
- Go to your Atlassian Account Settings
- Click on "Security" in the left sidebar
- Under "API token", click "Create and manage API tokens"
- Click "Create API token", give it a name (e.g., "D2J Integration")
- Copy the generated token - this is your
JIRA_API_TOKEN
- To find your
JIRA_ACCOUNT_ID
:- Log in to JIRA
- Click on your profile picture in the top-right
- Click "Profile"
- Your account ID is in the URL:
https://your-domain.atlassian.net/jira/people/YOUR-ACCOUNT-ID
-
JIRA Credentials Secret:
- Create a key-value secret with the following structure:
URL
: Your JIRA instance URL (e.g., companyname.atlassian.net)Username
: Your JIRA email addressPassword
: Your JIRA password
- Create a key-value secret with the following structure:
-
JIRA API Token Secret:
- Create a plain-text secret with the JIRA API token so Devin can use the REST API to access/update the ticket
-
Slack Setup:
- Go to Slack API Apps page
- Click "Create New App" → "From scratch"
- Choose a name and workspace
- Under "Basic Information":
- Find "Signing Secret" - this is your
SLACK_SIGNING_SECRET
- Find "Signing Secret" - this is your
- Go to "OAuth & Permissions":
- Under "Bot Token Scopes", add required permissions:
chat:write
channels:history
groups:history
- Install the app to your workspace
- Copy "Bot User OAuth Token" - this is your
SLACK_TOKEN
- Under "Bot Token Scopes", add required permissions:
- To find the
DEVIN_USER_ID
:- Right-click on Devin's name in Slack
- Click "View profile"
- Click the "•••" (more actions) button
- Click "Copy member ID"
-
Cloudflare Setup:
- Configure the worker with appropriate memory and CPU limits
- Set up scheduled triggers (default: every 15 minutes)
- Configure environment variables in the Cloudflare dashboard using
npx wrangler secret put
- Use TypeScript for all new code
- Follow the existing code structure
- Add appropriate error handling
- Update tests for new features
- Keep the
node_modules
directory in.gitignore
The application consists of three main components:
-
JIRA Service (
src/jira.ts
):- Handles JIRA API interactions for reading tickets and comments
- Processes attachments
- Monitors ticket assignments and mentions
-
Slack Service (
src/utils/slack.ts
):- Manages Slack message threading
- Sends notifications about JIRA updates
- Maintains thread mappings for organizing conversations
-
Worker (
src/worker.ts
):- Coordinates between services
- Handles scheduled JIRA monitoring
- Processes incoming events
- Create a feature branch
- Make your changes
- Run tests and linting
- Submit a pull request