mirror of
https://github.com/alamion/obsidian-jira-sync.git
synced 2026-07-22 05:43:04 +00:00
Refactor code to fit Obsidian guidelines.
This commit is contained in:
parent
d02fa2e435
commit
befbffed44
5 changed files with 49 additions and 27 deletions
|
|
@ -1,7 +1,7 @@
|
|||
{
|
||||
"id": "obsidian-jira-sync",
|
||||
"id": "jira-sync",
|
||||
"name": "Jira Issue Manager",
|
||||
"version": "1.1.0",
|
||||
"version": "1.1.2",
|
||||
"minAppVersion": "1.7.7",
|
||||
"description": "Get Jira issues, create and update them. Issue status and worklog management.",
|
||||
"author": "Alamion",
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
import JiraPlugin from "../main";
|
||||
import {requestUrl} from "obsidian";
|
||||
import {getAuthHeaders} from "./auth";
|
||||
import {debugLog} from "../tools/debugLogging";
|
||||
|
||||
export async function baseRequest(
|
||||
plugin: JiraPlugin,
|
||||
|
|
@ -8,24 +9,25 @@ export async function baseRequest(
|
|||
additional_url_path: string,
|
||||
body?: string
|
||||
): Promise<any> {
|
||||
return await requestUrl({
|
||||
const response = await requestUrl({
|
||||
url: `${plugin.settings.jiraUrl}/rest/api/2${additional_url_path}`,
|
||||
method: method,
|
||||
headers: getAuthHeaders(plugin),
|
||||
contentType: "application/json",
|
||||
throw: false,
|
||||
body
|
||||
}).then(response => {
|
||||
if (response.status < 200 || response.status >= 300) {
|
||||
const error = new Error(`Error updating issue:
|
||||
});
|
||||
if (response.status < 200 || response.status >= 300) {
|
||||
const error = new Error(`Error updating issue:
|
||||
${response.text || "Unknown error"}
|
||||
${body && '\nbody:' + body || ""}`);
|
||||
console.error(error);
|
||||
throw error;
|
||||
}
|
||||
console.debug(response);
|
||||
console.debug({"url": `${plugin.settings.jiraUrl}/rest/api/2${additional_url_path}`,
|
||||
"method": method, "body": body});
|
||||
return response.status === 204 ? null : response.json;
|
||||
});
|
||||
console.error(error);
|
||||
throw error;
|
||||
}
|
||||
debugLog(response);
|
||||
debugLog({"url": `${plugin.settings.jiraUrl}/rest/api/2${additional_url_path}`,
|
||||
"method": method, "body": body});
|
||||
return response.status === 204 ? null : response.json;
|
||||
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import {App, PluginSettingTab, setIcon, Setting} from "obsidian";
|
||||
import {App, normalizePath, PluginSettingTab, setIcon, Setting} from "obsidian";
|
||||
import JiraPlugin from "../main";
|
||||
import {FieldMapping, fieldMappings} from "../tools/mappingObsidianJiraFields";
|
||||
import {functionToArrowString, safeStringToFunction} from "../tools/convertFunctionString";
|
||||
|
|
@ -19,10 +19,10 @@ export class JiraSettingTab extends PluginSettingTab {
|
|||
const { containerEl } = this;
|
||||
|
||||
containerEl.empty();
|
||||
containerEl.createEl("h2", { text: "Jira Integration Settings" });
|
||||
containerEl.createEl("h2", { text: "Jira integration settings" });
|
||||
|
||||
new Setting(containerEl)
|
||||
.setName("Jira Username")
|
||||
.setName("Jira username")
|
||||
.setDesc("Your Jira username or email")
|
||||
.addText((text) =>
|
||||
text
|
||||
|
|
@ -35,7 +35,7 @@ export class JiraSettingTab extends PluginSettingTab {
|
|||
);
|
||||
|
||||
new Setting(containerEl)
|
||||
.setName("Jira Password or API Token")
|
||||
.setName("Jira password or API token")
|
||||
.setDesc("Your Jira password or API token")
|
||||
.addText((text) => {
|
||||
text.inputEl.type = "password";
|
||||
|
|
@ -62,7 +62,7 @@ export class JiraSettingTab extends PluginSettingTab {
|
|||
);
|
||||
|
||||
new Setting(containerEl)
|
||||
.setName("Issues Folder")
|
||||
.setName("Issues folder")
|
||||
.setDesc("Folder where Jira issues will be stored")
|
||||
.addText((text) =>
|
||||
text
|
||||
|
|
@ -75,7 +75,7 @@ export class JiraSettingTab extends PluginSettingTab {
|
|||
);
|
||||
|
||||
new Setting(containerEl)
|
||||
.setName("Session Cookie Name")
|
||||
.setName("Session cookie name")
|
||||
.setDesc("The name of the session cookie used by your Jira instance")
|
||||
.addText((text) =>
|
||||
text
|
||||
|
|
@ -96,16 +96,14 @@ export class JiraSettingTab extends PluginSettingTab {
|
|||
.setValue(this.plugin.settings.templatePath)
|
||||
.onChange(async (value) => {
|
||||
// Normalize path - ensure it has .md extension
|
||||
if (value && !value.toLowerCase().endsWith('.md')) {
|
||||
value = value + '.md';
|
||||
}
|
||||
value = normalizePath(value);
|
||||
this.plugin.settings.templatePath = value;
|
||||
await this.plugin.saveSettings();
|
||||
})
|
||||
);
|
||||
|
||||
// Add Jira-Obsidian Mapping setting
|
||||
containerEl.createEl("h3", { text: "Jira-Obsidian Field Mapping" });
|
||||
containerEl.createEl("h3", { text: "Jira-Obsidian field mapping" });
|
||||
|
||||
// Create Field Mappings UI
|
||||
const mappingSection = containerEl.createDiv({ cls: "jira-field-mappings" });
|
||||
|
|
@ -276,7 +274,7 @@ export class JiraSettingTab extends PluginSettingTab {
|
|||
// Load existing mappings if available
|
||||
const loadExistingMappings = () => {
|
||||
// Clear existing field list
|
||||
fieldsList.innerHTML = "";
|
||||
fieldsList.empty();
|
||||
|
||||
// If we have string representations stored, use those
|
||||
if (this.plugin.settings.fieldMappingsStrings &&
|
||||
|
|
@ -318,7 +316,7 @@ export class JiraSettingTab extends PluginSettingTab {
|
|||
|
||||
// Add example mappings section
|
||||
const examplesSection = mappingSection.createDiv({ cls: "mapping-examples" });
|
||||
examplesSection.createEl("h4", { text: "Example Field Mappings" });
|
||||
examplesSection.createEl("h4", { text: "Example field mappings" });
|
||||
|
||||
const examplesList = examplesSection.createEl("ul");
|
||||
|
||||
|
|
|
|||
20
src/tools/debugLogging.ts
Normal file
20
src/tools/debugLogging.ts
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
// Create a debug utility module (debug.ts)
|
||||
export const DEBUG_MODE = process.env.NODE_ENV !== 'production';
|
||||
|
||||
export function debugLog(...args: any[]): void {
|
||||
if (DEBUG_MODE) {
|
||||
console.log('[DEBUG]', ...args);
|
||||
}
|
||||
}
|
||||
|
||||
export function debugWarn(...args: any[]): void {
|
||||
if (DEBUG_MODE) {
|
||||
console.warn('[DEBUG WARNING]', ...args);
|
||||
}
|
||||
}
|
||||
|
||||
export function debugError(...args: any[]): void {
|
||||
if (DEBUG_MODE) {
|
||||
console.error('[DEBUG ERROR]', ...args);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,3 +1,5 @@
|
|||
import {debugLog} from "./debugLogging";
|
||||
|
||||
/**
|
||||
* Updates or adds a Jira sync section in the file content
|
||||
* @param fileContent - The current content of the file
|
||||
|
|
@ -72,7 +74,7 @@ function updateJiraSyncLine(fileContent: string, lineName: string, lineContent:
|
|||
export function extractAllJiraSyncValuesFromContent(fileContent: string): Record<string, string> {
|
||||
const sections = extractAllJiraSyncValuesFromSections(fileContent);
|
||||
const lines = extractAllJiraSyncValuesFromLines(fileContent);
|
||||
console.debug(`extracted from file: ${JSON.stringify(sections)}`);
|
||||
debugLog(`extracted from file: ${JSON.stringify(sections)}`);
|
||||
return { ...sections, ...lines };
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue