-
Notifications
You must be signed in to change notification settings - Fork 5
feat: implement Jira integration for PR handling #44
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
base: main
Are you sure you want to change the base?
Changes from 2 commits
36f990f
65ea29f
e581782
a038ad5
f5bece6
0fd258d
622f89c
a6ca420
6674c2c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,135 @@ | ||||||||||||
| import { Context } from 'probot'; | ||||||||||||
|
|
||||||||||||
| interface HandleJiraArg { | ||||||||||||
| context: Context; | ||||||||||||
| boardName: string; | ||||||||||||
| pr: { | ||||||||||||
| number: number; | ||||||||||||
| title: string; | ||||||||||||
| body: string | null; | ||||||||||||
| html_url: string; | ||||||||||||
| labels: string[]; | ||||||||||||
| user?: { | ||||||||||||
| login?: string; | ||||||||||||
| } | null; | ||||||||||||
| }; | ||||||||||||
| requestedBy: string; | ||||||||||||
| commentId: number; | ||||||||||||
| } | ||||||||||||
|
|
||||||||||||
| const getEnv = (name: string): string => { | ||||||||||||
| const value = process.env[name]; | ||||||||||||
|
|
||||||||||||
| if (!value?.trim()) { | ||||||||||||
| throw new Error(`Missing required env var: ${name}`); | ||||||||||||
| } | ||||||||||||
|
|
||||||||||||
| return value.trim(); | ||||||||||||
| }; | ||||||||||||
|
|
||||||||||||
| export const handleJira = async ({ context, boardName, pr, requestedBy, commentId }: HandleJiraArg): Promise<string> => { | ||||||||||||
| const jiraBaseUrl = getEnv('JIRA_BASE_URL').replace(/\/$/, ''); | ||||||||||||
| const jiraApiToken = getEnv('JIRA_API_TOKEN'); | ||||||||||||
| const hasCommunityLabel = pr.labels.some((label) => label.toLowerCase() === 'community'); | ||||||||||||
|
|
||||||||||||
| const payload = { | ||||||||||||
| fields: { | ||||||||||||
| project: { | ||||||||||||
| key: boardName, | ||||||||||||
| }, | ||||||||||||
| summary: `[PR #${pr.number}] ${pr.title}`, | ||||||||||||
| issuetype: { | ||||||||||||
| name: 'Task', | ||||||||||||
| }, | ||||||||||||
| ...(hasCommunityLabel ? { labels: ['community'] } : {}), | ||||||||||||
| description: { | ||||||||||||
| type: 'doc', | ||||||||||||
| version: 1, | ||||||||||||
| content: [ | ||||||||||||
| { | ||||||||||||
| type: 'paragraph', | ||||||||||||
| content: [ | ||||||||||||
| { | ||||||||||||
| type: 'text', | ||||||||||||
| text: 'Task automatically created by dionisio-bot.', | ||||||||||||
| }, | ||||||||||||
| ], | ||||||||||||
| }, | ||||||||||||
| { | ||||||||||||
| type: 'paragraph', | ||||||||||||
| content: [ | ||||||||||||
| { | ||||||||||||
| type: 'text', | ||||||||||||
| text: `PR: ${pr.html_url}`, | ||||||||||||
| }, | ||||||||||||
| ], | ||||||||||||
| }, | ||||||||||||
| { | ||||||||||||
| type: 'paragraph', | ||||||||||||
| content: [ | ||||||||||||
| { | ||||||||||||
| type: 'text', | ||||||||||||
| text: `PR description: ${pr.body?.trim() || 'no description'}`, | ||||||||||||
| }, | ||||||||||||
| ], | ||||||||||||
| }, | ||||||||||||
| { | ||||||||||||
| type: 'paragraph', | ||||||||||||
| content: [ | ||||||||||||
| { | ||||||||||||
| type: 'text', | ||||||||||||
| text: `PR author: ${pr.user?.login ?? 'unknown'}`, | ||||||||||||
| }, | ||||||||||||
| ], | ||||||||||||
| }, | ||||||||||||
| { | ||||||||||||
| type: 'paragraph', | ||||||||||||
| content: [ | ||||||||||||
| { | ||||||||||||
| type: 'text', | ||||||||||||
| text: `Requested by: ${requestedBy}`, | ||||||||||||
| }, | ||||||||||||
| ], | ||||||||||||
| }, | ||||||||||||
| ], | ||||||||||||
| }, | ||||||||||||
| }, | ||||||||||||
| }; | ||||||||||||
|
|
||||||||||||
| const response = await fetch(`${jiraBaseUrl}/rest/api/3/issue`, { | ||||||||||||
| method: 'POST', | ||||||||||||
| headers: { | ||||||||||||
| 'Authorization': `Basic ${jiraApiToken}`, | ||||||||||||
| 'Accept': 'application/json', | ||||||||||||
| 'Content-Type': 'application/json', | ||||||||||||
| }, | ||||||||||||
| body: JSON.stringify(payload), | ||||||||||||
| }); | ||||||||||||
|
|
||||||||||||
| if (!response.ok) { | ||||||||||||
| const body = await response.text(); | ||||||||||||
| throw new Error(`Jira request failed (${response.status}): ${body}`); | ||||||||||||
| } | ||||||||||||
| const task = (await response.json()) as { key?: string }; | ||||||||||||
|
|
||||||||||||
| await context.octokit.issues.update({ | ||||||||||||
| ...context.issue(), | ||||||||||||
| body: `${pr.body?.trim() || 'no description'} \n\n Task: [${task.key}]`, | ||||||||||||
| }); | ||||||||||||
|
Comment on lines
+129
to
+132
|
||||||||||||
|
|
||||||||||||
| const data = (await response.json()) as { key?: string }; | ||||||||||||
| const issueKey = data.key; | ||||||||||||
|
|
||||||||||||
|
||||||||||||
| if (!issueKey) { | ||||||||||||
| throw new Error('Jira response did not return issue key'); | ||||||||||||
| } | ||||||||||||
|
|
||||||||||||
| const issueUrl = `${jiraBaseUrl}/browse/${issueKey}`; | ||||||||||||
|
|
||||||||||||
| await context.octokit.reactions.createForIssueComment({ | ||||||||||||
| ...context.issue(), | ||||||||||||
| comment_id: commentId, | ||||||||||||
| content: '+1', | ||||||||||||
| }); | ||||||||||||
|
||||||||||||
| await context.octokit.reactions.createForIssueComment({ | |
| ...context.issue(), | |
| comment_id: commentId, | |
| content: '+1', | |
| }); |
| Original file line number | Diff line number | Diff line change | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -5,6 +5,7 @@ import { handleBackport } from './handleBackport'; | |||||||||||||
| import { run } from './Queue'; | ||||||||||||||
| import { consoleProps } from './createPullRequest'; | ||||||||||||||
| import { handleRebase } from './handleRebase'; | ||||||||||||||
| import { handleJira } from './handleJira'; | ||||||||||||||
|
|
||||||||||||||
| export = (app: Probot) => { | ||||||||||||||
| app.log.useLevelLabels = false; | ||||||||||||||
|
|
@@ -214,6 +215,55 @@ export = (app: Probot) => { | |||||||||||||
| ); | ||||||||||||||
| } | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| if (command === 'jira' && args?.trim()) { | ||||||||||||||
| const boardName = args.trim().replace(/^["']|["']$/g, ''); | ||||||||||||||
|
|
||||||||||||||
| await context.octokit.reactions.createForIssueComment({ | ||||||||||||||
| ...context.issue(), | ||||||||||||||
| comment_id: comment.id, | ||||||||||||||
| content: 'eyes', | ||||||||||||||
| }); | ||||||||||||||
|
|
||||||||||||||
| try { | ||||||||||||||
| await handleJira({ | ||||||||||||||
| context, | ||||||||||||||
| boardName, | ||||||||||||||
| pr: { | ||||||||||||||
| number: pr.data.number, | ||||||||||||||
| title: pr.data.title, | ||||||||||||||
| body: pr.data.body, | ||||||||||||||
| html_url: pr.data.html_url, | ||||||||||||||
| labels: pr.data.labels.map((label) => label.name), | ||||||||||||||
| user: pr.data.user, | ||||||||||||||
| }, | ||||||||||||||
| requestedBy: comment.user.login, | ||||||||||||||
| commentId: comment.id, | ||||||||||||||
| }); | ||||||||||||||
|
||||||||||||||
|
|
||||||||||||||
| await context.octokit.reactions.createForIssueComment({ | ||||||||||||||
| ...context.issue(), | ||||||||||||||
| comment_id: comment.id, | ||||||||||||||
| content: '+1', | ||||||||||||||
| }); | ||||||||||||||
|
||||||||||||||
| await context.octokit.reactions.createForIssueComment({ | |
| ...context.issue(), | |
| comment_id: comment.id, | |
| content: '+1', | |
| }); |
Outdated
Copilot
AI
Feb 12, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Comment says "thinking face" but the reaction used is confused. Update the comment to match the actual reaction (or change the reaction if a different one was intended).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Given the code sends
Authorization: Basic ${JIRA_API_TOKEN}, it’s unclear what exact format the env var should contain (raw API token vs base64-encodedemail:token). Add a short comment in the example env file describing the expected format (and any additional required Jira identity like email) to prevent misconfiguration.