mirror of
https://github.com/kovah/obsidian-jira-auto-linker.git
synced 2026-07-22 06:45:27 +00:00
Add a first working draft for the plugin
This commit is contained in:
parent
25b9f5f3cf
commit
de77adc8f4
20 changed files with 3765 additions and 0 deletions
17
.editorconfig
Normal file
17
.editorconfig
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
# top-most EditorConfig file
|
||||
root = true
|
||||
|
||||
[*]
|
||||
charset = utf-8
|
||||
end_of_line = lf
|
||||
insert_final_newline = true
|
||||
indent_style = tab
|
||||
indent_size = 4
|
||||
tab_width = 4
|
||||
|
||||
[*.md]
|
||||
trim_trailing_whitespace = false
|
||||
|
||||
[{*.yml,*.yaml}]
|
||||
indent_size = 2
|
||||
tab_width = 2
|
||||
3
.eslintignore
Normal file
3
.eslintignore
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
node_modules/
|
||||
|
||||
main.js
|
||||
23
.eslintrc
Normal file
23
.eslintrc
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
{
|
||||
"root": true,
|
||||
"parser": "@typescript-eslint/parser",
|
||||
"env": { "node": true },
|
||||
"plugins": [
|
||||
"@typescript-eslint"
|
||||
],
|
||||
"extends": [
|
||||
"eslint:recommended",
|
||||
"plugin:@typescript-eslint/eslint-recommended",
|
||||
"plugin:@typescript-eslint/recommended"
|
||||
],
|
||||
"parserOptions": {
|
||||
"sourceType": "module"
|
||||
},
|
||||
"rules": {
|
||||
"no-unused-vars": "off",
|
||||
"@typescript-eslint/no-unused-vars": ["error", { "args": "none" }],
|
||||
"@typescript-eslint/ban-ts-comment": "off",
|
||||
"no-prototype-builtins": "off",
|
||||
"@typescript-eslint/no-empty-function": "off"
|
||||
}
|
||||
}
|
||||
3
.github/FUNDING.yml
vendored
Normal file
3
.github/FUNDING.yml
vendored
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
github: kovah
|
||||
patreon: Kovah
|
||||
liberapay: kovah
|
||||
14
.github/dependabot.yml
vendored
Normal file
14
.github/dependabot.yml
vendored
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
version: 2
|
||||
updates:
|
||||
- package-ecosystem: "npm"
|
||||
directory: "/"
|
||||
schedule:
|
||||
interval: "weekly"
|
||||
groups:
|
||||
npm-major:
|
||||
update-types:
|
||||
- "major"
|
||||
npm-minor:
|
||||
update-types:
|
||||
- "minor"
|
||||
- "patch"
|
||||
37
.github/workflows/build-release.yml
vendored
Normal file
37
.github/workflows/build-release.yml
vendored
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
name: Release Obsidian plugin
|
||||
|
||||
on:
|
||||
push:
|
||||
tags:
|
||||
- "*"
|
||||
|
||||
jobs:
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
permissions:
|
||||
contents: write
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
|
||||
- name: Use Node.js
|
||||
uses: actions/setup-node@v3
|
||||
with:
|
||||
node-version: "22.x"
|
||||
|
||||
- name: Build plugin
|
||||
run: |
|
||||
npm ci
|
||||
npm run build
|
||||
|
||||
- name: Create release
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
run: |
|
||||
tag="${GITHUB_REF#refs/tags/}"
|
||||
|
||||
zip jira-linker-${{ github.ref_name }}.zip main.js manifest.json styles.css LICENSE README.md
|
||||
|
||||
gh release create "$tag" \
|
||||
--title="$tag" \
|
||||
--draft \
|
||||
main.js manifest.json styles.css jira-linker-${{ github.ref_name }}.zip
|
||||
20
.github/workflows/test.yml
vendored
Normal file
20
.github/workflows/test.yml
vendored
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
name: Test package building
|
||||
|
||||
on:
|
||||
pull_request:
|
||||
|
||||
jobs:
|
||||
test:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
|
||||
- name: Use Node.js
|
||||
uses: actions/setup-node@v3
|
||||
with:
|
||||
node-version: "22.x"
|
||||
|
||||
- name: Build plugin
|
||||
run: |
|
||||
npm ci
|
||||
npm run build
|
||||
23
.gitignore
vendored
Normal file
23
.gitignore
vendored
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
# vscode
|
||||
.vscode
|
||||
|
||||
# Intellij
|
||||
*.iml
|
||||
.idea
|
||||
|
||||
# npm
|
||||
node_modules
|
||||
|
||||
# Don't include the compiled main.js file in the repo.
|
||||
# They should be uploaded to GitHub releases instead.
|
||||
main.js
|
||||
styles.css
|
||||
|
||||
# Exclude sourcemaps
|
||||
*.map
|
||||
|
||||
# obsidian
|
||||
data.json
|
||||
|
||||
# Exclude macOS Finder (System Explorer) View States
|
||||
.DS_Store
|
||||
1
.npmrc
Normal file
1
.npmrc
Normal file
|
|
@ -0,0 +1 @@
|
|||
tag-version-prefix=""
|
||||
7
LICENSE
Normal file
7
LICENSE
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
Copyright © 2025 Kevin Woblick <contact@kovah.de>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
55
esbuild.config.mjs
Normal file
55
esbuild.config.mjs
Normal file
|
|
@ -0,0 +1,55 @@
|
|||
import builtins from 'builtin-modules';
|
||||
import esbuild from 'esbuild';
|
||||
import { sassPlugin } from 'esbuild-sass-plugin';
|
||||
import process from 'process';
|
||||
|
||||
const banner =
|
||||
`/*
|
||||
Atlassian Jira Linker
|
||||
Copyright © 2025 Kevin Woblick <contact@kovah.de>
|
||||
THIS IS A GENERATED/BUNDLED FILE BY ESBUILD
|
||||
if you want to view the source, please visit the github repository of this plugin
|
||||
*/
|
||||
`;
|
||||
|
||||
const prod = (process.argv[2] === 'production');
|
||||
|
||||
const context = await esbuild.context({
|
||||
banner: {
|
||||
js: banner,
|
||||
css: banner
|
||||
},
|
||||
entryPoints: ['main.ts', 'styles.scss'],
|
||||
bundle: true,
|
||||
external: [
|
||||
'obsidian',
|
||||
'electron',
|
||||
'@codemirror/autocomplete',
|
||||
'@codemirror/collab',
|
||||
'@codemirror/commands',
|
||||
'@codemirror/language',
|
||||
'@codemirror/lint',
|
||||
'@codemirror/search',
|
||||
'@codemirror/state',
|
||||
'@codemirror/view',
|
||||
'@lezer/common',
|
||||
'@lezer/highlight',
|
||||
'@lezer/lr',
|
||||
...builtins
|
||||
],
|
||||
format: 'cjs',
|
||||
target: 'es2018',
|
||||
logLevel: 'info',
|
||||
sourcemap: prod ? false : 'inline',
|
||||
treeShaking: true,
|
||||
outdir: '.',
|
||||
minify: prod,
|
||||
plugins: [sassPlugin()]
|
||||
});
|
||||
|
||||
if (prod) {
|
||||
await context.rebuild();
|
||||
process.exit(0);
|
||||
} else {
|
||||
await context.watch();
|
||||
}
|
||||
173
main.ts
Normal file
173
main.ts
Normal file
|
|
@ -0,0 +1,173 @@
|
|||
import {App, MarkdownPostProcessorContext, Plugin, PluginSettingTab, Setting} from 'obsidian';
|
||||
|
||||
interface JiraProjectRegistration {
|
||||
projectKey: string,
|
||||
baseUrl: string
|
||||
}
|
||||
|
||||
interface JiraLinkerSettings {
|
||||
registrations: Array<JiraProjectRegistration>;
|
||||
}
|
||||
|
||||
const DEFAULT_SETTINGS: JiraLinkerSettings = {
|
||||
registrations: [],
|
||||
};
|
||||
|
||||
export default class JiraLinker extends Plugin {
|
||||
settings: JiraLinkerSettings;
|
||||
|
||||
async onload() {
|
||||
await this.loadSettings();
|
||||
this.addSettingTab(new SampleSettingTab(this.app, this));
|
||||
|
||||
this.registerMarkdownPostProcessor((el: HTMLElement, ctx: MarkdownPostProcessorContext) => {
|
||||
this.processLinks(el);
|
||||
});
|
||||
}
|
||||
|
||||
private processLinks(el: HTMLElement) {
|
||||
this.processNode(el);
|
||||
}
|
||||
|
||||
private processNode(node: Node) {
|
||||
if (['A', 'CODE', 'PRE', 'IMG', 'svg', 'MJX-CONTAINER'].contains(node.nodeName)) {
|
||||
return; // do not process specific node types to not break
|
||||
}
|
||||
if (node.nodeType === Node.TEXT_NODE) {
|
||||
// directly process text nodes
|
||||
const text = node.nodeValue;
|
||||
if (text) {
|
||||
const newHtml = this.replaceWithLinks(text);
|
||||
if (newHtml !== text) {
|
||||
const span = document.createElement('span');
|
||||
span.innerHTML = newHtml;
|
||||
node.parentNode?.replaceChild(span, node);
|
||||
}
|
||||
}
|
||||
} else if (node.nodeType === Node.ELEMENT_NODE) {
|
||||
// if an regular element was found, process its child nodes (applies to lists, fo example)
|
||||
const element = node as HTMLElement;
|
||||
for (let i = 0; i < element.childNodes.length; i++) {
|
||||
this.processNode(element.childNodes[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private replaceWithLinks(text: string): string {
|
||||
return this.settings.registrations.reduce((modifiedText, registration) => {
|
||||
const regex = new RegExp(`\\b(${registration.projectKey}-\\d+)\\b`, 'gi');
|
||||
return modifiedText.replace(
|
||||
regex,
|
||||
(match) => `<a href="${registration.baseUrl}/browse/${match}" target="_blank" rel="noopener noreferrer">${match}</a>`
|
||||
);
|
||||
}, text);
|
||||
}
|
||||
|
||||
onunload() {
|
||||
// nothing to do here
|
||||
}
|
||||
|
||||
async loadSettings() {
|
||||
this.settings = Object.assign({}, DEFAULT_SETTINGS, await this.loadData());
|
||||
}
|
||||
|
||||
async saveSettings() {
|
||||
await this.saveData(this.settings);
|
||||
}
|
||||
}
|
||||
|
||||
class SampleSettingTab extends PluginSettingTab {
|
||||
plugin: JiraLinker;
|
||||
|
||||
constructor(app: App, plugin: JiraLinker) {
|
||||
super(app, plugin);
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
display(): void {
|
||||
const {containerEl} = this;
|
||||
|
||||
containerEl.empty();
|
||||
|
||||
containerEl.createEl('h1', {text: 'Jira Linker'});
|
||||
containerEl.createEl('p').innerHTML = 'by <a href="https://kovah.de" target="_blank">Kevin Woblick</a>';
|
||||
containerEl.createEl('br');
|
||||
|
||||
containerEl.createEl('h2', {text: 'Projects'});
|
||||
containerEl.createEl('p', {text: 'Configure your projects here. The project key is the actual key from Jira and consists of uppercase letters or numbers without the dash and the issue number. The Jira URL must be set without a path, like https://example.atlassian.net.'});
|
||||
|
||||
// Display current registrations
|
||||
this.plugin.settings.registrations.forEach((registration, index) => {
|
||||
new Setting(containerEl)
|
||||
.setName(`Project: ${registration.projectKey}`)
|
||||
.setDesc(`Base URL: ${registration.baseUrl}`)
|
||||
.addExtraButton((btn) =>
|
||||
btn
|
||||
.setIcon('trash')
|
||||
.setTooltip('Delete')
|
||||
.onClick(async () => {
|
||||
this.plugin.settings.registrations.splice(index, 1);
|
||||
await this.plugin.saveSettings();
|
||||
this.display();
|
||||
})
|
||||
);
|
||||
});
|
||||
|
||||
// Add a new registration
|
||||
let newProjectKey: string = '';
|
||||
let newBaseUrl: string = '';
|
||||
|
||||
// Add a new registration
|
||||
new Setting(containerEl)
|
||||
.setName('Add New Registration')
|
||||
.addText((text) =>
|
||||
text.setPlaceholder('Project Key').onChange((value) => {
|
||||
newProjectKey = value;
|
||||
})
|
||||
)
|
||||
.addText((text) =>
|
||||
text.setPlaceholder('Jira URL').onChange((value) => {
|
||||
newBaseUrl = value;
|
||||
})
|
||||
)
|
||||
.addButton((btn) =>
|
||||
btn
|
||||
.setButtonText('Add')
|
||||
.setCta()
|
||||
.onClick(async () => {
|
||||
// Validation logic
|
||||
const projectKeyValid = /^[a-zA-Z][a-zA-Z0-9]{1,9}$/.test(newProjectKey);
|
||||
const baseUrlValid = /^https:\/\/[a-zA-Z0-9.-]+\.atlassian\.net$/.test(newBaseUrl);
|
||||
|
||||
if (!projectKeyValid) {
|
||||
errorEl.textContent = 'Invalid Project Key. It must be 2-10 letters or numbers, starting with a letter.';
|
||||
errorEl.classList.remove('hidden');
|
||||
return;
|
||||
}
|
||||
if (!baseUrlValid) {
|
||||
errorEl.textContent = 'Invalid Jira URL. It must be the base URL of your Jira instance without a path (e.g., https://example.atlassian.net).';
|
||||
errorEl.classList.remove('hidden');
|
||||
return;
|
||||
}
|
||||
errorEl.classList.add('hidden');
|
||||
|
||||
// Add the new registration
|
||||
this.plugin.settings.registrations.push({
|
||||
projectKey: newProjectKey,
|
||||
baseUrl: newBaseUrl,
|
||||
});
|
||||
await this.plugin.saveSettings();
|
||||
this.display(); // Refresh UI
|
||||
})
|
||||
);
|
||||
|
||||
const errorEl = containerEl.createEl('div', {
|
||||
cls: 'jira-linker-error',
|
||||
text: '',
|
||||
});
|
||||
|
||||
containerEl.createEl('br');
|
||||
containerEl.createEl('hr');
|
||||
containerEl.createEl('small').innerHTML = '❤️ Support my work via <a href="https://patreon.com/Kovah" target="_blank">Patreon</a>, <a href="https://github.com/Kovah" target="_blank">GitHub Sponsors</a> or <a href="https://liberapay.com/kovah" target="_blank">Liberapay</a>';
|
||||
}
|
||||
}
|
||||
15
manifest.json
Normal file
15
manifest.json
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
{
|
||||
"id": "jira-linker",
|
||||
"name": "Atlassian Jira Linker",
|
||||
"version": "1.0.0-beta.1",
|
||||
"minAppVersion": "1.0.0",
|
||||
"description": "Automatically create links to Jira from issue IDs like APP-1426.",
|
||||
"author": "Kevin Woblick",
|
||||
"authorUrl": "https://kovah.de",
|
||||
"fundingUrl": {
|
||||
"Patreon": "https://patreon.com/Kovah",
|
||||
"GitHub Sponsor": "https://github.com/Kovah",
|
||||
"Liberapay": "https://liberapay.com/kovah"
|
||||
},
|
||||
"isDesktopOnly": false
|
||||
}
|
||||
3297
package-lock.json
generated
Normal file
3297
package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load diff
29
package.json
Normal file
29
package.json
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
{
|
||||
"name": "jira-linker",
|
||||
"version": "1.0.0-beta.1",
|
||||
"description": "Automatically create links to Jira from issue IDs like APP-1426.",
|
||||
"main": "main.js",
|
||||
"scripts": {
|
||||
"dev": "node esbuild.config.mjs",
|
||||
"build": "tsc -noEmit -skipLibCheck && node esbuild.config.mjs production",
|
||||
"version": "node version-bump.mjs && git add manifest.json versions.json"
|
||||
},
|
||||
"keywords": [
|
||||
"obsidian",
|
||||
"atlassian",
|
||||
"jira"
|
||||
],
|
||||
"author": "Kevin Woblick <contact@kovah.de>",
|
||||
"license": "MIT",
|
||||
"devDependencies": {
|
||||
"@types/node": "^22.13.4",
|
||||
"@typescript-eslint/eslint-plugin": "^8.24.0",
|
||||
"@typescript-eslint/parser": "^8.24.0",
|
||||
"builtin-modules": "^4.0.0",
|
||||
"esbuild": "^0.25.0",
|
||||
"esbuild-sass-plugin": "^3.3.1",
|
||||
"obsidian": "latest",
|
||||
"tslib": "^2.8.1",
|
||||
"typescript": "^5.7.3"
|
||||
}
|
||||
}
|
||||
BIN
preview.jpg
Normal file
BIN
preview.jpg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 142 KiB |
7
styles.scss
Normal file
7
styles.scss
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
.jira-linker-error {
|
||||
color: rgba(250, 44, 55, .7);
|
||||
}
|
||||
|
||||
.jira-linker-error.hidden {
|
||||
display: none;
|
||||
}
|
||||
24
tsconfig.json
Normal file
24
tsconfig.json
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
{
|
||||
"compilerOptions": {
|
||||
"baseUrl": ".",
|
||||
"inlineSourceMap": true,
|
||||
"inlineSources": true,
|
||||
"module": "ESNext",
|
||||
"target": "ES6",
|
||||
"allowJs": true,
|
||||
"noImplicitAny": true,
|
||||
"moduleResolution": "node",
|
||||
"importHelpers": true,
|
||||
"isolatedModules": true,
|
||||
"strictNullChecks": true,
|
||||
"lib": [
|
||||
"DOM",
|
||||
"ES5",
|
||||
"ES6",
|
||||
"ES7"
|
||||
]
|
||||
},
|
||||
"include": [
|
||||
"**/*.ts"
|
||||
]
|
||||
}
|
||||
14
version-bump.mjs
Normal file
14
version-bump.mjs
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
import { readFileSync, writeFileSync } from "fs";
|
||||
|
||||
const targetVersion = process.env.npm_package_version;
|
||||
|
||||
// read minAppVersion from manifest.json and bump version to target version
|
||||
let manifest = JSON.parse(readFileSync("manifest.json", "utf8"));
|
||||
const { minAppVersion } = manifest;
|
||||
manifest.version = targetVersion;
|
||||
writeFileSync("manifest.json", JSON.stringify(manifest, null, "\t"));
|
||||
|
||||
// update versions.json with target version and minAppVersion from manifest.json
|
||||
let versions = JSON.parse(readFileSync("versions.json", "utf8"));
|
||||
versions[targetVersion] = minAppVersion;
|
||||
writeFileSync("versions.json", JSON.stringify(versions, null, "\t"));
|
||||
3
versions.json
Normal file
3
versions.json
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
{
|
||||
"1.0.0-beta.1": "1.0.0"
|
||||
}
|
||||
Loading…
Reference in a new issue