fix: use relativePath and get project basePath on rust side

This commit is contained in:
ndom91 2024-09-13 12:01:03 +02:00
parent d14b6496b1
commit e8bb66c151
5 changed files with 21 additions and 10 deletions

View File

@ -93,7 +93,7 @@
const prTemplatePath = project.git_host.pullRequestTemplatePath;
if (prTemplatePath) {
pullRequestTemplateBody = await $prService?.getPrTemplateContent(prTemplatePath);
pullRequestTemplateBody = await $prService?.getPrTemplateContent(prTemplatePath, project.id);
}
if (pullRequestTemplateBody) {

View File

@ -90,9 +90,12 @@ export class GitHubPrService implements GitHostPrService {
return new GitHubPrMonitor(this, prNumber);
}
async getPrTemplateContent(path: string) {
async getPrTemplateContent(path: string, projectId: string) {
try {
const fileContents: string | undefined = await invoke('get_pr_template_contents', { path });
const fileContents: string | undefined = await invoke('get_pr_template_contents', {
relativePath: path,
projectId
});
return fileContents;
} catch (err) {
console.error(`Error reading pull request template at path: ${path}`, err);

View File

@ -17,8 +17,8 @@ export interface GitHostPrService {
baseBranchName,
upstreamName
}: CreatePullRequestArgs): Promise<PullRequest>;
getAvailablePrTemplates(path?: string): Promise<string[] | undefined>;
getPrTemplateContent(path?: string): Promise<string | undefined>;
getAvailablePrTemplates(path: string): Promise<string[] | undefined>;
getPrTemplateContent(path: string, projectId: string): Promise<string | undefined>;
merge(method: MergeMethod, prNumber: number): Promise<void>;
prMonitor(prNumber: number): GitHostPrMonitor;
}

View File

@ -25,9 +25,10 @@
$prService?.getAvailablePrTemplates(project.path).then((availableTemplates) => {
if (availableTemplates) {
allAvailableTemplates = availableTemplates.map((availableTemplate) => {
const relativePath = availableTemplate.replace(`${project.path}/`, '');
return {
label: availableTemplate.replace(`${project.path}/`, ''),
value: availableTemplate
label: relativePath,
value: relativePath
};
});
}

View File

@ -99,9 +99,16 @@ pub mod commands {
}
#[tauri::command(async)]
#[instrument]
pub fn get_pr_template_contents(path: &path::Path) -> Result<String, Error> {
Ok(read_file_from_workspace(&path)?)
#[instrument(skip(projects))]
pub fn get_pr_template_contents(
projects: State<'_, Controller>,
relative_path: &path::Path,
project_id: ProjectId,
) -> Result<String, Error> {
let project = projects.get(project_id)?;
let template_path = project.path.join(relative_path);
Ok(read_file_from_workspace(&template_path.as_path())?)
}
}