Skip to content

Commit

Permalink
fix: if using set, clean was broken
Browse files Browse the repository at this point in the history
update interface to add convert in MonoRepoProperties
  • Loading branch information
Mara-Li committed May 4, 2024
1 parent bc36d3a commit 1ea27f7
Show file tree
Hide file tree
Showing 8 changed files with 46 additions and 19 deletions.
5 changes: 3 additions & 2 deletions src/GitHub/delete.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ export async function deleteFromGithub(
const monoProperties: MonoRepoProperties = {
frontmatter: repo,
repo: repoProperties.repo,
convert: repoProperties.convert,
};
deleted.push(await deleteFromGithubOneRepo(
silent,
Expand Down Expand Up @@ -85,7 +86,7 @@ async function deleteFromGithubOneRepo(
logs({settings}, `No file to delete in ${repo.owner}/${repo.repo}`);
return {success: false, deleted: [], undeleted: []};
}
const allSharedFiles = filesManagement.getAllFileWithPath(repoProperties.repo);
const allSharedFiles = filesManagement.getAllFileWithPath(repoProperties.repo, repoProperties.convert);
const allSharedConverted = allSharedFiles.map((file) => {
return { converted: file.converted, repo: file.repoFrontmatter };
});
Expand Down Expand Up @@ -307,7 +308,7 @@ function cleanDryRun(
Vault.recurseChildren(dryRunFolder as TFolder, (file: TAbstractFile) => {
if (!excludedFileFromDelete(normalizePath(file.path.replace(dryRunFolderPath, "")), settings) && (isAttachment(file.path, settings.embed.unHandledObsidianExt) || file.path.match("md$")) && file instanceof TFile) dryRunFiles.push(file);
});
const allSharedFiles = filesManagement.getAllFileWithPath(repoProperties.repo).map((file) => {
const allSharedFiles = filesManagement.getAllFileWithPath(repoProperties.repo, repoProperties.convert).map((file) => {
return { converted: file.converted, repo: file.repoFrontmatter };
});
let deletedSuccess = 0;
Expand Down
4 changes: 2 additions & 2 deletions src/GitHub/files.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,12 +86,12 @@ export class FilesManagement extends Publisher {
* @return {ConvertedLink[]} The shared files
*/

getAllFileWithPath(repo: Repository | null): ConvertedLink[] {
getAllFileWithPath(repo: Repository | null, convert: FrontmatterConvert): ConvertedLink[] {
const files = this.vault.getFiles().filter((x) => !x.path.startsWith(this.settings.github.dryRun.folderName));
const allFileWithPath: ConvertedLink[] = [];
for (const file of files) {
if (isAttachment(file.name, this.settings.embed.unHandledObsidianExt)) {
const filepath = getImagePath(file, this.settings, null);
const filepath = getImagePath(file, this.settings, convert);
allFileWithPath.push({
converted: filepath,
real: file.path,
Expand Down
4 changes: 3 additions & 1 deletion src/GitHub/upload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ export default class Publisher {
const repoProperties: MonoRepoProperties = {
frontmatter: properties.frontmatter.repo,
repo: properties.repository,
convert: properties.frontmatter.general,
};
try {
for (const file of linkedFiles) {
Expand Down Expand Up @@ -335,7 +336,8 @@ export default class Publisher {
{
frontmatter: repo,
repo: properties.repository,
} as MonoRepoProperties
convert: properties.frontmatter.general,
}
);
}
return {
Expand Down
7 changes: 6 additions & 1 deletion src/commands/callback.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import GithubPublisher from "../main";
import {MonoRepoProperties, MultiRepoProperties, Repository} from "../settings/interface";
import {createLink} from "../utils";
import {checkRepositoryValidity, isShared} from "../utils/data_validation_test";
import { frontmatterFromFile, getRepoFrontmatter } from "../utils/parse_frontmatter";
import { frontmatterFromFile, getFrontmatterSettings, getRepoFrontmatter } from "../utils/parse_frontmatter";
import {purgeNotesRemote, shareOneNote} from ".";
import {shareEditedOnly, uploadAllEditedNotes, uploadAllNotes, uploadNewNotes} from "./plugin_commands";

Expand Down Expand Up @@ -80,6 +80,11 @@ export async function purgeNotesRemoteCallback(plugin: GithubPublisher, repo: Re
const monoRepo: MonoRepoProperties = {
frontmatter: Array.isArray(frontmatter) ? frontmatter[0] : frontmatter,
repo,
convert: getFrontmatterSettings(
null,
plugin.settings,
repo
)
};
//@ts-ignore
const publisher = await plugin.reloadOctokit(repo?.smartKey);
Expand Down
7 changes: 6 additions & 1 deletion src/commands/file_menu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { Menu, MenuItem, Platform, TFile, TFolder} from "obsidian";
import GithubPublisher from "../main";
import {MonoRepoProperties, Repository} from "../settings/interface";
import {defaultRepo, getRepoSharedKey, isExcludedPath, isInDryRunFolder, isShared, multipleSharedKey} from "../utils/data_validation_test";
import { frontmatterFromFile, getRepoFrontmatter } from "../utils/parse_frontmatter";
import { frontmatterFromFile, getFrontmatterSettings, getRepoFrontmatter } from "../utils/parse_frontmatter";
import {shareAllMarkedNotes, shareOneNote} from ".";
import {ChooseRepoToRun} from "./suggest_other_repo_commands_modal";

Expand All @@ -22,6 +22,11 @@ export async function shareFolderRepo(plugin: GithubPublisher, folder: TFolder,
const monoProperties: MonoRepoProperties = {
frontmatter: Array.isArray(repoFrontmatter) ? repoFrontmatter[0] : repoFrontmatter,
repo,
convert: getFrontmatterSettings(
null,
plugin.settings,
repo
)
};
await shareAllMarkedNotes(
publisher,
Expand Down
6 changes: 3 additions & 3 deletions src/commands/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ export async function shareNewNote(
): Promise<void|boolean> {
const plugin = PublisherManager.plugin;
new Notice(i18next.t("informations.scanningRepo") );
const sharedFilesWithPaths = PublisherManager.getAllFileWithPath(monoRepo.repo);
const sharedFilesWithPaths = PublisherManager.getAllFileWithPath(monoRepo.repo, monoRepo.convert);
// Get all file in the repo before the creation of the branch
const githubSharedNotes = await PublisherManager.getAllFileFromRepo(
monoRepo.frontmatter.branch, // we need to take the master branch because the branch to create doesn't exist yet
Expand Down Expand Up @@ -301,7 +301,7 @@ export async function shareAllEditedNotes(
) {
const plugin = PublisherManager.plugin;
new Notice(i18next.t("informations.scanningRepo") );
const sharedFilesWithPaths = PublisherManager.getAllFileWithPath(monoRepo.repo);
const sharedFilesWithPaths = PublisherManager.getAllFileWithPath(monoRepo.repo, monoRepo.convert);
const githubSharedNotes = await PublisherManager.getAllFileFromRepo(
monoRepo.frontmatter.branch,
monoRepo.frontmatter
Expand Down Expand Up @@ -352,7 +352,7 @@ export async function shareOnlyEdited(
const shortRepo = monoRepo.repo;
const repoFrontmatter = monoRepo.frontmatter;
new Notice(i18next.t("informations.scanningRepo") );
const sharedFilesWithPaths = PublisherManager.getAllFileWithPath(shortRepo);
const sharedFilesWithPaths = PublisherManager.getAllFileWithPath(shortRepo, monoRepo.convert);
const githubSharedNotes = await PublisherManager.getAllFileFromRepo(
repoFrontmatter.branch,
repoFrontmatter
Expand Down
31 changes: 22 additions & 9 deletions src/commands/plugin_commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import GithubPublisher from "../main";
import {MonoRepoProperties, MultiRepoProperties, Repository} from "../settings/interface";
import {createLink} from "../utils";
import {checkRepositoryValidity, isShared} from "../utils/data_validation_test";
import { frontmatterFromFile, getRepoFrontmatter } from "../utils/parse_frontmatter";
import { frontmatterFromFile, getFrontmatterSettings, getRepoFrontmatter } from "../utils/parse_frontmatter";
import {
purgeNotesRemote,
shareAllEditedNotes,
Expand Down Expand Up @@ -83,7 +83,12 @@ export async function deleteCommands(plugin : GithubPublisher, repo: Repository
const publisher = await plugin.reloadOctokit(repo?.smartKey);
const mono: MonoRepoProperties = {
frontmatter: Array.isArray(repoFrontmatter) ? repoFrontmatter[0] : repoFrontmatter,
repo
repo,
convert: getFrontmatterSettings(
null,
plugin.settings,
repo
)
};
await purgeNotesRemote(
publisher,
Expand All @@ -108,7 +113,12 @@ export async function uploadAllNotes(plugin: GithubPublisher, repo: Repository |
const repoFrontmatter = getRepoFrontmatter(plugin.settings, repo);
const mono: MonoRepoProperties = {
frontmatter: Array.isArray(repoFrontmatter) ? repoFrontmatter[0] : repoFrontmatter,
repo
repo,
convert: getFrontmatterSettings(
null,
plugin.settings,
repo
)
};
await shareAllMarkedNotes(
publisher,
Expand Down Expand Up @@ -137,8 +147,9 @@ export async function uploadNewNotes(plugin: GithubPublisher, branchName: string
branchName,
{
frontmatter: Array.isArray(repoFrontmatter) ? repoFrontmatter[0] : repoFrontmatter,
repo
} as MonoRepoProperties,
repo,
convert: getFrontmatterSettings(null, plugin.settings, repo)
},
);
}

Expand Down Expand Up @@ -179,8 +190,9 @@ export async function uploadAllEditedNotes(plugin: GithubPublisher ,branchName:
branchName,
{
frontmatter: Array.isArray(repoFrontmatter) ? repoFrontmatter[0] : repoFrontmatter,
repo
} as MonoRepoProperties,
repo,
convert: getFrontmatterSettings(null, plugin.settings, repo)
},
);
}

Expand All @@ -200,7 +212,8 @@ export async function shareEditedOnly(branchName: string, repo: Repository|null,
branchName,
{
frontmatter: Array.isArray(repoFrontmatter) ? repoFrontmatter[0] : repoFrontmatter,
repo
} as MonoRepoProperties,
repo,
convert: getFrontmatterSettings(null, plugin.settings, repo)
},
);
}
1 change: 1 addition & 0 deletions src/settings/interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,7 @@ export interface MonoProperties {
export interface MonoRepoProperties {
frontmatter: RepoFrontmatter;
repo: Repository | null;
convert: FrontmatterConvert;
}

export interface MultiRepoProperties {
Expand Down

0 comments on commit 1ea27f7

Please sign in to comment.