From 4bb208f30ebc1fca7c478f0b8c741a176b81e5e6 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 13 May 2026 08:17:31 +0000 Subject: [PATCH 1/6] Initial plan From eb0e5b7816b5b27ba2e79a85fe03f01790899bbc Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 13 May 2026 08:23:11 +0000 Subject: [PATCH 2/6] Show repo preview status before network fetch Agent-Logs-Url: https://github.com/download-directory/download-directory.github.io/sessions/c1e317da-bd62-4921-9431-761295f6be08 Co-authored-by: fregante <1402241+fregante@users.noreply.github.com> --- index.ts | 16 ++++++---------- repository-info.test.ts | 16 +++++++++++++++- repository-info.ts | 39 ++++++++++++++++++++++++++++++--------- 3 files changed, 51 insertions(+), 20 deletions(-) diff --git a/index.ts b/index.ts index ec2e887..6714f96 100644 --- a/index.ts +++ b/index.ts @@ -9,7 +9,7 @@ import { } from 'list-github-dir-content'; import pMap from 'p-map'; import {downloadFile} from './download.js'; -import getRepositoryInfo from './repository-info.js'; +import getRepositoryInfo, {getRepositoryPreview} from './repository-info.js'; type ApiOptions = ListGithubDirectoryOptions & {getFullData: true}; @@ -92,6 +92,11 @@ async function init() { throw new Error('You are offline'); } + const repositoryPreview = getRepositoryPreview(url); + if (!('error' in repositoryPreview)) { + updateStatus(`Repo: ${repositoryPreview.user}/${repositoryPreview.repository}\nDirectory: /${repositoryPreview.directory}`); + } + const parsedPath = await getRepositoryInfo(url); if ('error' in parsedPath) { @@ -110,15 +115,6 @@ async function init() { } const {user, repository, gitReference, directory, isPrivate} = parsedPath; - updateStatus(`Repo: ${user}/${repository}\nDirectory: /${directory}`, { - source: { - user, - repository, - gitReference, - directory, - isPrivate, - }, - }); if ('downloadUrl' in parsedPath) { updateStatus('Downloading the entire repository directly from GitHub'); diff --git a/repository-info.test.ts b/repository-info.test.ts index 83fd578..49b2ce3 100644 --- a/repository-info.test.ts +++ b/repository-info.test.ts @@ -1,5 +1,19 @@ import {test, expect} from 'vitest'; -import getRepositoryInfo from './repository-info.js'; +import getRepositoryInfo, {getRepositoryPreview} from './repository-info.js'; + +test('getRepositoryPreview', () => { + expect(getRepositoryPreview('https://github.com/user')).toEqual({ + error: 'NOT_A_REPOSITORY', + }); + expect(getRepositoryPreview('https://github.com/fregante/doma/blob/develop/readme.md')).toEqual({ + error: 'NOT_A_DIRECTORY', + }); + expect(getRepositoryPreview('https://github.com/wesbos/JavaScript30/tree/master/01%20-%20JavaScript%20Drum%20Kit/sounds')).toEqual({ + user: 'wesbos', + repository: 'JavaScript30', + directory: '01 - JavaScript Drum Kit/sounds', + }); +}); test('getRepositoryInfo', async () => { await expect(getRepositoryInfo('https://github.com/user')).resolves.toMatchInlineSnapshot(` diff --git a/repository-info.ts b/repository-info.ts index 525b974..1b63426 100644 --- a/repository-info.ts +++ b/repository-info.ts @@ -6,6 +6,28 @@ function cleanUrl(url: string) { .replace(/[/]$/, ''); // Drop trailing slash } +export function getRepositoryPreview(url: string): +| {error: 'NOT_A_REPOSITORY' | 'NOT_A_DIRECTORY'} +| {user: string; repository: string; directory: string} { + const [, user, repository, type, , ...directoryParts] = cleanUrl( + decodeURIComponent(new URL(url).pathname), + ).split('/'); + + if (!user || !repository) { + return {error: 'NOT_A_REPOSITORY'}; + } + + if (type && type !== 'tree') { + return {error: 'NOT_A_DIRECTORY'}; + } + + return { + user, + repository, + directory: directoryParts.join('/'), + }; +} + async function parsePath( user: string, repo: string, @@ -43,17 +65,16 @@ export default async function getRepositoryInfo( isPrivate: boolean; } > { - const [, user, repository, type, ...parts] = cleanUrl( - decodeURIComponent(new URL(url).pathname), - ).split('/'); - - if (!user || !repository) { - return {error: 'NOT_A_REPOSITORY'}; + const preview = getRepositoryPreview(url); + if ('error' in preview) { + return preview; } - if (type && type !== 'tree') { - return {error: 'NOT_A_DIRECTORY'}; - } + const {user, repository} = preview; + const pathParts = cleanUrl( + decodeURIComponent(new URL(url).pathname), + ).split('/'); + const parts = pathParts.slice(4); const repoInfoResponse = await authenticatedFetch( `https://api.github.com/repos/${user}/${repository}`, From 2e03f3cf10fb434afeb1b200d223e99cb42c01a5 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 13 May 2026 08:24:43 +0000 Subject: [PATCH 3/6] Refine preview URL parsing for clarity Agent-Logs-Url: https://github.com/download-directory/download-directory.github.io/sessions/c1e317da-bd62-4921-9431-761295f6be08 Co-authored-by: fregante <1402241+fregante@users.noreply.github.com> --- repository-info.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/repository-info.ts b/repository-info.ts index 1b63426..6870be7 100644 --- a/repository-info.ts +++ b/repository-info.ts @@ -9,9 +9,10 @@ function cleanUrl(url: string) { export function getRepositoryPreview(url: string): | {error: 'NOT_A_REPOSITORY' | 'NOT_A_DIRECTORY'} | {user: string; repository: string; directory: string} { - const [, user, repository, type, , ...directoryParts] = cleanUrl( + const [, user, repository, ...restPathParts] = cleanUrl( decodeURIComponent(new URL(url).pathname), ).split('/'); + const type = restPathParts[0]; if (!user || !repository) { return {error: 'NOT_A_REPOSITORY'}; @@ -21,6 +22,8 @@ export function getRepositoryPreview(url: string): return {error: 'NOT_A_DIRECTORY'}; } + const directoryParts = type === 'tree' ? restPathParts.slice(2) : []; + return { user, repository, From 6c60d6b4098e1b8b41809fdbc6a04c3c2105c3be Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 13 May 2026 08:26:21 +0000 Subject: [PATCH 4/6] Clarify early status message and path parsing Agent-Logs-Url: https://github.com/download-directory/download-directory.github.io/sessions/c1e317da-bd62-4921-9431-761295f6be08 Co-authored-by: fregante <1402241+fregante@users.noreply.github.com> --- index.ts | 2 +- repository-info.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/index.ts b/index.ts index 6714f96..aa7cb9e 100644 --- a/index.ts +++ b/index.ts @@ -94,7 +94,7 @@ async function init() { const repositoryPreview = getRepositoryPreview(url); if (!('error' in repositoryPreview)) { - updateStatus(`Repo: ${repositoryPreview.user}/${repositoryPreview.repository}\nDirectory: /${repositoryPreview.directory}`); + updateStatus(`Parsed URL — Repo: ${repositoryPreview.user}/${repositoryPreview.repository}\nDirectory: /${repositoryPreview.directory}`); } const parsedPath = await getRepositoryInfo(url); diff --git a/repository-info.ts b/repository-info.ts index 6870be7..2e33fd4 100644 --- a/repository-info.ts +++ b/repository-info.ts @@ -77,7 +77,7 @@ export default async function getRepositoryInfo( const pathParts = cleanUrl( decodeURIComponent(new URL(url).pathname), ).split('/'); - const parts = pathParts.slice(4); + const parts = pathParts[3] === 'tree' ? pathParts.slice(4) : []; const repoInfoResponse = await authenticatedFetch( `https://api.github.com/repos/${user}/${repository}`, From 881a3478e49ddaa5fd2e73eb2a05149b95462e67 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 13 May 2026 08:59:38 +0000 Subject: [PATCH 5/6] Address PR review feedback on repository parsing API Agent-Logs-Url: https://github.com/download-directory/download-directory.github.io/sessions/327891a9-2dcf-471d-abf5-6a2011fa09af Co-authored-by: fregante <1402241+fregante@users.noreply.github.com> --- index.ts | 34 ++++++++++++++++++++++--------- repository-info.test.ts | 45 ++++++++++++++++++++++++----------------- repository-info.ts | 19 ++++++----------- 3 files changed, 56 insertions(+), 42 deletions(-) diff --git a/index.ts b/index.ts index aa7cb9e..6c221e6 100644 --- a/index.ts +++ b/index.ts @@ -9,7 +9,7 @@ import { } from 'list-github-dir-content'; import pMap from 'p-map'; import {downloadFile} from './download.js'; -import getRepositoryInfo, {getRepositoryPreview} from './repository-info.js'; +import {getRepositoryInfo, getRepositoryPreview} from './repository-info.js'; type ApiOptions = ListGithubDirectoryOptions & {getFullData: true}; @@ -93,19 +93,24 @@ async function init() { } const repositoryPreview = getRepositoryPreview(url); - if (!('error' in repositoryPreview)) { - updateStatus(`Parsed URL — Repo: ${repositoryPreview.user}/${repositoryPreview.repository}\nDirectory: /${repositoryPreview.directory}`); + if ('error' in repositoryPreview) { + if (repositoryPreview.error === 'NOT_A_REPOSITORY') { + updateStatus('⚠ Not a repository'); + } else if (repositoryPreview.error === 'NOT_A_DIRECTORY') { + updateStatus('⚠ Not a directory'); + } else { + updateStatus('⚠ Unknown error'); + } + + return; } - const parsedPath = await getRepositoryInfo(url); + updateStatus(`Parsed URL — Repo: ${repositoryPreview.user}/${repositoryPreview.repository}\nDirectory: /${repositoryPreview.directory}`); + + const parsedPath = await getRepositoryInfo(repositoryPreview); if ('error' in parsedPath) { - // eslint-disable-next-line unicorn/prefer-switch -- I hate how it looks - if (parsedPath.error === 'NOT_A_REPOSITORY') { - updateStatus('⚠ Not a repository'); - } else if (parsedPath.error === 'NOT_A_DIRECTORY') { - updateStatus('⚠ Not a directory'); - } else if (parsedPath.error === 'REPOSITORY_NOT_FOUND') { + if (parsedPath.error === 'REPOSITORY_NOT_FOUND') { updateStatus('⚠ Repository not found. If it’s private, you should enter a token that can access it.'); } else { updateStatus('⚠ Unknown error'); @@ -115,6 +120,15 @@ async function init() { } const {user, repository, gitReference, directory, isPrivate} = parsedPath; + updateStatus(`Repo: ${user}/${repository}\nDirectory: /${directory}`, { + source: { + user, + repository, + gitReference, + directory, + isPrivate, + }, + }); if ('downloadUrl' in parsedPath) { updateStatus('Downloading the entire repository directly from GitHub'); diff --git a/repository-info.test.ts b/repository-info.test.ts index 49b2ce3..8ceec1a 100644 --- a/repository-info.test.ts +++ b/repository-info.test.ts @@ -1,5 +1,5 @@ import {test, expect} from 'vitest'; -import getRepositoryInfo, {getRepositoryPreview} from './repository-info.js'; +import {getRepositoryInfo, getRepositoryPreview} from './repository-info.js'; test('getRepositoryPreview', () => { expect(getRepositoryPreview('https://github.com/user')).toEqual({ @@ -11,33 +11,30 @@ test('getRepositoryPreview', () => { expect(getRepositoryPreview('https://github.com/wesbos/JavaScript30/tree/master/01%20-%20JavaScript%20Drum%20Kit/sounds')).toEqual({ user: 'wesbos', repository: 'JavaScript30', + parts: ['master', '01 - JavaScript Drum Kit', 'sounds'], directory: '01 - JavaScript Drum Kit/sounds', }); }); test('getRepositoryInfo', async () => { - await expect(getRepositoryInfo('https://github.com/user')).resolves.toMatchInlineSnapshot(` - { - "error": "NOT_A_REPOSITORY", - } - `); - await expect(getRepositoryInfo('https://github.com/fregante/doma/blob/develop/readme.md')).resolves.toMatchInlineSnapshot(` - { - "error": "NOT_A_DIRECTORY", - } - `); - await expect(getRepositoryInfo('https://github.com/refined-github/sandbox/tree/durian/folder')).resolves.toMatchInlineSnapshot(` + const sandboxDurianFolder = getRepositoryPreview('https://github.com/refined-github/sandbox/tree/durian/folder'); + expect(sandboxDurianFolder).not.toHaveProperty('error'); + await expect(getRepositoryInfo(sandboxDurianFolder as {user: string; repository: string; parts: string[]})).resolves.toMatchInlineSnapshot(` { "error": "BRANCH_NOT_FOUND", } `); - await expect(getRepositoryInfo('https://github.com/refined-github/private/tree/durian/folder')).resolves.toMatchInlineSnapshot(` + const privateDurianFolder = getRepositoryPreview('https://github.com/refined-github/private/tree/durian/folder'); + expect(privateDurianFolder).not.toHaveProperty('error'); + await expect(getRepositoryInfo(privateDurianFolder as {user: string; repository: string; parts: string[]})).resolves.toMatchInlineSnapshot(` { "error": "REPOSITORY_NOT_FOUND", } `); // Simple branches are not verified at this point. Should they be? - await expect(getRepositoryInfo('https://github.com/refined-github/sandbox/tree/durian')).resolves.toMatchInlineSnapshot(` + const sandboxDurian = getRepositoryPreview('https://github.com/refined-github/sandbox/tree/durian'); + expect(sandboxDurian).not.toHaveProperty('error'); + await expect(getRepositoryInfo(sandboxDurian as {user: string; repository: string; parts: string[]})).resolves.toMatchInlineSnapshot(` { "directory": "", "downloadUrl": "https://api.github.com/repos/refined-github/sandbox/zipball/durian", @@ -47,7 +44,9 @@ test('getRepositoryInfo', async () => { "user": "refined-github", } `); - await expect(getRepositoryInfo('https://github.com/refined-github/sandbox/tree/branch/with/slashes')).resolves.toMatchInlineSnapshot(` + const sandboxSlashes = getRepositoryPreview('https://github.com/refined-github/sandbox/tree/branch/with/slashes'); + expect(sandboxSlashes).not.toHaveProperty('error'); + await expect(getRepositoryInfo(sandboxSlashes as {user: string; repository: string; parts: string[]})).resolves.toMatchInlineSnapshot(` { "directory": "", "gitReference": "branch/with/slashes", @@ -56,7 +55,9 @@ test('getRepositoryInfo', async () => { "user": "refined-github", } `); - await expect(getRepositoryInfo('https://github.com/refined-github/sandbox/tree/default-a/.github/workflows')).resolves.toMatchInlineSnapshot(` + const sandboxWorkflows = getRepositoryPreview('https://github.com/refined-github/sandbox/tree/default-a/.github/workflows'); + expect(sandboxWorkflows).not.toHaveProperty('error'); + await expect(getRepositoryInfo(sandboxWorkflows as {user: string; repository: string; parts: string[]})).resolves.toMatchInlineSnapshot(` { "directory": ".github/workflows", "gitReference": "default-a", @@ -65,7 +66,9 @@ test('getRepositoryInfo', async () => { "user": "refined-github", } `); - await expect(getRepositoryInfo('https://github.com/microsoft/typescript')).resolves.toMatchInlineSnapshot(` + const microsoftTypescript = getRepositoryPreview('https://github.com/microsoft/typescript'); + expect(microsoftTypescript).not.toHaveProperty('error'); + await expect(getRepositoryInfo(microsoftTypescript as {user: string; repository: string; parts: string[]})).resolves.toMatchInlineSnapshot(` { "directory": "", "downloadUrl": "https://api.github.com/repos/microsoft/typescript/zipball", @@ -74,7 +77,9 @@ test('getRepositoryInfo', async () => { "user": "microsoft", } `); - await expect(getRepositoryInfo('https://github.com/fregante/doma/tree/develop')).resolves.toMatchInlineSnapshot(` + const domaDevelop = getRepositoryPreview('https://github.com/fregante/doma/tree/develop'); + expect(domaDevelop).not.toHaveProperty('error'); + await expect(getRepositoryInfo(domaDevelop as {user: string; repository: string; parts: string[]})).resolves.toMatchInlineSnapshot(` { "directory": "", "downloadUrl": "https://api.github.com/repos/fregante/doma/zipball/develop", @@ -84,7 +89,9 @@ test('getRepositoryInfo', async () => { "user": "fregante", } `); - await expect(getRepositoryInfo('https://github.com/wesbos/JavaScript30/tree/master/01%20-%20JavaScript%20Drum%20Kit/sounds')).resolves.toMatchInlineSnapshot(` + const javascript30Sounds = getRepositoryPreview('https://github.com/wesbos/JavaScript30/tree/master/01%20-%20JavaScript%20Drum%20Kit/sounds'); + expect(javascript30Sounds).not.toHaveProperty('error'); + await expect(getRepositoryInfo(javascript30Sounds as {user: string; repository: string; parts: string[]})).resolves.toMatchInlineSnapshot(` { "directory": "01 - JavaScript Drum Kit/sounds", "gitReference": "master", diff --git a/repository-info.ts b/repository-info.ts index 2e33fd4..e759aab 100644 --- a/repository-info.ts +++ b/repository-info.ts @@ -8,7 +8,7 @@ function cleanUrl(url: string) { export function getRepositoryPreview(url: string): | {error: 'NOT_A_REPOSITORY' | 'NOT_A_DIRECTORY'} -| {user: string; repository: string; directory: string} { +| {user: string; repository: string; parts: string[]; directory: string} { const [, user, repository, ...restPathParts] = cleanUrl( decodeURIComponent(new URL(url).pathname), ).split('/'); @@ -23,10 +23,12 @@ export function getRepositoryPreview(url: string): } const directoryParts = type === 'tree' ? restPathParts.slice(2) : []; + const parts = type === 'tree' ? restPathParts.slice(1) : []; return { user, repository, + parts, directory: directoryParts.join('/'), }; } @@ -48,8 +50,8 @@ async function parsePath( } } -export default async function getRepositoryInfo( - url: string, +export async function getRepositoryInfo( + repositoryInfo: {user: string; repository: string; parts: string[]}, ): Promise< | {error: string} | { @@ -68,16 +70,7 @@ export default async function getRepositoryInfo( isPrivate: boolean; } > { - const preview = getRepositoryPreview(url); - if ('error' in preview) { - return preview; - } - - const {user, repository} = preview; - const pathParts = cleanUrl( - decodeURIComponent(new URL(url).pathname), - ).split('/'); - const parts = pathParts[3] === 'tree' ? pathParts.slice(4) : []; + const {user, repository, parts} = repositoryInfo; const repoInfoResponse = await authenticatedFetch( `https://api.github.com/repos/${user}/${repository}`, From 87cbfc66e64bdcfab910d7e61a5218c2b2fc425b Mon Sep 17 00:00:00 2001 From: fregante Date: Wed, 13 May 2026 16:22:22 +0700 Subject: [PATCH 6/6] Update index.ts --- index.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/index.ts b/index.ts index 6c221e6..736d8cd 100644 --- a/index.ts +++ b/index.ts @@ -105,7 +105,7 @@ async function init() { return; } - updateStatus(`Parsed URL — Repo: ${repositoryPreview.user}/${repositoryPreview.repository}\nDirectory: /${repositoryPreview.directory}`); + updateStatus(`Repo: ${repositoryPreview.user}/${repositoryPreview.repository}`); const parsedPath = await getRepositoryInfo(repositoryPreview); @@ -120,7 +120,7 @@ async function init() { } const {user, repository, gitReference, directory, isPrivate} = parsedPath; - updateStatus(`Repo: ${user}/${repository}\nDirectory: /${directory}`, { + updateStatus(`Directory: /${directory}`, { source: { user, repository,