diff --git a/manifest.json b/manifest.json index 42cf9f1..59d5f0c 100644 --- a/manifest.json +++ b/manifest.json @@ -1,7 +1,7 @@ { "id": "jira-sync", "name": "Jira Issue Manager", - "version": "1.4.3", + "version": "1.4.4", "minAppVersion": "1.10.1", "description": "Get Jira issues, create and update them. Issue status and worklog management.", "author": "Alamion", diff --git a/package.json b/package.json index d15d9a1..2d81241 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "obsidian-sample-plugin", - "version": "1.4.3", + "version": "1.4.4", "description": "This is a sample plugin for Obsidian (https://obsidian.md)", "main": "main.js", "scripts": { diff --git a/src/commands/createIssue.ts b/src/commands/createIssue.ts index bc8df4a..b5f9852 100644 --- a/src/commands/createIssue.ts +++ b/src/commands/createIssue.ts @@ -11,75 +11,74 @@ import {IssueAddSummaryModal} from "../modals/IssueAddSummaryModal"; const t = useTranslations("commands.create_issue").t; -/** - * Register the create issue command - */ + export function registerCreateIssueCommand(plugin: JiraPlugin): void { plugin.addCommand({ id: "create-issue-jira", name: t("name"), checkCallback: (checking: boolean) => { - return checkCommandCallback(plugin, checking, checkProjects, []); + return checkCommandCallback(plugin, checking, createIssue, []); }, }); } -/** - * Create a new issue in Jira from the current note - */ -export async function checkProjects(plugin: JiraPlugin, file: TFile): Promise { +export async function createIssue(plugin: JiraPlugin, file: TFile): Promise { try { const fields = await readJiraFieldsFromFile(plugin, file); - - const projects = await fetchProjects(plugin); - - if (!fields.project || !projects.map((project: any) => project.key).includes(fields.project)) { - new ProjectModal(plugin.app, - projects.map((project: any) => ({ - id: project.key, - name: project.name, - })) as JiraProject[], - async (projectKey: string) => { - fields.project = projectKey; - await checkIssueTypes(plugin, file, fields) - }).open(); - } else { - await checkIssueTypes(plugin, file, fields); - } - + await checkProjects(plugin, fields); + await checkIssueTypes(plugin, fields); + await checkSummary(plugin, fields); + const issueKey = await createIssueFromFile(plugin, file, fields); + new Notice(t('success', {issueKey})); } catch (error) { new Notice(t('error') + ": " + (error.message || "Unknown error"), 3000); console.error(error); } } -async function checkIssueTypes(plugin: JiraPlugin, file: TFile, fields: any): Promise { - const issueTypes = await fetchIssueTypes(plugin, fields.project); +export async function checkProjects(plugin: JiraPlugin, fields: any): Promise { + const projects = await fetchProjects(plugin); + if (!fields.project || !projects.map((project: any) => project.key).includes(fields.project)) { + await new Promise((resolve) => { + new ProjectModal(plugin.app, + projects.map((project: any) => ({ + id: project.key, + name: project.name, + })) as JiraProject[], + async (projectKey: string) => { + fields.project = projectKey; + resolve(); + }).open(); + }); + } +} - if (!fields.issuetype || !issueTypes.values.map((issueType: any) => issueType.name).includes(fields.issuetype)) { - new IssueTypeModal(plugin.app, - issueTypes.values.map((type: any) => ({ - name: type.name, - })) as JiraIssueType[], - async (issueType: string) => { - fields.issuetype = issueType; - await checkSummary(plugin, file, fields); - }).open(); - } else { - await checkSummary(plugin, file, fields); +async function checkIssueTypes(plugin: JiraPlugin, fields: any): Promise { + const issueTypesResponse = await fetchIssueTypes(plugin, fields.project); + const issueTypes = plugin.settings.connection.apiVersion === "3" ? issueTypesResponse.issueTypes : issueTypesResponse.values; + if (!fields.issuetype || !issueTypes.map((issueType: any) => issueType.name).includes(fields.issuetype)) { + await new Promise((resolve) => { + new IssueTypeModal(plugin.app, + issueTypes.map((type: any) => ({ + name: type.name, + })) as JiraIssueType[], + async (issueType: string) => { + fields.issuetype = issueType; + resolve(); + }).open(); + }); } } -async function checkSummary(plugin: JiraPlugin, file: TFile, fields: any): Promise { +async function checkSummary(plugin: JiraPlugin, fields: any): Promise { if (!fields.summary) { - new IssueAddSummaryModal(plugin.app, - async (summary: string) => { - fields.summary = summary; - const issueKey = await createIssueFromFile(plugin, file, fields); - new Notice(t('success', {issueKey})); - }).open(); - } else { - await createIssueFromFile(plugin, file, fields); + await new Promise((resolve) => { + new IssueAddSummaryModal(plugin.app, + async (summary: string) => { + fields.summary = summary; + resolve(); + }).open(); + }); } } diff --git a/src/tools/markdownHtml.ts b/src/tools/markdownHtml.ts index 56bcda8..2a3264b 100644 --- a/src/tools/markdownHtml.ts +++ b/src/tools/markdownHtml.ts @@ -1,6 +1,3 @@ -import {Notice} from "obsidian"; - - /** * Convert Jira markup to Markdown * @param str The Jira markup string