Wiki source code of GitHub Importer
Last modified by Finn on 2026/09/10 07:38
Show last authors
| author | version | line-number | content |
|---|---|---|---|
| 1 | {{velocity}} | ||
| 2 | #if (!$request.import) | ||
| 3 | = $services.localization.render('githubimporter.description.title') = | ||
| 4 | $services.localization.render('githubimporter.description') | ||
| 5 | = $services.localization.render('githubimporter.description.options') = | ||
| 6 | #else | ||
| 7 | ## Set input and output types for filter | ||
| 8 | #set($input = 'githubimporter+wiki') | ||
| 9 | #set($output = 'xwiki+instance') | ||
| 10 | ## Should validate if parent already exists | ||
| 11 | #set($parentValidationError = false) | ||
| 12 | ## Set input properties by going through each request parameter value | ||
| 13 | #set($inputProperties = {}) | ||
| 14 | #foreach($parameterName in $request.parameterNames) | ||
| 15 | #if ($parameterName.startsWith('githubimporter_properties_descriptor_')) | ||
| 16 | #set($propertyName = $parameterName.substring(37)) | ||
| 17 | #set($paramValue = $request.get($parameterName)) | ||
| 18 | #if ($propertyName.startsWith('source')) | ||
| 19 | #if ($paramValue.startsWith('http')) | ||
| 20 | #set($paramValue = "url:${paramValue}") | ||
| 21 | #else | ||
| 22 | #set($propertyName = 'source') | ||
| 23 | #set($paramValue = "file:${paramValue}") | ||
| 24 | #end | ||
| 25 | #end | ||
| 26 | #if ($propertyName.startsWith('parent')) | ||
| 27 | #if ($paramValue.endsWith('.WebHome')) | ||
| 28 | #set ($paramValue = $paramValue.replace('.WebHome', '')) | ||
| 29 | #end | ||
| 30 | #set ($parentName = $paramValue.substring($paramValue.lastIndexOf('.') + 1)) | ||
| 31 | #set($spaceQuery = "select count(space.name) from XWikiSpace as space where space.name='$parentName'") | ||
| 32 | #set ($spaceFound = $services.query.xwql($spaceQuery).execute()[0]) | ||
| 33 | #if ($spaceFound > 0) | ||
| 34 | #set ($parentValidationError = "$services.localization.render('githubimporter.validation.parent')") | ||
| 35 | #end | ||
| 36 | #end | ||
| 37 | #if ($request.getParameter($parameterName) && $request.getParameter($parameterName) != '') | ||
| 38 | #set($void = $inputProperties.put($propertyName, $paramValue)) | ||
| 39 | #end | ||
| 40 | #end | ||
| 41 | #end | ||
| 42 | |||
| 43 | #if ($parentValidationError) | ||
| 44 | {{error}}$parentValidationError{{/error}} | ||
| 45 | #else | ||
| 46 | ## Set default options for XWiki output instance otherwise outputProperties will be null | ||
| 47 | #set($outputProperties = {}) | ||
| 48 | ## Set job in filter and start the conversion | ||
| 49 | #set($job = $services.filter.startConvert($input, $inputProperties, $output, $outputProperties)) | ||
| 50 | #if ($job and $request.method == 'POST') | ||
| 51 | {{info}}$services.localization.render('githubimporter.job.info'){{/info}} | ||
| 52 | #end | ||
| 53 | #end | ||
| 54 | #end | ||
| 55 | {{/velocity}} | ||
| 56 | |||
| 57 | {{template name="job_macros.vm"/}} | ||
| 58 | |||
| 59 | {{velocity output="false"}} | ||
| 60 | #set ($discard = $xwiki.jsfx.use('uicomponents/job/job.js', true)) | ||
| 61 | {{/velocity}} | ||
| 62 | |||
| 63 | {{velocity}} | ||
| 64 | ## Display job log of conversion | ||
| 65 | #if (!$parentValidationError && $request.method == 'POST') | ||
| 66 | == Import Information == | ||
| 67 | {{html}} | ||
| 68 | <div id="filter_job_status"> | ||
| 69 | #set($job = $services.filter.currentJob) | ||
| 70 | #if ($job) | ||
| 71 | #set ($jobStatusURL = $xwiki.getURL('GitHub Importer.Code.FilterStreamJobJSON', 'get', $escapetool.url({ | ||
| 72 | 'outputSyntax': 'plain' | ||
| 73 | }))) | ||
| 74 | <div class="xcontent job-status" data-url="$jobStatusURL"> | ||
| 75 | #set($jobStatus = $job.status) | ||
| 76 | #set($finished = $jobStatus.state.name() == 'FINISHED') | ||
| 77 | #if (!$finished) | ||
| 78 | #displayJobProgressBar($jobStatus) | ||
| 79 | #else | ||
| 80 | #if (!$jobStatus.logTail.hasLogLevel('ERROR')) | ||
| 81 | <div class="box successmessage"> | ||
| 82 | $services.localization.render('githubimporter.job.complete') | ||
| 83 | </div> | ||
| 84 | #else | ||
| 85 | <div class="box errormessage"> | ||
| 86 | $services.localization.render('githubimporter.job.error') | ||
| 87 | </div> | ||
| 88 | #end | ||
| 89 | #end | ||
| 90 | #displayJobStatusLog($jobStatus true) | ||
| 91 | </div> | ||
| 92 | #end | ||
| 93 | </div> | ||
| 94 | {{/html}} | ||
| 95 | #end | ||
| 96 | {{/velocity}} | ||
| 97 | |||
| 98 | {{velocity}} | ||
| 99 | {{html clean="false"}} | ||
| 100 | <form class="xform" method="post"> | ||
| 101 | <fieldset> | ||
| 102 | <dl> | ||
| 103 | <dt> | ||
| 104 | <label for="githubimporter_input_source_type"> | ||
| 105 | $services.localization.render('githubimporter.sourcetype.title') | ||
| 106 | <span class="xRequired">$services.localization.render('githubimporter.validation.required')</span> | ||
| 107 | </label> | ||
| 108 | <span class="xHint">$services.localization.render('githubimporter.sourcetype.hint')</span> | ||
| 109 | </dt> | ||
| 110 | <dd> | ||
| 111 | <select name="githubimporter_sourcetype" id="githubimporter_sourcetype" required> | ||
| 112 | <option value="url" name="githubimporter_sourcetype_url" #if($request.get('githubimporter_sourcetype') == "url")selected #end> | ||
| 113 | $services.localization.render('githubimporter.sourcetype.url') | ||
| 114 | </option> | ||
| 115 | <option value="file" name="githubimporter_sourcetype_file" #if($request.get('githubimporter_sourcetype') == "file") selected #end> | ||
| 116 | $services.localization.render('githubimporter.sourcetype.file') | ||
| 117 | </option> | ||
| 118 | </select> | ||
| 119 | </dd> | ||
| 120 | <dt class="githubimporter_properties_descriptor_source#if($request.import && $request.get('githubimporter_sourcetype') != "url") hidden#end"> | ||
| 121 | <label for="githubimporter_properties_descriptor_source"> | ||
| 122 | $services.localization.render('githubimporter.source.url.title') | ||
| 123 | <span class="xRequired">$services.localization.render('githubimporter.validation.required')</span> | ||
| 124 | </label> | ||
| 125 | <span class="xHint">$services.localization.render('githubimporter.source.url.hint')</span> | ||
| 126 | </dt> | ||
| 127 | <dd class="githubimporter_properties_descriptor_source#if($request.import && $request.get('githubimporter_sourcetype') != "url") hidden#end"> | ||
| 128 | <input id="githubimporter_properties_descriptor_source_input" name="githubimporter_properties_descriptor_source" type="text" | ||
| 129 | #if($request.get('githubimporter_sourcetype') == "url") required #end | ||
| 130 | value="#if($request.import && $request.get('githubimporter_properties_descriptor_source'))$request.get('githubimporter_properties_descriptor_source')#end" | ||
| 131 | pattern="[(http(s)?):\/\/(www\.)?a-zA-Z0-9@:%._\+~#=]{2,256}\.[a-z]{2,6}\b([-a-zA-Z0-9@:%_\+.~#?&//=]*\.git)" title="Repository URL is invalid."/> | ||
| 132 | </dd> | ||
| 133 | <dt class="githubimporter_properties_descriptor_source_file#if($request.get('githubimporter_sourcetype') != "file") hidden#end"> | ||
| 134 | <label for="githubimporter_properties_descriptor_source_file"> | ||
| 135 | $services.localization.render('githubimporter.source.file.title') | ||
| 136 | <span class="xRequired">$services.localization.render('githubimporter.validation.required')</span> | ||
| 137 | </label> | ||
| 138 | <span class="xHint">$services.localization.render('githubimporter.source.file.hint')</span> | ||
| 139 | </dt> | ||
| 140 | <dd class="githubimporter_properties_descriptor_source_file#if($request.get('githubimporter_sourcetype') != "file") hidden#end"> | ||
| 141 | <input id="githubimporter_properties_descriptor_source_file_input" name="githubimporter_properties_descriptor_source_file" type="text" | ||
| 142 | #if($request.get('githubimporter_sourcetype') == "file") required #end | ||
| 143 | value="#if($request.import && $request.get('githubimporter_properties_descriptor_source_file'))$request.get('githubimporter_properties_descriptor_source_file')#end" | ||
| 144 | pattern="((^\/.*[a-zA-Z])|(^[a-zA-Z]:))(\\|\/)[\\\S|*\S]?((.*\.zip)|((([^\.]*))))$" title="This path is invalid."/> | ||
| 145 | </dd> | ||
| 146 | <dt> | ||
| 147 | <label for="githubimporter_properties_descriptor_parent"> | ||
| 148 | $services.localization.render('githubimporter.parent.title') | ||
| 149 | <span class="xRequired">$services.localization.render('githubimporter.validation.required')</span> | ||
| 150 | </label> | ||
| 151 | <span class="xHint">$services.localization.render('githubimporter.parent.hint')</span> | ||
| 152 | </dt> | ||
| 153 | <dd> | ||
| 154 | <input id="githubimporter_properties_descriptor_parent" name="githubimporter_properties_descriptor_parent" type="text" required | ||
| 155 | value="#if($request.import)$request.get('githubimporter_properties_descriptor_parent')#end"/> | ||
| 156 | </dd> | ||
| 157 | <dt> | ||
| 158 | <label for="githubimporter_properties_descriptor_username">$services.localization.render('githubimporter.authenticator.title')</label> | ||
| 159 | <span class="xHint">$services.localization.render('githubimporter.authenticator.hint', | ||
| 160 | ['<a href="https://docs.github.com/en/github/authenticating-to-github/creating-a-personal-access-token">', '</a>']) | ||
| 161 | </span> | ||
| 162 | </dt> | ||
| 163 | <dd> | ||
| 164 | <input id="githubimporter_properties_descriptor_username" name="githubimporter_properties_descriptor_username" type="text" | ||
| 165 | value="#if($request.import)$request.get('githubimporter_properties_descriptor_username')#end"/> | ||
| 166 | </dd> | ||
| 167 | <dt> | ||
| 168 | <label for="githubimporter_properties_descriptor_authCode">$services.localization.render('githubimporter.password.title')</label> | ||
| 169 | <span class="xHint">$services.localization.render('githubimporter.password.hint')</span> | ||
| 170 | </dt> | ||
| 171 | <dd> | ||
| 172 | <input id="githubimporter_properties_descriptor_authCode" name="githubimporter_properties_descriptor_authCode" type="password" | ||
| 173 | value="#if($request.import)$request.get('githubimporter_properties_descriptor_authCode')#end"/> | ||
| 174 | </dd> | ||
| 175 | <dt> | ||
| 176 | <label for="githubimporter_properties_descriptor_convertSyntax">$services.localization.render('githubimporter.convertsyntax.title')</label> | ||
| 177 | <span class="xHint">$services.localization.render('githubimporter.convertsyntax.hint')</span> | ||
| 178 | </dt> | ||
| 179 | <dd> | ||
| 180 | <input id="githubimporter_properties_descriptor_convertSyntax" name="githubimporter_properties_descriptor_convertSyntax" type="checkbox" value="true" | ||
| 181 | #if(!$request.import) checked#elseif($request.get('githubimporter_properties_descriptor_convertSyntax')) checked#end/> | ||
| 182 | </dd> | ||
| 183 | <dt> | ||
| 184 | <label for="githubimporter_properties_descriptor_createHierarchy">$services.localization.render('githubimporter.createhierarchy.title')</label> | ||
| 185 | <span class="xHint">$services.localization.render('githubimporter.createhierarchy.hint')</span> | ||
| 186 | </dt> | ||
| 187 | <dd> | ||
| 188 | <input id="githubimporter_properties_descriptor_createHierarchy" name="githubimporter_properties_descriptor_createHierarchy" type="checkbox" value="true" | ||
| 189 | #if(!$request.import) checked#elseif($request.get('githubimporter_properties_descriptor_createHierarchy')) checked#end/> | ||
| 190 | </dd> | ||
| 191 | </dl> | ||
| 192 | <p> | ||
| 193 | <span class="buttonwrapper"> | ||
| 194 | <input class="button" type="submit" name="import" value="$services.localization.render('githubimporter.button.import')" /> | ||
| 195 | </span> | ||
| 196 | </p> | ||
| 197 | </fieldset> | ||
| 198 | </form> | ||
| 199 | {{/html}} | ||
| 200 | {{/velocity}} |