fix: git paths

This commit is contained in:
ndom91 2024-09-08 16:34:58 +02:00
parent e2bb456f7d
commit bbe9249a01
2 changed files with 17 additions and 21 deletions

View File

@ -12,35 +12,21 @@
import TextBox from '$lib/shared/TextBox.svelte';
import Toggle from '$lib/shared/Toggle.svelte';
import { getContext } from '$lib/utils/context';
// import { join } from '@tauri-apps/api/path';
// import { readDir, type DirEntry } from '@tauri-apps/plugin-fs';
import { type DirEntry } from '@tauri-apps/plugin-fs';
import { onMount } from 'svelte';
// import { get } from 'svelte/store';
const usePullRequestTemplate = gitHostUsePullRequestTemplate();
const pullRequestTemplatePath = gitHostPullRequestTemplatePath();
let selectedTemplate = $state('');
let allAvailableTemplates = $state<DirEntry[]>([]);
let allAvailableTemplates = $state<string[]>([]);
const projectService = getContext(ProjectService);
// const currentProjectId = get(projectService.persistedId);
onMount(async () => {
const availableTemplates = await projectService.getAvailablePullRequestTemplates();
allAvailableTemplates = availableTemplates;
// console.log('project1', currentProjectId);
// const currentProject = await projectService.getProject(currentProjectId);
// console.log('currentProject', currentProject);
// const targetPath = await join(currentProject.path, '.github');
// readDir(targetPath).then((files) => {
// console.log('GITHUB FILES', files);
// files.forEach((file) => {
// allAvailableTemplates.push(file);
// });
// });
if (availableTemplates) {
allAvailableTemplates = availableTemplates;
}
});
</script>
@ -84,7 +70,7 @@
<Select
value={selectedTemplate}
options={allAvailableTemplates.map((p) => ({ label: p.name, value: p.name }))}
options={allAvailableTemplates.map((p) => ({ label: p, value: p }))}
label="Available Templates"
wide={true}
searchable

View File

@ -61,6 +61,7 @@ pub mod commands {
}
#[tauri::command(async)]
// NOTE: Do I need this instrument macro?
pub fn get_available_pull_request_templates(
path: &path::Path,
) -> Result<Vec<path::PathBuf>, Error> {
@ -68,9 +69,18 @@ pub mod commands {
let mut available_paths = Vec::new();
for entry in paths {
// let path = entry.map_err(anyhow::Error::from)?.path();
// println!("Name: {}", path.display());
// available_paths.push(path);
let path = entry.map_err(anyhow::Error::from)?.path();
println!("Name: {}", path.display());
available_paths.push(path);
let path_str = path.to_string_lossy();
if path_str.contains(".github/PULL_REQUEST_TEMPLATE.md")
|| path_str.contains(".github/pull_request_template.md")
|| path_str.contains(".github/PULL_REQUEST_TEMPLATE/")
{
println!("Name: {}", path.display());
available_paths.push(path);
}
}
Ok(available_paths)