diff --git a/extensions/jira/CHANGELOG.md b/extensions/jira/CHANGELOG.md index 798b81985f5..2d62bf26a63 100644 --- a/extensions/jira/CHANGELOG.md +++ b/extensions/jira/CHANGELOG.md @@ -1,5 +1,8 @@ # Jira Changelog +## [Add ability to configuring Git branch name format] - 2025-01-09 +- Implemented the ability to configure the Git branch name format in the extension settings. + ## [Add ability to open issues in other application defined in extension preferences] - 2024-12-25 - Implemented the ability to open by default in any other application (e.g. other browser) any issue. diff --git a/extensions/jira/README.md b/extensions/jira/README.md index afc4ba478be..628c2ae301a 100644 --- a/extensions/jira/README.md +++ b/extensions/jira/README.md @@ -8,3 +8,13 @@ The Jira extension supports OAuth authentication by default. But if you want, yo 1. Get an API token as described [here](https://support.atlassian.com/atlassian-account/docs/manage-api-tokens-for-your-atlassian-account/). 2. Select any command from the Jira extension, then press `⌘` + `K` and scroll down to `Configure Extension`. Enter your email, API token, and Jira site URL (without `https://`) on the right. Note that all three must be provided to use API tokens. + +## Note + +You can change the default `Git branch name` in preferences; the following keys are available: + +* {issueKey} +* {issueSummary} +* {issueSummaryShort} +* {issueType} +* {projectKey} \ No newline at end of file diff --git a/extensions/jira/package.json b/extensions/jira/package.json index c3c49eaedae..f18bac398ac 100644 --- a/extensions/jira/package.json +++ b/extensions/jira/package.json @@ -18,7 +18,9 @@ "horumy", "santiago_perez", "silv", - "EyLuismi" + "EyLuismi", + "pernielsentikaer", + "BehnH" ], "pastContributors": [ "igor9silva" @@ -153,6 +155,15 @@ "title": "Open Issues in", "required": false, "description": "Select the browser or application to open Issues with." + }, + { + "name": "branch_name", + "title": "Git Branch Name", + "description": "The format for copying Git branch names.\nAvailable keys: {issueKey} {issueSummary} {issueSummaryShort} {issueType} {projectKey}", + "type": "textfield", + "required": false, + "default": "{issueKey}-{issueSummary}", + "placeholder": "{issueKey}-{issueSummary}" } ], "dependencies": { diff --git a/extensions/jira/src/components/IssueActions.tsx b/extensions/jira/src/components/IssueActions.tsx index 72009509f67..eb618a16935 100644 --- a/extensions/jira/src/components/IssueActions.tsx +++ b/extensions/jira/src/components/IssueActions.tsx @@ -20,7 +20,7 @@ import { getJiraCredentials } from "../api/jiraCredentials"; import { autocompleteUsers, User } from "../api/users"; import { getUserAvatar } from "../helpers/avatars"; import { getErrorMessage } from "../helpers/errors"; -import { slugify } from "../helpers/string"; +import { generateBranchName } from "../helpers/issues"; import CreateIssueForm from "./CreateIssueForm"; import IssueAttachments from "./IssueAttachments"; @@ -146,7 +146,7 @@ export default function IssueActions({ } } - const { open_in } = getPreferenceValues(); + const { open_in, branch_name } = getPreferenceValues(); return ( @@ -269,7 +269,7 @@ export default function IssueActions({ diff --git a/extensions/jira/src/helpers/issues.ts b/extensions/jira/src/helpers/issues.ts index a181095556c..e00b0552df6 100644 --- a/extensions/jira/src/helpers/issues.ts +++ b/extensions/jira/src/helpers/issues.ts @@ -315,3 +315,21 @@ export function getCustomFieldValue(fieldSchema: CustomFieldSchema, value: unkno return null; } } + +export function generateBranchName(issue: Issue | IssueDetail, nameFormat?: string): string { + const issueKey = issue.key; + const issueSummary = issue.fields.summary.toLowerCase(); + const issueSummaryShort = issueSummary.split(" ").slice(0, 5).join("-"); + + if (!nameFormat) { + nameFormat = "{issueKey}-{issueSummary}"; + } + + // Supported fields in the Jira UI: issue key, issue summary, issue summary short, issue type, project key + return nameFormat + .replace("{issueKey}", issueKey) + .replace("{issueSummary}", issueSummary) + .replace("{issueSummaryShort}", issueSummaryShort) + .replace("{issueType}", issue.fields.issuetype.name) + .replace("{projectKey}", issue.fields.project?.key || ""); +}