-
Notifications
You must be signed in to change notification settings - Fork 81
IBX-4175: Add links checker #2130
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: 5.0
Are you sure you want to change the base?
Changes from all commits
0bf03af
f784962
e11f4a5
aec9328
277f1df
a1a0f26
825bde6
fcf3082
69570ba
f2be2cb
ec9d1cc
0fe6da3
7d77edb
c17a6ac
96332d4
96a01ee
b116b6a
0e767f4
a0f2d7d
aefb01c
61a9d47
aeba155
bd693ac
e4b8629
eb12bbb
3c19be4
05dd9ee
70d99cb
6787efb
6e5e404
3d6300f
cd6809a
8bc9732
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,202 @@ | ||||||||
| <?php | ||||||||
|
|
||||||||
| $usageFiles = call_user_func(function (array $a): array { | ||||||||
| asort($a); | ||||||||
| return $a; | ||||||||
| }, (new Finder('./docs')) | ||||||||
|
Check failure on line 6 in tools/links/links.config.php
|
||||||||
|
|
||||||||
| ->includeName('*.md') | ||||||||
| ->excludeName('new_in_doc.md')//TMP | ||||||||
| ->excludeWholeName('./docs/release_notes/*')//TMP | ||||||||
| ->excludeWholeName('./docs/snippets/*')//TMP | ||||||||
| ->excludeWholeName('./docs/update_and_migration/*')//TMP | ||||||||
|
|
||||||||
| //->includeName('*.html') // Memory issues | ||||||||
| ->includeWholeName('./**/php_api_reference/index.html') // Should be enough | ||||||||
|
|
||||||||
| ->find(), | ||||||||
| ); | ||||||||
|
|
||||||||
| $resourceFiles = call_user_func(function (array $a): array { | ||||||||
| asort($a); | ||||||||
| return $a; | ||||||||
| }, | ||||||||
| // Images | ||||||||
| (new Finder('./docs')) | ||||||||
| ->includeName('*.png') | ||||||||
| ->includeName('*.jpg') | ||||||||
| ->excludeWholeName('./docs/release_notes/img/*')//TMP | ||||||||
| ->excludeWholeName('./docs/update_and_migration/img/*')//TMP | ||||||||
| ->excludeWholeName('./docs/api/php_api/php_api_reference/images/*')//TMP | ||||||||
| ->find(), | ||||||||
| ); | ||||||||
|
|
||||||||
| $exclusionTests = array_merge_recursive(UrlTester::getDefaultExclusionTests(), [ | ||||||||
| 'url' => [ | ||||||||
| function (string $url, ?string $file = null): bool { | ||||||||
| // docs/index.md content is not Markdown but HTML with server URLs | ||||||||
| return 'docs/index.md' === $file && str_starts_with($url, 'docs/'); | ||||||||
| }, | ||||||||
| function (string $url, ?string $file = null): bool { | ||||||||
|
Check warning on line 40 in tools/links/links.config.php
|
||||||||
| // ibexa.co APIs needing authentication, namespaces, commercial aliases, etc. | ||||||||
| return str_starts_with($url, 'https://updates.ibexa.co') // 401 | ||||||||
| || str_starts_with($url, 'https://flex.ibexa.co') // 404 | ||||||||
| || str_starts_with($url, 'https://support.ibexa.co') // 302 → /login | ||||||||
| || str_starts_with($url, 'https://connect.ibexa.co') // 302 → https://ibexa.integromat.celonis.com/ | ||||||||
| || str_starts_with($url, 'http://ibexa.co/namespaces/') // 301 | ||||||||
| || str_starts_with($url, 'http://ibexa.co/xmlns/') // 301 | ||||||||
| || str_starts_with($url, 'http://ez.no/namespaces/') //301 | ||||||||
| //|| str_starts_with($url, 'http://ez.no/xmlns/') //301 | ||||||||
| || str_starts_with($url, 'https://api.cloud.ibexa.co') // 301, PLATFORMSH_CLI_API_URL | ||||||||
| //|| str_starts_with($url, 'https://admin.perso.ibexa.co/api/') // 400 | ||||||||
| || str_starts_with($url, 'https://admin.perso.ibexa.co/') // 404 | ||||||||
| || str_starts_with($url, 'https://event.perso.ibexa.co/api/') // 400 | ||||||||
| || str_starts_with($url, 'https://event.perso.ibexa.co/ebl/') // 404 | ||||||||
| || str_starts_with($url, 'https://import.perso.ibexa.co/api/') // 400 | ||||||||
| || str_starts_with($url, 'https://reco.perso.ibexa.co') // 403 | ||||||||
| || str_starts_with($url, 'https://admin.yoochoose.net') // 400 | ||||||||
| || str_starts_with($url, 'https://event.yoochoose.net/api/') // 400 | ||||||||
| || str_starts_with($url, 'https://event.yoochoose.net/ebl/') // 404 | ||||||||
| || str_starts_with($url, 'https://event.yoochoose.net/') // 404 | ||||||||
| || str_starts_with($url, 'https://reco.yoochoose.net') // 403 | ||||||||
| || str_starts_with($url, 'https://tracker.ibexa.co/') // 999 Could not resolve host | ||||||||
| ; | ||||||||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||
| }, | ||||||||
| function (string $url, ?string $file = null): bool { | ||||||||
| // Third parties APIs, namespaces, etc. | ||||||||
| return str_starts_with($url, 'https://api.fastly.com') // 301 or 403 | ||||||||
| || str_starts_with($url, 'https://unsplash.com') // 405 | ||||||||
| || str_starts_with($url, 'http://docbook.org/ns/') // 301 | ||||||||
| || str_starts_with($url, 'http://schema.org/ListItem') // 301 → https | ||||||||
| || str_starts_with($url, 'http://www.w3.org/1999/xlink') // 301 → https | ||||||||
| || str_starts_with($url, 'https://www.google.com/recaptcha/admin') // 302 → https://accounts.google.com/ServiceLogin | ||||||||
| ; | ||||||||
| }, | ||||||||
| function (string $url, ?string $file = null): bool { | ||||||||
|
Check warning on line 75 in tools/links/links.config.php
|
||||||||
| return (bool)preg_match('@(https?:)?//([a-z]+\.)?(localhost|127.0.0.1|123.456.789.0)(:[0-9]+)?(/.*|$)@', $url); | ||||||||
|
Check warning on line 76 in tools/links/links.config.php
|
||||||||
| }, | ||||||||
| function (string $url, ?string $file = null): bool { | ||||||||
|
Check warning on line 78 in tools/links/links.config.php
|
||||||||
| // Fake, placeholders, local servers, etc. | ||||||||
| return str_contains($url, 'foobar.com') | ||||||||
| || str_contains($url, 'mydomain.com') | ||||||||
| || str_contains($url, '//my_site.com') | ||||||||
| || str_contains($url, '//address.of/') | ||||||||
| || str_contains($url, '//some/file/here') | ||||||||
| || str_contains($url, '//mydoc.pdf') | ||||||||
| || str_contains($url, 'var/ezdemo_site/') | ||||||||
| || str_contains($url, '//server_uri') | ||||||||
| || str_contains($url, '//FRA_server_uri') | ||||||||
| || str_contains($url, '//user:password@host') | ||||||||
| || str_contains($url, '//user:pass@localhost') | ||||||||
Check warningCode scanning / SonarCloud Credentials should not be hard-coded Medium
Detected URI with password, review this potentially hardcoded credential. See more on SonarQube Cloud
|
||||||||
|
|
||||||||
| || str_contains($url, '//elasticsearch:9200') | ||||||||
| || str_contains($url, '//solr:8983') | ||||||||
| || str_contains($url, '//varnish:80') | ||||||||
| || str_contains($url, '//my.varnish.server') | ||||||||
| || str_contains($url, '//myuser:mypasswd@my.varnish.server') | ||||||||
|
Check warning on line 95 in tools/links/links.config.php
|
||||||||
|
|
||||||||
| || str_contains($url, 'platformsh.site') | ||||||||
| ; | ||||||||
| }, | ||||||||
| function (string $url, ?string $file = null): bool { | ||||||||
|
Check warning on line 99 in tools/links/links.config.php
|
||||||||
| return str_starts_with($url, '/assets/') | ||||||||
| || str_contains($url, '{{ asset('); | ||||||||
| }, | ||||||||
| function (string $url, ?string $file = null): bool { | ||||||||
|
Check warning on line 103 in tools/links/links.config.php
|
||||||||
| return false !== strpos($url, 'javascript:'); | ||||||||
| }, | ||||||||
| function (string $url, ?string $file = null): bool { | ||||||||
| return str_contains($url, '{{ path(') | ||||||||
| //|| str_contains($url, '{{ ez_path(') | ||||||||
| || str_contains($url, '{{ ibexa_path(') | ||||||||
| || str_contains($url, '{{ ibexa_url(') | ||||||||
| //|| str_contains($url, "|e('html_attr')") | ||||||||
| || str_contains($url, '{{ image_uri }}') | ||||||||
| || str_contains($url, '{{ ibexa_checkout_step_path(') | ||||||||
| || str_contains($url, '{{ ibexa_checkout_step_url(') | ||||||||
| ; | ||||||||
| }, | ||||||||
| function (string $url, ?string $file = null): bool { | ||||||||
| return str_ends_with($file, '/rest_api_authentication.md') | ||||||||
| && str_ends_with($url, 'web+ez:DELETE /content/locations/1/2'); | ||||||||
| }, | ||||||||
| function (string $url, ?string $file = null): bool { | ||||||||
| return str_ends_with($file, '/file_url_handling.md') | ||||||||
| && (str_contains($url, 'http://`') || str_contains($url, 'ftp://`')); | ||||||||
| }, | ||||||||
| function (string $url, ?string $file = null): bool { | ||||||||
| if (str_ends_with($file, '/php_api_reference/index.html')) { | ||||||||
| return str_contains($url, '/namespaces/symfony-contracts') || str_contains($url, '/classes/Symfony-Contracts'); | ||||||||
| } | ||||||||
| return false; | ||||||||
| }, | ||||||||
|
|
||||||||
| ], | ||||||||
| 'location' => [ | ||||||||
| function (string $url, string $location, ?string $file = null): bool { | ||||||||
|
Check warning on line 134 in tools/links/links.config.php
|
||||||||
| return str_starts_with($url, 'https://issues.ibexa.co/') && str_starts_with($location, 'https://issues.ibexa.co/login.jsp'); | ||||||||
| }, | ||||||||
| function (string $url, string $location, ?string $file = null): bool { | ||||||||
| return str_starts_with($url, 'https://symfony.com/doc/7.3/') && str_starts_with($location, 'https://symfony.com/doc/current/'); | ||||||||
| }, | ||||||||
| function (string $url, string $location, ?string $file = null): bool { | ||||||||
| return str_starts_with($url, 'https://youtu.be/') && explode('/', $url)[3] . '&feature=youtu.be' === explode('?v=', $location)[1]; | ||||||||
| }, | ||||||||
| function (string $url, string $location, ?string $file = null): bool { | ||||||||
| return str_starts_with($url, 'https://www.facebook.com/') && str_starts_with($location, 'https://www.facebook.com/unsupportedbrowser'); | ||||||||
| }, | ||||||||
| function (string $url, string $location, ?string $file = null): bool { | ||||||||
|
Check warning on line 146 in tools/links/links.config.php
|
||||||||
| return 'https://www.json.org/' === $url && 'https://www.JSON.org/json-en.html' === $location; | ||||||||
| }, | ||||||||
| function (string $url, string $location, ?string $file = null): bool { | ||||||||
| return $url === 'https://console.aws.amazon.com/iam/home#/users' | ||||||||
| && preg_match('@https://[a-z0-9-]+\.console\.aws\.amazon\.com/iam/home#/users@', $location); | ||||||||
| }, | ||||||||
| function (string $url, string $location, ?string $file = null): bool { | ||||||||
|
Check warning on line 153 in tools/links/links.config.php
|
||||||||
| return 'https://www.paypal.com/bizsignup/#/singlePageSignup' === $url && str_starts_with($location, 'https://www.paypal.com/unifiedonboarding/entry'); | ||||||||
| }, | ||||||||
| ], | ||||||||
| 'fragment' => [ | ||||||||
| /*function (string $url, ?string $file = null): bool { | ||||||||
| return str_ends_with($file, '.md') && ( | ||||||||
| // ## Commerce [[% include 'snippets/commerce_badge.md' %]] | ||||||||
| str_ends_with($url, '/permission_use_cases.md#commerce') | ||||||||
| // ### Ensure proper Captcha behavior [[% include 'snippets/experience_badge.md' %]] [[% include 'snippets/commerce_badge.md' %]] | ||||||||
| || str_ends_with($url, '/reverse_proxy.md#ensure-proper-captcha-behavior') | ||||||||
| ); | ||||||||
| },*/ | ||||||||
| function (string $url, ?string $file = null): bool { | ||||||||
|
Check warning on line 166 in tools/links/links.config.php
|
||||||||
| return str_starts_with($url, 'https://classic.yarnpkg.com/en/docs/') | ||||||||
| || str_starts_with($url, 'https://ddev.readthedocs.io/'); | ||||||||
| }, | ||||||||
| function (string $url, ?string $file = null): bool { | ||||||||
| return $url == 'https://www.paypal.com/bizsignup/#/singlePageSignup'; | ||||||||
| } | ||||||||
| ], | ||||||||
| ]); | ||||||||
|
|
||||||||
| $curlUsageTests = [ | ||||||||
| function (string $url, ?string $file = null): bool { | ||||||||
| return str_starts_with($url, 'https://docs.aws.amazon.com/'); | ||||||||
| }, | ||||||||
| function (string $url, ?string $file = null): bool { | ||||||||
|
Check warning on line 180 in tools/links/links.config.php
|
||||||||
| return str_starts_with($url, 'https://semver.org/'); | ||||||||
| }, | ||||||||
| function (string $url, ?string $file = null): bool { | ||||||||
| return str_starts_with($url, 'https://cdn.jsdelivr.net/npm/'); | ||||||||
| }, | ||||||||
| ]; | ||||||||
|
|
||||||||
| $mkdocs = yaml_parse_file('mkdocs.yml'); | ||||||||
|
|
||||||||
| $replacements = []; | ||||||||
| foreach ($mkdocs['extra'] as $key => $value) { | ||||||||
| if (is_string($value)) { | ||||||||
| $replacements['[[= ' . $key . ' =]]'] = $value; | ||||||||
| } | ||||||||
| } | ||||||||
|
|
||||||||
| $absoluteLinks = $mkdocs['validation']['links']['absolute_links'] ?? $mkdocs['validation']['absolute_links'] ?? 'info'; | ||||||||
| if ('relative_to_docs' === $absoluteLinks) { | ||||||||
| //TODO | ||||||||
| } | ||||||||
|
|
||||||||
| $find = './docs'; | ||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TODO: Check this subdomain introduced in 3638442#diff-38a9c21114f72dda086ab70f5ed479a451a285a263de16e8a8a4867a4996334cL450-R511