Просмотр исходного кода

rename variable and add tet of extractedArchiveDirName method

Ryu Sato 2 лет назад
Родитель
Сommit
280bdb2a01

+ 20 - 1
apps/app/src/features/growi-plugin/server/models/vo/github-url.spec.ts

@@ -63,6 +63,25 @@ describe('archiveUrl()', () => {
     const { archiveUrl } = githubUrl;
     const { archiveUrl } = githubUrl;
 
 
     // then
     // then
-    expect(archiveUrl).toEqual('https://github.com/org/repos/archive/refs/heads/fix/bug.zip');
+    expect(archiveUrl).toEqual('https://github.com/org/repos/archive/refs/heads/fix%2Fbug.zip');
   });
   });
 });
 });
+
+describe('extractedArchiveDirName()', () => {
+
+  it.concurrent.each`
+    branchName
+    ${'a"\'!,;-=@`]<>|&{}()$%+#/b'}
+    ${'a---b'}
+  `("'$branchName'", ({ branchName }) => {
+    // setup
+    const githubUrl = new GitHubUrl('https://github.com/org/repos', branchName);
+
+    // when
+    const { extractedArchiveDirName } = githubUrl;
+
+    // then
+    expect(extractedArchiveDirName).toEqual('a-b');
+  });
+
+});

+ 1 - 1
apps/app/src/features/growi-plugin/server/models/vo/github-url.ts

@@ -31,7 +31,7 @@ export class GitHubUrl {
     return ghUrl.toString();
     return ghUrl.toString();
   }
   }
 
 
-  get archiveFileName(): string {
+  get extractedArchiveDirName(): string {
     return this._branchName.replaceAll(sanitizeChars, '-');
     return this._branchName.replaceAll(sanitizeChars, '-');
   }
   }
 
 

+ 6 - 6
apps/app/src/features/growi-plugin/server/services/growi-plugin/growi-plugin.ts

@@ -76,11 +76,11 @@ export class GrowiPluginService implements IGrowiPluginService {
 
 
           // TODO: imprv Document version and repository version possibly different.
           // TODO: imprv Document version and repository version possibly different.
           const ghUrl = new GitHubUrl(growiPlugin.origin.url, growiPlugin.origin.ghBranch);
           const ghUrl = new GitHubUrl(growiPlugin.origin.url, growiPlugin.origin.ghBranch);
-          const { reposName, archiveUrl, archiveFileName } = ghUrl;
+          const { reposName, archiveUrl, extractedArchiveDirName } = ghUrl;
 
 
-          const zipFilePath = path.join(PLUGIN_STORING_PATH, `${archiveFileName}.zip`);
+          const zipFilePath = path.join(PLUGIN_STORING_PATH, `${extractedArchiveDirName}.zip`);
           const unzippedPath = PLUGIN_STORING_PATH;
           const unzippedPath = PLUGIN_STORING_PATH;
-          const unzippedReposPath = path.join(PLUGIN_STORING_PATH, `${reposName}-${archiveFileName}`);
+          const unzippedReposPath = path.join(PLUGIN_STORING_PATH, `${reposName}-${extractedArchiveDirName}`);
 
 
           try {
           try {
             // download github repository to local file system
             // download github repository to local file system
@@ -110,14 +110,14 @@ export class GrowiPluginService implements IGrowiPluginService {
   async install(origin: IGrowiPluginOrigin): Promise<string> {
   async install(origin: IGrowiPluginOrigin): Promise<string> {
     const ghUrl = new GitHubUrl(origin.url, origin.ghBranch);
     const ghUrl = new GitHubUrl(origin.url, origin.ghBranch);
     const {
     const {
-      organizationName, reposName, archiveUrl, archiveFileName,
+      organizationName, reposName, archiveUrl, extractedArchiveDirName,
     } = ghUrl;
     } = ghUrl;
 
 
     const installedPath = `${organizationName}/${reposName}`;
     const installedPath = `${organizationName}/${reposName}`;
 
 
     const organizationPath = path.join(PLUGIN_STORING_PATH, organizationName);
     const organizationPath = path.join(PLUGIN_STORING_PATH, organizationName);
-    const zipFilePath = path.join(organizationPath, `${reposName}-${archiveFileName}.zip`);
-    const temporaryReposPath = path.join(organizationPath, `${reposName}-${archiveFileName}`);
+    const zipFilePath = path.join(organizationPath, `${reposName}-${extractedArchiveDirName}.zip`);
+    const temporaryReposPath = path.join(organizationPath, `${reposName}-${extractedArchiveDirName}`);
     const reposPath = path.join(organizationPath, reposName);
     const reposPath = path.join(organizationPath, reposName);
 
 
     if (!fs.existsSync(organizationPath)) fs.mkdirSync(organizationPath);
     if (!fs.existsSync(organizationPath)) fs.mkdirSync(organizationPath);