Skip to content
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

Auto fix outdated links in comments and documentation #19325

Open
wants to merge 27 commits into
base: master
Choose a base branch
from

Conversation

WinterSilence
Copy link
Contributor

@WinterSilence WinterSilence commented Mar 25, 2022

Adds \yii\build\helpers\LinkChecker to checking links (caches results)
Adds \yii\build\controller\FixLinksController to finding links, replacing updated links and logging removed links
Adds Github workflow cron-outdated-links.yml runing FixLinksController every day

Q A
Is bugfix?
New feature?
Breaks BC?
Fixed issues #19314

@WinterSilence WinterSilence marked this pull request as ready for review March 25, 2022 22:22
Copy link
Member

@samdark samdark left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks 👍

@samdark samdark added this to the infrastructure milestone Mar 29, 2022
@samdark samdark requested a review from a team March 29, 2022 20:46
build/controllers/FixLinksController.php Outdated Show resolved Hide resolved
@WinterSilence WinterSilence requested review from samdark and removed request for a team April 3, 2022 08:41
@samdark
Copy link
Member

samdark commented Apr 5, 2022

Still errors:

❯ ./build/build fix-links
PHP Warning 'yii\base\ErrorException' with message 'Undefined array key "http://www.yiiframework.com"'

in /Users/samdark/src/yii2/build/helpers/LinkChecker.php:72

Stack trace:
#0 /Users/samdark/src/yii2/build/helpers/LinkChecker.php(72): yii\base\ErrorHandler->handleError(2, 'Undefined array...', '/Users/samdark/...', 72)
#1 /Users/samdark/src/yii2/build/helpers/LinkChecker.php(37): yii\build\helpers\LinkChecker->checkUrl('http://www.yiif...')
#2 /Users/samdark/src/yii2/build/controllers/FixLinksController.php(158): yii\build\helpers\LinkChecker->check('http://www.yiif...')
#3 /Users/samdark/src/yii2/build/controllers/FixLinksController.php(77): yii\build\controllers\FixLinksController->findOutdatedLinks('/**\n * @link ht...')
#4 /Users/samdark/src/yii2/build/controllers/FixLinksController.php(41): yii\build\controllers\FixLinksController->fixSources()
#5 [internal function]: yii\build\controllers\FixLinksController->actionIndex()
#6 /Users/samdark/src/yii2/framework/base/InlineAction.php(57): call_user_func_array(Array, Array)
#7 /Users/samdark/src/yii2/framework/base/Controller.php(178): yii\base\InlineAction->runWithParams(Array)
#8 /Users/samdark/src/yii2/framework/console/Controller.php(182): yii\base\Controller->runAction('', Array)
#9 /Users/samdark/src/yii2/framework/base/Module.php(552): yii\console\Controller->runAction('', Array)
#10 /Users/samdark/src/yii2/framework/console/Application.php(180): yii\base\Module->runAction('fix-links', Array)
#11 /Users/samdark/src/yii2/framework/console/Application.php(147): yii\console\Application->runAction('fix-links', Array)
#12 /Users/samdark/src/yii2/framework/base/Application.php(384): yii\console\Application->handleRequest(Object(yii\console\Request))
#13 /Users/samdark/src/yii2/build/build(40): yii\base\Application->run()
#14 {main}

@WinterSilence
Copy link
Contributor Author

WinterSilence commented Apr 5, 2022

@samdark нет бы, помочь.. поправил.

need filter test/dummy hosts in LinkChecker: now, links like as http://www.myserver.com and http://www.example.com/images/logo.gif in "outdated" list.

@samdark
Copy link
Member

samdark commented Apr 6, 2022

It takes forever to check all links but it seems it works. There are some issues though:

  1. https://www.yiiframework.com/extension/yiisoft/yii2-twig/doc/guide/ is replaced with https://www.yiiframework.com/extension/yiisoft/yii2-twig/doc/guide/2.4/en/. First link always leads to latest version.
  2. Same for https://phpunit.de/manual/current/en/writing-tests-for-phpunit.html.
  3. https://developer.mozilla.org/en-US/docs/HTTP/Access_control_CORS was replaced with /en-us/docs/web/http/cors.
  4. https://www.microsoft.com/sql-server/ was replaced with https://www.microsoft.com/en-us/sql-server?rtc=1/ i.e. it's language specific URL now instead of generic routing page.
  5. https://www.oracle.com/database/ was replaced with /database/.

@samdark
Copy link
Member

samdark commented Apr 6, 2022

Judging on these, I'm not sure it's a good idea to add it to pipeline to automatically fix things.

@WinterSilence
Copy link
Contributor Author

WinterSilence commented Apr 6, 2022

https://www.yiiframework.com/extension/yiisoft/yii2-twig/doc/guide/ is replaced with https://www.yiiframework.com/extension/yiisoft/yii2-twig/doc/guide/2.4/en/. First link always leads to latest version.

Permanent redirects codes: 301 and 308.
Temporary redirects: 302 and 307.
i.е. https://www.yiiframework.com return invalid code and why https://www.yiiframework.com redirect twice?
We can skip temporary redirects.

https://www.microsoft.com/sql-server/ was replaced with https://www.microsoft.com/en-us/sql-server?rtc=1/ i.e. it's language specific URL now instead of generic routing page.

English manual must contains links to en pages, Russian manual must contains links to ru pages and etc.

@WinterSilence
Copy link
Contributor Author

@samdark partially fixed

I'm not sure it's a good idea to add it to pipeline to automatically fix things.

at first, need collect links like as https://phpunit.de/manual/current/en/writing-tests-for-phpunit.html and append to ignore list, at next callings we replaces permanently redirected links .

Add option `FixLinksController::$safeMode`
Fix trimming in `findOutdatedLinks()`
@WinterSilence
Copy link
Contributor Author

@samdark add safe mode to collect links without changes in files

Copy link

codecov bot commented Mar 13, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 48.02%. Comparing base (b0aa6ab) to head (a2070d3).

Additional details and impacted files
@@           Coverage Diff           @@
##           master   #19325   +/-   ##
=======================================
  Coverage   48.02%   48.02%           
=======================================
  Files         445      445           
  Lines       43892    43892           
=======================================
  Hits        21080    21080           
  Misses      22812    22812           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants