Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion github-issue-to-markdown.html
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,12 @@ <h1>Convert GitHub issue to markdown</h1>

function parseGitHubUrl(url) {
try {
const urlObj = new URL(url)
// Normalize URL by adding https:// if no protocol is present
let normalizedUrl = url.trim()
if (!normalizedUrl.match(/^https?:\/\//)) {
normalizedUrl = 'https://' + normalizedUrl
}
const urlObj = new URL(normalizedUrl)
const [, owner, repo, , number] = urlObj.pathname.split('/')
if (!owner || !repo || !number) {
throw new Error('Invalid URL format')
Expand Down Expand Up @@ -601,6 +606,16 @@ <h1>Convert GitHub issue to markdown</h1>
assertDeepEqual(result, { owner: 'owner', repo: 'repo', number: '123' })
})

test('parseGitHubUrl: URL without protocol (adds https://)', () => {
const result = parseGitHubUrl('github.com/owner/repo/issues/123')
assertDeepEqual(result, { owner: 'owner', repo: 'repo', number: '123' })
})

test('parseGitHubUrl: URL with http:// protocol', () => {
const result = parseGitHubUrl('http://github.com/owner/repo/issues/456')
assertDeepEqual(result, { owner: 'owner', repo: 'repo', number: '456' })
})

test('parseGitHubUrl: valid PR URL', () => {
const result = parseGitHubUrl('https://github.com/simonw/sqlite-utils/pull/456')
assertDeepEqual(result, { owner: 'simonw', repo: 'sqlite-utils', number: '456' })
Expand Down