Skip to content

Commit 707d094

Browse files
authored
Merge pull request #23 from LonoxX/develop
feat: Global Settings should override pre-repository settings
2 parents 9851e64 + 72de1f8 commit 707d094

6 files changed

Lines changed: 358 additions & 6 deletions

File tree

manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"id": "github-issues",
33
"name": "Github Issues",
4-
"version": "1.3.0",
4+
"version": "1.2.3",
55
"minAppVersion": "0.15.0",
66
"description": "Track Github Issues and pull requests directly in your vault",
77
"author": "LonoxX",

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "github-issues",
3-
"version": "1.3.0",
3+
"version": "1.2.3",
44
"description": "Track GitHub issues and pull requests in Obsidian",
55
"main": "main.js",
66
"scripts": {

src/file-manager.ts

Lines changed: 59 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import {
1414
extractNumberFromFilename
1515
} from "./util/templateUtils";
1616
import { getEffectiveRepoSettings } from "./util/settingsUtils";
17+
import { extractPersistBlocks, mergePersistBlocks, shouldUpdateContent } from "./util/persistUtils";
1718

1819
export class FileManager {
1920
constructor(
@@ -430,12 +431,35 @@ export class FileManager {
430431
const updateMode = repo.issueUpdateMode;
431432

432433
if (updateMode === "update") {
434+
// Read existing content first
435+
const existingContent = await this.app.vault.read(file);
436+
437+
// Check if content needs updating based on updated_at field
438+
if (!shouldUpdateContent(existingContent, issue.updated_at)) {
439+
this.noticeManager.debug(
440+
`Skipped update for issue ${issue.number}: no changes detected (updated_at match)`
441+
);
442+
return;
443+
}
444+
445+
// Extract persist blocks from existing content
446+
const persistBlocks = extractPersistBlocks(existingContent);
447+
433448
// Create the complete new content with updated frontmatter
434-
const updatedContent = await this.createIssueContent(
449+
let updatedContent = await this.createIssueContent(
435450
issue,
436451
repo,
437452
comments,
438453
);
454+
455+
// Merge persist blocks back into new content
456+
if (persistBlocks.size > 0) {
457+
updatedContent = mergePersistBlocks(updatedContent, existingContent, persistBlocks);
458+
this.noticeManager.debug(
459+
`Restored ${persistBlocks.size} persist block(s) for issue ${issue.number}`
460+
);
461+
}
462+
439463
await this.app.vault.modify(file, updatedContent);
440464
this.noticeManager.debug(`Updated issue ${issue.number}`);
441465
} else if (updateMode === "append") {
@@ -527,12 +551,35 @@ export class FileManager {
527551
const updateMode = repo.pullRequestUpdateMode;
528552

529553
if (updateMode === "update") {
554+
// Read existing content first
555+
const existingContent = await this.app.vault.read(file);
556+
557+
// Check if content needs updating based on updated_at field
558+
if (!shouldUpdateContent(existingContent, pr.updated_at)) {
559+
this.noticeManager.debug(
560+
`Skipped update for PR ${pr.number}: no changes detected (updated_at match)`
561+
);
562+
return;
563+
}
564+
565+
// Extract persist blocks from existing content
566+
const persistBlocks = extractPersistBlocks(existingContent);
567+
530568
// Create the complete new content with updated frontmatter
531-
const updatedContent = await this.createPullRequestContent(
569+
let updatedContent = await this.createPullRequestContent(
532570
pr,
533571
repo,
534572
comments,
535573
);
574+
575+
// Merge persist blocks back into new content
576+
if (persistBlocks.size > 0) {
577+
updatedContent = mergePersistBlocks(updatedContent, existingContent, persistBlocks);
578+
this.noticeManager.debug(
579+
`Restored ${persistBlocks.size} persist block(s) for PR ${pr.number}`
580+
);
581+
}
582+
536583
await this.app.vault.modify(file, updatedContent);
537584
this.noticeManager.debug(`Updated PR ${pr.number}`);
538585
} else if (updateMode === "append") {
@@ -619,6 +666,11 @@ created: "${
619666
? format(new Date(issue.created_at), this.settings.dateFormat)
620667
: new Date(issue.created_at).toLocaleString()
621668
}"
669+
updated: "${
670+
this.settings.dateFormat !== ""
671+
? format(new Date(issue.updated_at), this.settings.dateFormat)
672+
: new Date(issue.updated_at).toLocaleString()
673+
}"
622674
url: "${issue.html_url}"
623675
opened_by: "${issue.user?.login}"
624676
assignees: [${(
@@ -675,6 +727,11 @@ created: "${
675727
? format(new Date(pr.created_at), this.settings.dateFormat)
676728
: new Date(pr.created_at).toLocaleString()
677729
}"
730+
updated: "${
731+
this.settings.dateFormat !== ""
732+
? format(new Date(pr.updated_at), this.settings.dateFormat)
733+
: new Date(pr.updated_at).toLocaleString()
734+
}"
678735
url: "${pr.html_url}"
679736
opened_by: "${pr.user?.login}"
680737
assignees: [${(

src/settings-tab.ts

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -338,6 +338,9 @@ export class GitHubTrackerSettingTab extends PluginSettingTab {
338338
// Template variables help
339339
this.addTemplateVariablesHelp(advancedContainer, 'issue');
340340

341+
// Persist blocks help
342+
this.addPersistBlocksHelp(advancedContainer);
343+
341344
new Setting(advancedContainer)
342345
.setName("Date format")
343346
.setDesc("Format for dates in issue files (e.g., yyyy-MM-dd HH:mm:ss)")
@@ -3046,6 +3049,60 @@ export class GitHubTrackerSettingTab extends PluginSettingTab {
30463049
helpText.textContent = getTemplateHelp();
30473050
}
30483051

3052+
private addPersistBlocksHelp(container: HTMLElement): void {
3053+
const helpContainer = container.createDiv("github-issues-template-help");
3054+
3055+
const details = helpContainer.createEl("details");
3056+
const summary = details.createEl("summary");
3057+
summary.textContent = "Protect your custom notes with Persist Blocks";
3058+
summary.addClass("github-issues-template-help-summary");
3059+
3060+
const contentContainer = details.createDiv("github-issues-template-variables");
3061+
3062+
// Introduction
3063+
const intro = contentContainer.createEl("p");
3064+
intro.innerHTML = `<strong>Persist blocks</strong> allow you to add your own custom notes to GitHub issue and PR files without them being overwritten during sync.`;
3065+
3066+
// Basic usage
3067+
const usageTitle = contentContainer.createEl("h4");
3068+
usageTitle.textContent = "Basic Usage";
3069+
3070+
const usageExample = contentContainer.createEl("pre");
3071+
usageExample.textContent = `{% persist "notes" %}
3072+
## My Notes
3073+
- Your custom content here
3074+
- Will never be overwritten!
3075+
{% endpersist %}`;
3076+
3077+
// How it works
3078+
const howTitle = contentContainer.createEl("h4");
3079+
howTitle.textContent = "How It Works";
3080+
3081+
const howList = contentContainer.createEl("ul");
3082+
howList.innerHTML = `
3083+
<li><strong>Smart Updates:</strong> Files are only updated if GitHub data has changed (checks the <code>updated</code> field)</li>
3084+
<li><strong>Content Protection:</strong> Everything inside persist blocks is preserved during sync</li>
3085+
<li><strong>Position Preservation:</strong> Blocks stay exactly where you placed them using surrounding text as anchors</li>
3086+
`;
3087+
3088+
// Multiple blocks
3089+
const multipleTitle = contentContainer.createEl("h4");
3090+
multipleTitle.textContent = "Multiple Blocks";
3091+
3092+
const multipleDesc = contentContainer.createEl("p");
3093+
multipleDesc.textContent = "You can have multiple persist blocks in one file. Each needs a unique name:";
3094+
3095+
const multipleExample = contentContainer.createEl("pre");
3096+
multipleExample.textContent = `{% persist "notes" %}
3097+
Your notes here...
3098+
{% endpersist %}
3099+
3100+
{% persist "todos" %}
3101+
- [ ] Task 1
3102+
- [ ] Task 2
3103+
{% endpersist %}`;
3104+
}
3105+
30493106
private async updateTokenBadge(container?: HTMLElement): Promise<void> {
30503107
const badgeContainer = container || this.containerEl.querySelector(".github-issues-token-badge-container") as HTMLElement;
30513108
if (!badgeContainer) return;

0 commit comments

Comments
 (0)