MCPcopy Index your code
hub / github.com/serverless/serverless / parseGitHubURL

Function parseGitHubURL

packages/sf-core/src/utils/https/index.js:73–102  ·  view source on GitHub ↗
(url)

Source from the content-addressed store, hash-verified

71 * @returns Parsed repository information
72 */
73const parseGitHubURL = (url) => {
74 // Splitting the pathname to get the repository details
75 const parts = url.pathname.split('/')
76 const pathLength = 4
77 const isSubdirectory = parts.length > pathLength
78 const owner = parts[1]
79 const repo = parts[2]
80 const branch = isSubdirectory ? parts[pathLength] : 'master'
81 const isGitHubEnterprise = url.hostname !== 'github.com'
82
83 // Validating GitHub URL if it's not a GitHub Enterprise URL
84 if (!isGitHubEnterprise) {
85 validateUrl({ url, hostname: 'github.com', service: 'GitHub', owner, repo })
86 }
87
88 // Constructing the download URL
89 const downloadUrl = `https://${isGitHubEnterprise ? url.hostname : 'github.com'}/${owner}/${repo}/archive/${branch}.zip`
90
91 // Returning parsed repository information
92 return {
93 owner,
94 repo,
95 branch,
96 downloadUrl,
97 isSubdirectory,
98 pathToDirectory: getPathDirectory(pathLength + 1, parts),
99 username: url.username || '',
100 password: url.password || '',
101 }
102}
103
104/**
105 * Parse Bitbucket URL

Callers 1

parseRepoURLFunction · 0.85

Calls 2

validateUrlFunction · 0.85
getPathDirectoryFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…