Skip to content
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

Allow configuration of Jira branch names #16222

Merged
merged 16 commits into from
Jan 9, 2025
3 changes: 3 additions & 0 deletions extensions/jira/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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.

Expand Down
10 changes: 10 additions & 0 deletions extensions/jira/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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}
13 changes: 12 additions & 1 deletion extensions/jira/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@
"horumy",
"santiago_perez",
"silv",
"EyLuismi"
"EyLuismi",
"pernielsentikaer",
"BehnH"
],
"pastContributors": [
"igor9silva"
Expand Down Expand Up @@ -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": {
Expand Down
6 changes: 3 additions & 3 deletions extensions/jira/src/components/IssueActions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -146,7 +146,7 @@ export default function IssueActions({
}
}

const { open_in } = getPreferenceValues<Preferences>();
const { open_in, branch_name } = getPreferenceValues<Preferences>();

return (
<ActionPanel title={issue.key}>
Expand Down Expand Up @@ -269,7 +269,7 @@ export default function IssueActions({

<Action.CopyToClipboard
title="Copy Git Branch Name"
content={`${issue.key}-${slugify(issue.fields.summary)}`}
content={generateBranchName(issue, branch_name)}
shortcut={{ modifiers: ["cmd", "shift"], key: "." }}
/>

Expand Down
18 changes: 18 additions & 0 deletions extensions/jira/src/helpers/issues.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 || "");
}