@@ -150,7 +150,35 @@ async function getRepoLanguages(repoInfo) {
150150 }
151151}
152152
153- function preFillFields ( repoData , languages ) {
153+ async function getLicenseURL ( repoURL ) {
154+ const urlParts = repoURL . replace ( 'https://github.com/' , '' ) . split ( '/' )
155+ const owner = urlParts [ 0 ]
156+ const repo = urlParts [ 1 ]
157+
158+ try {
159+ const apiUrl = `https://api.github.com/repos/${ owner } /${ repo } /contents`
160+ const response = await fetch ( apiUrl )
161+
162+ const files = await response . json ( )
163+
164+ const licenseFile = files . find ( file => {
165+ const fileName = file . name . toLowerCase ( )
166+ return fileName . startsWith ( 'license' )
167+ } )
168+
169+ if ( licenseFile ) {
170+ return `${ repoURL } /blob/main/${ licenseFile . name } `
171+ }
172+
173+ return `${ repoURL } /blob/main/LICENSE`
174+
175+ } catch ( error ) {
176+ console . error ( 'Could not check license via API:' , error . message )
177+ return `${ repoURL } /blob/main/LICENSE`
178+ }
179+ }
180+
181+ async function preFillFields ( repoData , languages ) {
154182 if ( ! window . formIOInstance ) {
155183 notificationSystem . error ( "Form interface not initialized. Please refresh and try again." ) ;
156184 return ;
@@ -198,10 +226,11 @@ function preFillFields(repoData, languages) {
198226 const currentPermissions = permissionsComp . getValue ( ) || { } ;
199227
200228 currentPermissions . licenses = currentPermissions . licenses || [ ] ;
229+ const licenseURL = await getLicenseURL ( repoData . html_url )
201230
202231 const licenseObj = {
203232 name : repoData . license . spdx_id ,
204- URL : repoData . html_url + "/blob/main/LICENSE"
233+ URL : licenseURL
205234 } ;
206235
207236 currentPermissions . licenses = [ licenseObj ] ;
0 commit comments