diff --git a/CHANGELOG b/CHANGELOG index 6ff06091f618d7bc5c0231b29837b63388d2ecdd..6ae1f8cbcdeb4a8b24a41a2d4568177e4d59baf1 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -54,6 +54,7 @@ v 8.3.0 (unreleased) - Suppress warning about missing `.gitlab-ci.yml` if builds are disabled - Do not show build status unless builds are enabled and `.gitlab-ci.yml` is present - Persist runners registration token in database + - Fix online editor should not remove newlines at the end of the file v 8.2.3 - Fix application settings cache not expiring after changes (Stan Hu) @@ -61,8 +62,6 @@ v 8.2.3 - Update documentation for "Guest" permissions - Properly convert Emoji-only comments into Award Emojis - Enable devise paranoid mode to prevent user enumeration attack - -v 8.2.3 - Webhook payload has an added, modified and removed properties for each commit - Fix 500 error when creating a merge request that removes a submodule diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 09edfc8c302c587420d4dac723080f525f86908c..7ced7c57889557f6da23e60a3a7c7e29fdfa3000 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -1,72 +1,99 @@ # Contribute to GitLab -Thank you for your interest in contributing to GitLab. -This guide details how contribute to GitLab in a way that is efficient for everyone. -If you have read this guide and want to know how the GitLab core-team operates please see [the GitLab contributing process](PROCESS.md). +Thank you for your interest in contributing to GitLab. This guide details how +to contribute to GitLab in a way that is efficient for everyone. + +GitLab comes into two flavors, GitLab Community Edition (CE) our free and open +source edition, and GitLab Enterprise Edition (EE) which is our commercial +edition. Throughout this guide you will see references to CE and EE for +abbreviation. + +If you have read this guide and want to know how the GitLab [core-team][] +operates please see [the GitLab contributing process](PROCESS.md). ## Contributor license agreement -By submitting code as an individual you agree to the [individual contributor license agreement](doc/legal/individual_contributor_license_agreement.md). By submitting code as an entity you agree to the [corporate contributor license agreement](doc/legal/corporate_contributor_license_agreement.md). +By submitting code as an individual you agree to the +[individual contributor license agreement](doc/legal/individual_contributor_license_agreement.md). +By submitting code as an entity you agree to the +[corporate contributor license agreement](doc/legal/corporate_contributor_license_agreement.md). ## Security vulnerability disclosure -Please report suspected security vulnerabilities in private to support@gitlab.com, also see the [disclosure section on the GitLab.com website](https://about.gitlab.com/disclosure/). Please do NOT create publicly viewable issues for suspected security vulnerabilities. +Please report suspected security vulnerabilities in private to +`support@gitlab.com`, also see the +[disclosure section on the GitLab.com website](https://about.gitlab.com/disclosure/). +Please do **NOT** create publicly viewable issues for suspected security +vulnerabilities. ## Closing policy for issues and merge requests -GitLab is a popular open source project and the capacity to deal with issues and merge requests is limited. Out of respect for our volunteers, issues and merge requests not in line with the guidelines listed in this document may be closed without notice. +GitLab is a popular open source project and the capacity to deal with issues +and merge requests is limited. Out of respect for our volunteers, issues and +merge requests not in line with the guidelines listed in this document may be +closed without notice. -Please treat our volunteers with courtesy and respect, it will go a long way towards getting your issue resolved. +Please treat our volunteers with courtesy and respect, it will go a long way +towards getting your issue resolved. -Issues and merge requests should be in English and contain appropriate language for audiences of all ages. +Issues and merge requests should be in English and contain appropriate language +for audiences of all ages. ## Helping others -Please help other GitLab users when you can. -The channels people will reach out on can be found on the [getting help page](https://about.gitlab.com/getting-help/). -Sign up for the mailing list, answer GitLab questions on StackOverflow or respond in the IRC channel. -You can also sign up on [CodeTriage](http://www.codetriage.com/gitlabhq/gitlabhq) to help with one issue every day. +Please help other GitLab users when you can. The channels people will reach out +on can be found on the [getting help page][]. + +Sign up for the mailing list, answer GitLab questions on StackOverflow or +respond in the IRC channel. You can also sign up on [CodeTriage][] to help with +the remaining issues on the GitHub issue tracker. ## I want to contribute! If you want to contribute to GitLab, but are not sure where to start, -look for [issues](https://gitlab.com/gitlab-org/gitlab-ce/issues?milestone_id=&scope=all&sort=created_desc&state=opened&utf8=%E2%9C%93&assignee_id=&author_id=&milestone_title=&label_name=up-for-grabs) -with the label `up-for-grabs`. -These issues will be of reasonable size and challenge, for anyone to start -contributing to GitLab. +look for [issues with the label `up-for-grabs`][up-for-grabs]. These issues +will be of reasonable size and challenge, for anyone to start contributing to +GitLab. -This was inspired by [an article by Kent C. Dodds](https://medium.com/@kentcdodds/first-timers-only-78281ea47455#.i2f363mx4). +This was inspired by [an article by Kent C. Dodds][medium-up-for-grabs]. ## Issue tracker -To get support for your particular problem please use the [getting help channels](https://about.gitlab.com/getting-help/). +To get support for your particular problem please use the +[getting help channels](https://about.gitlab.com/getting-help/). -The [GitLab CE issue tracker on GitLab.com](https://gitlab.com/gitlab-org/gitlab-ce/issues) is -for bugs in the latest GitLab release and feature proposals. +The [GitLab CE issue tracker on GitLab.com][ce-tracker] is for bugs concerning +the latest GitLab release and [feature proposals](#feature-proposals). -When submitting an issue please conform to the issue submission guidelines listed below. -Not all issues will be addressed and your issue is more likely to be addressed -if you submit a merge request which partially or fully addresses the issue. +When submitting an issue please conform to the issue submission guidelines +listed below. Not all issues will be addressed and your issue is more likely to +be addressed if you submit a merge request which partially or fully solves +the issue. -If you're unsure where to post, post to the [mailing list](https://groups.google.com/forum/#!forum/gitlabhq) -or [Stack Overflow](https://stackoverflow.com/questions/tagged/gitlab) first. -There are a lot of helpful GitLab users there who may be able to help you quickly. -If your particular issue turns out to be a bug, it will find its way from there. +If you're unsure where to post, post to the [mailing list][google-group] or +[Stack Overflow][stackoverflow] first. There are a lot of helpful GitLab users +there who may be able to help you quickly. If your particular issue turns out +to be a bug, it will find its way from there. -Please send a merge request with a tested solution or a merge request with a failing test instead of opening an issue if you can. +If it happens that you know the solution to an existing bug, please first +open the issue in order to keep track of it and then open the relevant merge +request that potentially fixes it. ### Feature proposals To create a feature proposal for CE and CI, open an issue on the -[issue tracker of CE](https://gitlab.com/gitlab-org/gitlab-ce/issues). +[issue tracker of CE][ce-tracker]. -For feature proposals for EE, open an issue on -[the issue tracker of EE](https://gitlab.com/gitlab-org/gitlab-ce/issues). +For feature proposals for EE, open an issue on the +[issue tracker of EE][ee-tracker]. -Add the label `feature proposal` to the issue. +In order to help track the feature proposals, we have created a +[`feature proposal`][fpl] label. For the time being, users that are not members +of the project cannot add labels. You can instead ask one of the [core team][] +members to add the label `feature proposal` to the issue. -Please keep feature proposals as small and simple as possible, -complex proposals might be edited to make them small and simple. +Please keep feature proposals as small and simple as possible, complex ones +might be edited to make them small and simple. For changes in the interface, it can be helpful to create a mockup first. If you want to create something yourself, consider opening an issue first to @@ -74,76 +101,143 @@ discuss whether it is interesting to include this in GitLab. ### Issue tracker guidelines -**[Search the issues](https://gitlab.com/gitlab-org/gitlab-ce/issues)** -for similar entries before submitting your own, -there's a good chance somebody else had the same issue or feature proposal. -Show your support with `:+1:` and/or join the discussion. - -Please submit bugs in the following format (as the first post): - -1. **Summary:** Summarize your issue in one sentence (what goes wrong, what did you expect to happen) -1. **Steps to reproduce:** How can we reproduce the issue -1. **Expected behavior:** Describe your issue in detail -1. **Observed behavior** -1. **Relevant logs and/or screenshots:** Please use code blocks (\`\`\`) to format console output, logs, and code as it's very hard to read otherwise. -1. **Output of checks** - * Results of GitLab [Application Check](doc/install/installation.md#check-application-status) (For installations with omnibus-gitlab package: `sudo gitlab-rake gitlab:check SANITIZE=true`); For installations from source: `sudo -u git -H bundle exec rake gitlab:check RAILS_ENV=production SANITIZE=true`); we will only investigate if the tests are passing - * Version of GitLab you are running; we will only investigate issues in the latest stable and development releases as per the [maintenance policy](MAINTENANCE.md) - * Add the last commit SHA-1 of the GitLab version you used to replicate the issue (obtainable from the help page) - * Describe your setup (use relevant parts from the env info: For installations with omnibus-gitlab package: `sudo gitlab-rake gitlab:env:info`; For installations from source: `sudo -u git -H bundle exec rake gitlab:env:info RAILS_ENV=production`) -1. **Possible fixes**: If you can, link to the line of code that might be responsible for the problem +**[Search the issue tracker][ce-tracker]** for similar entries before +submitting your own, there's a good chance somebody else had the same issue or +feature proposal. Show your support with an award emoji and/or join the +discussion. + +Please submit bugs using the following template in the issue description area. +The text in the parenthesis is there to help you with what to include. Omit it +when submitting the actual issue. You can copy-paste it and then edit as you +see fit. + +``` +## Summary + +(Summarize your issue in one sentence - what goes wrong, what did you expect to happen) + +## Steps to reproduce + +(How one can reproduce the issue - this is very important) + +## Expected behavior + +(What you should see instead) + +## Relevant logs and/or screenshots + +(Paste any relevant logs - please use code blocks (```) to format console output, +logs, and code as it's very hard to read otherwise.) + +## Output of checks + +### Results of GitLab Application Check + +(For installations with omnibus-gitlab package run and paste the output of: +sudo gitlab-rake gitlab:check SANITIZE=true) + +(For installations from source run and paste the output of: +sudo -u git -H bundle exec rake gitlab:check RAILS_ENV=production SANITIZE=true) + +(we will only investigate if the tests are passing) + +### Results of GitLab Environment Info + +(For installations with omnibus-gitlab package run and paste the output of: +sudo gitlab-rake gitlab:env:info) + +(For installations from source run and paste the output of: +sudo -u git -H bundle exec rake gitlab:env:info) + +## Possible fixes + +(If you can, link to the line of code that might be responsible for the problem) + +``` ## Merge requests -We welcome merge requests with fixes and improvements to GitLab code, tests, and/or documentation. The features we would really like a merge request for are listed with the -[label 'accepting merge requests' on our issue tracker for CE](https://gitlab.com/gitlab-org/gitlab-ce/issues?milestone_id=&scope=all&sort=created_desc&state=opened&utf8=%E2%9C%93&assignee_id=&author_id=&milestone_title=&label_name=Accepting+Merge+Requests) -and [EE](https://gitlab.com/gitlab-org/gitlab-ee/issues?milestone_id=&scope=all&sort=created_desc&state=opened&utf8=%E2%9C%93&assignee_id=&author_id=&milestone_title=&label_name=Accepting+Merge+Requests) -but other improvements are also welcome. -If you want to add a new feature that is not labeled it is best to first create a feedback issue (if there isn't one already) and leave a comment asking for it to be marked accepting merge requests. -Please include screenshots or wireframes if the feature will also change the UI. +We welcome merge requests with fixes and improvements to GitLab code, tests, +and/or documentation. The features we would really like a merge request for are +listed with the label [`Accepting Merge Requests` on our issue tracker for CE][accepting-mrs-ce] +and [EE][accepting-mrs-ee] but other improvements are also welcome. -Merge requests can be filed either at [gitlab.com](https://gitlab.com/gitlab-org/gitlab-ce/merge_requests) or [github.com](https://github.com/gitlabhq/gitlabhq/pulls). +If you want to add a new feature that is not labeled it is best to first create +a feedback issue (if there isn't one already) and leave a comment asking for it +to be marked as `Accepting merge requests`. Please include screenshots or +wireframes if the feature will also change the UI. -If you are new to GitLab development (or web development in general), search for the label `easyfix` ([GitLab.com](https://gitlab.com/gitlab-org/gitlab-ce/issues?label_name=easyfix), [GitHub](https://github.com/gitlabhq/gitlabhq/labels/easyfix)). Those are issues easy to fix, marked by the GitLab core-team. If you are unsure how to proceed but want to help, mention one of the core-team members to give you a hint. +Merge requests can be filed either at [GitLab.com][gitlab-mr-tracker] or at +[github.com][github-mr-tracker]. -To start with GitLab download the [GitLab Development Kit](https://gitlab.com/gitlab-org/gitlab-development-kit) and see [Development section](doc/development/README.md) in the help file. +If you are new to GitLab development (or web development in general), see the +[I want to contribute!](#i-want-to-contribute) section to get you started with +some potentially easy issues. + +To start with GitLab development download the [GitLab Development Kit][gdk] and +see the [Development section](doc/development/README.md) for some guidelines. ### Merge request guidelines -If you can, please submit a merge request with the fix or improvements including tests. If you don't know how to fix the issue but can write a test that exposes the issue we will accept that as well. In general bug fixes that include a regression test are merged quickly while new features without proper tests are least likely to receive timely feedback. The workflow to make a merge request is as follows: +If you can, please submit a merge request with the fix or improvements +including tests. If you don't know how to fix the issue but can write a test +that exposes the issue we will accept that as well. In general bug fixes that +include a regression test are merged quickly while new features without proper +tests are least likely to receive timely feedback. The workflow to make a merge +request is as follows: 1. Fork the project into your personal space on GitLab.com 1. Create a feature branch 1. Write [tests](https://gitlab.com/gitlab-org/gitlab-development-kit#running-the-tests) and code 1. Add your changes to the [CHANGELOG](CHANGELOG) -1. If you are changing the README, some documentation or other things which have no effect on the tests, add `[ci skip]` somewhere in the commit message -1. If you have multiple commits please combine them into one commit by [squashing them](https://git-scm.com/book/en/Git-Tools-Rewriting-History#Squashing-Commits) -1. Push the commit to your fork +1. If you are changing the README, some documentation or other things which + have no effect on the tests, add `[ci skip]` somewhere in the commit message +1. If you have multiple commits please combine them into one commit by + [squashing them][git-squash] +1. Push the commit(s) to your fork 1. Submit a merge request (MR) to the master branch 1. The MR title should describe the change you want to make -1. The MR description should give a motive for your change and the method you used to achieve it +1. The MR description should give a motive for your change and the method you + used to achieve it 1. If the MR changes the UI it should include before and after screenshots -1. If the MR changes CSS classes please include the list of affected pages `grep css-class ./app -R` -1. Link relevant [issues](https://gitlab.com/gitlab-org/gitlab-ce/issues) -from the merge request description and leave a comment on them with a link back to the MR -1. Be prepared to answer questions and incorporate feedback even if requests for this arrive weeks or months after your MR submission -1. If your MR touches code that executes shell commands, make sure it adheres to the [shell command guidelines]( doc/development/shell_commands.md). -1. Also have a look at the [shell command guidelines](doc/development/shell_commands.md) if your code reads or opens files, or handles paths to files on disk. -1. If your code creates new files on disk please read the [shared files guidelines](doc/development/shared_files.md). - -The **official merge window** is in the beginning of the month from the 1st to the 7th day of the month. The best time to submit a MR and get feedback fast. -Before this time the GitLab B.V. team is still dealing with work that is created by the monthly release such as regressions requiring patch releases. -After the 7th it is already getting closer to the release date of the next version. This means there is less time to fix the issues created by merging large new features. - -Please keep the change in a single MR **as small as possible**. If you want to contribute a large feature think very hard what the minimum viable change is. Can you split functionality? Can you only submit the backend/API code? Can you start with a very simple UI? Can you do part of the refactor? The increased reviewability of small MR's that leads to higher code quality is more important to us than having a minimal commit log. The smaller a MR is the more likely it is it will be merged (quickly), after that you can send more MR's to enhance it. - -For examples of feedback on merge requests please look at already [closed merge requests](https://gitlab.com/gitlab-org/gitlab-ce/merge_requests?assignee_id=&label_name=&milestone_id=&scope=&sort=&state=closed). If you would like quick feedback on your merge request feel free to mention one of the Merge Marshalls of [the core-team](https://about.gitlab.com/core-team/). Please ensure that your merge request meets the contribution acceptance criteria. +1. If the MR changes CSS classes please include the list of affected pages + `grep css-class ./app -R` +1. Link any relevant [issues][ce-tracker] in the merge request description and + leave a comment on them with a link back to the MR +1. Be prepared to answer questions and incorporate feedback even if requests + for this arrive weeks or months after your MR submission +1. If your MR touches code that executes shell commands, reads or opens files or + handles paths to files on disk, make sure it adheres to the + [shell command guidelines](doc/development/shell_commands.md) +1. If your code creates new files on disk please read the + [shared files guidelines](doc/development/shared_files.md). + +The **official merge window** is in the beginning of the month from the 1st to +the 7th day of the month. This is the best time to submit an MR and get +feedback fast. Before this time the GitLab Inc. team is still dealing with work +that is created by the monthly release such as regressions requiring patch +releases. After the 7th it is already getting closer to the release date of the +next version. This means there is less time to fix the issues created by +merging large new features. + +Please keep the change in a single MR **as small as possible**. If you want to +contribute a large feature think very hard what the minimum viable change is. +Can you split the functionality? Can you only submit the backend/API code? Can +you start with a very simple UI? Can you do part of the refactor? The increased +reviewability of small MRs that leads to higher code quality is more important +to us than having a minimal commit log. The smaller an MR is the more likely it +is it will be merged (quickly). After that you can send more MRs to enhance it. + +For examples of feedback on merge requests please look at already +[closed merge requests][]. If you would like quick feedback on your merge +request feel free to mention one of the Merge Marshalls of the [core team][]. +Please ensure that your merge request meets the contribution acceptance criteria. ## Definition of done -If you contribute to GitLab please know that changes involve more than just code. -We have the following [definition of done](http://guide.agilealliance.org/guide/definition-of-done.html). -Please ensure you support the feature you contribute through all of these steps. +If you contribute to GitLab please know that changes involve more than just +code. We have the following [definition of done][]. Please ensure you support +the feature you contribute through all of these steps. 1. Description explaining the relevancy (see following item) 1. Working and clean code that is commented where needed @@ -157,14 +251,16 @@ Please ensure you support the feature you contribute through all of these steps. 1. Community questions answered 1. Answers to questions radiated (in docs/wiki/etc.) -If you add a dependency in GitLab (such as an operating system package) please consider updating the following and note the applicability of each in your merge request: +If you add a dependency in GitLab (such as an operating system package) please +consider updating the following and note the applicability of each in your +merge request: 1. Note the addition in the release blog post (create one if it doesn't exist yet) https://gitlab.com/gitlab-com/www-gitlab-com/merge_requests/ 1. Upgrade guide, for example https://gitlab.com/gitlab-org/gitlab-ce/blob/master/doc/update/7.5-to-7.6.md 1. Upgrader https://gitlab.com/gitlab-org/gitlab-ce/blob/master/doc/update/upgrader.md#2-run-gitlab-upgrade-tool 1. Installation guide https://gitlab.com/gitlab-org/gitlab-ce/blob/master/doc/install/installation.md#1-packages-dependencies 1. GitLab Development Kit https://gitlab.com/gitlab-org/gitlab-development-kit -1. Test suite https://gitlab.com/gitlab-org/gitlab-ci/blob/master/doc/examples/configure_a_runner_to_run_the_gitlab_ce_test_suite.md +1. Test suite https://gitlab.com/gitlab-org/gitlab-ce/blob/master/scripts/prepare_build.sh 1. Omnibus package creator https://gitlab.com/gitlab-org/omnibus-gitlab ## Merge request description format @@ -178,53 +274,105 @@ If you add a dependency in GitLab (such as an operating system package) please c ## Contribution acceptance criteria 1. The change is as small as possible (see the above paragraph for details) -1. Include proper tests and make all tests pass (unless it contains a test exposing a bug in existing code) -1. All tests have to pass, if you suspect a failing CI build is unrelated to your contribution ask for tests to be restarted. See [the CI setup document](http://doc.gitlab.com/ce/development/ci_setup.html) on who you can ask for test restart. -1. Initially contains a single commit (please use `git rebase -i` to squash commits) -1. Can merge without problems (if not please merge `master`, never rebase commits pushed to the remote server) +1. Include proper tests and make all tests pass (unless it contains a test + exposing a bug in existing code) +1. If you suspect a failing CI build is unrelated to your contribution, you may + try and restart the failing CI job or ask a developer to fix the + aforementioned failing test +1. Your MR initially contains a single commit (please use `git rebase -i` to + squash commits) +1. Your changes can merge without problems (if not please merge `master`, never + rebase commits pushed to the remote server) 1. Does not break any existing functionality -1. Fixes one specific issue or implements one specific feature (do not combine things, send separate merge requests if needed) -1. Migrations should do only one thing (eg: either create a table, move data to a new table or remove an old table) to aid retrying on failure +1. Fixes one specific issue or implements one specific feature (do not combine + things, send separate merge requests if needed) +1. Migrations should do only one thing (eg: either create a table, move data to + a new table or remove an old table) to aid retrying on failure 1. Keeps the GitLab code base clean and well structured 1. Contains functionality we think other users will benefit from too 1. Doesn't add configuration options since they complicate future changes -1. Changes after submitting the merge request should be in separate commits (no squashing). You will be asked to squash when the review is over, before merging. -1. It conforms to the following style guides. - If your change touches a line that does not follow the style, - modify the entire line to follow it. This prevents linting tools from generating warnings. - Don't touch neighbouring lines. As an exception, automatic mass refactoring modifications - may leave style non-compliant. +1. Changes after submitting the merge request should be in separate commits + (no squashing). If necessary, you will be asked to squash when the review is + over, before merging. +1. It conforms to the following style guides: + * If your change touches a line that does not follow the style, modify the + entire line to follow it. This prevents linting tools from generating warnings. + * Don't touch neighbouring lines. As an exception, automatic mass + refactoring modifications may leave style non-compliant. ## Style guides 1. [Ruby](https://github.com/bbatsov/ruby-style-guide). - Important sections include [Source Code Layout](https://github.com/bbatsov/ruby-style-guide#source-code-layout) - and [Naming](https://github.com/bbatsov/ruby-style-guide#naming). Use: + Important sections include [Source Code Layout][rss-source] and + [Naming][rss-naming]. Use: - multi-line method chaining style **Option B**: dot `.` on previous line - string literal quoting style **Option A**: single quoted by default 1. [Rails](https://github.com/bbatsov/rails-style-guide) -1. [Testing](https://github.com/thoughtbot/guides/tree/master/style#testing) -1. [CoffeeScript](https://github.com/thoughtbot/guides/tree/master/style#coffeescript) -1. [Shell commands](doc/development/shell_commands.md) created by GitLab contributors to enhance security +1. [Testing](https://github.com/thoughtbot/guides/tree/master/style/testing) +1. [CoffeeScript](https://github.com/thoughtbot/guides/tree/master/style/coffeescript) +1. [Shell commands](doc/development/shell_commands.md) created by GitLab + contributors to enhance security 1. [Markdown](http://www.cirosantilli.com/markdown-styleguide) 1. [Database Migrations](doc/development/migration_style_guide.md) 1. [Documentation styleguide](doc_styleguide.md) -1. Interface text should be written subjectively instead of objectively. It should be the GitLab core team addressing a person. It should be written in present time and never use past tense (has been/was). For example instead of "prohibited this user from being saved due to the following errors:" the text should be "sorry, we could not create your account because:". Also these [excellent writing guidelines](https://github.com/NARKOZ/guides#writing). +1. Interface text should be written subjectively instead of objectively. It + should be the GitLab core team addressing a person. It should be written in + present time and never use past tense (has been/was). For example instead + of _prohibited this user from being saved due to the following errors:_ the + text should be _sorry, we could not create your account because:_ -This is also the style used by linting tools such as [RuboCop](https://github.com/bbatsov/rubocop), [PullReview](https://www.pullreview.com/) and [Hound CI](https://houndci.com). +This is also the style used by linting tools such as +[RuboCop](https://github.com/bbatsov/rubocop), +[PullReview](https://www.pullreview.com/) and [Hound CI](https://houndci.com). ## Code of conduct -As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities. - -We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, ethnicity, age, or religion. - -Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct. - -Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team. - -This code of conduct applies both within project spaces and in public spaces when an individual is representing the project or its community. - -Instances of abusive, harassing, or otherwise unacceptable behavior can be reported by emailing contact@gitlab.com - -This Code of Conduct is adapted from the [Contributor Covenant](http://contributor-covenant.org), version 1.1.0, available at [http://contributor-covenant.org/version/1/1/0/](http://contributor-covenant.org/version/1/1/0/) \ No newline at end of file +As contributors and maintainers of this project, we pledge to respect all +people who contribute through reporting issues, posting feature requests, +updating documentation, submitting pull requests or patches, and other +activities. + +We are committed to making participation in this project a harassment-free +experience for everyone, regardless of level of experience, gender, gender +identity and expression, sexual orientation, disability, personal appearance, +body size, race, ethnicity, age, or religion. + +Examples of unacceptable behavior by participants include the use of sexual +language or imagery, derogatory comments or personal attacks, trolling, public +or private harassment, insults, or other unprofessional conduct. + +Project maintainers have the right and responsibility to remove, edit, or +reject comments, commits, code, wiki edits, issues, and other contributions +that are not aligned to this Code of Conduct. Project maintainers who do not +follow the Code of Conduct may be removed from the project team. + +This code of conduct applies both within project spaces and in public spaces +when an individual is representing the project or its community. + +Instances of abusive, harassing, or otherwise unacceptable behavior can be +reported by emailing `contact@gitlab.com`. + +This Code of Conduct is adapted from the [Contributor Covenant][], version 1.1.0, +available at [http://contributor-covenant.org/version/1/1/0/](http://contributor-covenant.org/version/1/1/0/). + +[core team]: https://about.gitlab.com/core-team/ +[getting help page]: https://about.gitlab.com/getting-help/ +[Codetriage]: http://www.codetriage.com/gitlabhq/gitlabhq +[up-for-grabs]: https://gitlab.com/gitlab-org/gitlab-ce/issues?label_name=up+for+grabs +[medium-up-for-grabs]: https://medium.com/@kentcdodds/first-timers-only-78281ea47455 +[ce-tracker]: https://gitlab.com/gitlab-org/gitlab-ce/issues +[ee-tracker]: https://gitlab.com/gitlab-org/gitlab-ee/issues +[google-group]: https://groups.google.com/forum/#!forum/gitlabhq +[stackoverflow]: https://stackoverflow.com/questions/tagged/gitlab +[fpl]: https://gitlab.com/gitlab-org/gitlab-ce/issues?label_name=feature+proposal +[accepting-mrs-ce]: https://gitlab.com/gitlab-org/gitlab-ce/issues?label_name=Accepting+Merge+Requests +[accepting-mrs-ee]: https://gitlab.com/gitlab-org/gitlab-ee/issues?label_name=Accepting+Merge+Requests +[gitlab-mr-tracker]: https://gitlab.com/gitlab-org/gitlab-ce/merge_requests +[github-mr-tracker]: https://github.com/gitlabhq/gitlabhq/pulls +[gdk]: https://gitlab.com/gitlab-org/gitlab-development-kit +[git-squash]: https://git-scm.com/book/en/Git-Tools-Rewriting-History#Squashing-Commits +[closed merge requests]: https://gitlab.com/gitlab-org/gitlab-ce/merge_requests?assignee_id=&label_name=&milestone_id=&scope=&sort=&state=closed +[definition of done]: http://guide.agilealliance.org/guide/definition-of-done.html +[Contributor Covenant]: http://contributor-covenant.org +[rss-source]: https://github.com/bbatsov/ruby-style-guide/blob/master/README.md#source-code-layout +[rss-naming]: https://github.com/bbatsov/ruby-style-guide/blob/master/README.md#naming diff --git a/app/assets/stylesheets/framework/panels.scss b/app/assets/stylesheets/framework/panels.scss index 61053aff91a27185066b1aee3b65bd32f765dddd..57b9451b264d95f6a5a66c52e51ee35d55930f84 100644 --- a/app/assets/stylesheets/framework/panels.scss +++ b/app/assets/stylesheets/framework/panels.scss @@ -3,7 +3,6 @@ .panel-heading { padding: 7px $gl-padding; - line-height: 42px !important; } .panel-body { @@ -15,3 +14,7 @@ } } } + +.container-blank .panel .panel-heading { + line-height: 42px !important; +} diff --git a/app/assets/stylesheets/framework/variables.scss b/app/assets/stylesheets/framework/variables.scss index 91954683c3e8db28989abfd7fd970c2e35cd3a73..2ef40a6e51738724399a45b592faf9a30c757152 100644 --- a/app/assets/stylesheets/framework/variables.scss +++ b/app/assets/stylesheets/framework/variables.scss @@ -19,7 +19,7 @@ $border-color: #dce0e6; $table-border-color: #eef0f2; $background-color: #F7F8FA; $header-height: 58px; -$fixed-layout-width: 1200px; +$fixed-layout-width: 1280px; $gl-gray: #7f8fa4; $gl-padding: 16px; $gl-avatar-size: 46px; diff --git a/app/controllers/projects/notes_controller.rb b/app/controllers/projects/notes_controller.rb index 88b949a27ab931bc823a5e2856a5630ea958136c..ae6e9f6fd3857dd51a88b02f37fa46abb3955c85 100644 --- a/app/controllers/projects/notes_controller.rb +++ b/app/controllers/projects/notes_controller.rb @@ -13,7 +13,8 @@ class Projects::NotesController < Projects::ApplicationController @notes.each do |note| notes_json[:notes] << { id: note.id, - html: note_to_html(note) + html: note_to_html(note), + valid: note.valid? } end diff --git a/app/helpers/gitlab_markdown_helper.rb b/app/helpers/gitlab_markdown_helper.rb index 5004e02ea0b396269f8f165e3b377e6255cd06ad..a0cf3dc084398fb165f9919af8003c5e76c596a4 100644 --- a/app/helpers/gitlab_markdown_helper.rb +++ b/app/helpers/gitlab_markdown_helper.rb @@ -20,7 +20,7 @@ module GitlabMarkdownHelper end user = current_user if defined?(current_user) - gfm_body = Gitlab::Markdown.render(escaped_body, project: @project, current_user: user, pipeline: :single_line) + gfm_body = Banzai.render(escaped_body, project: @project, current_user: user, pipeline: :single_line) fragment = Nokogiri::HTML::DocumentFragment.parse(gfm_body) if fragment.children.size == 1 && fragment.children[0].name == 'a' @@ -50,7 +50,7 @@ module GitlabMarkdownHelper context[:project] ||= @project - html = Gitlab::Markdown.render(text, context) + html = Banzai.render(text, context) context.merge!( current_user: (current_user if defined?(current_user)), @@ -61,7 +61,7 @@ module GitlabMarkdownHelper ref: @ref ) - Gitlab::Markdown.post_process(html, context) + Banzai.post_process(html, context) end def asciidoc(text) diff --git a/app/helpers/issues_helper.rb b/app/helpers/issues_helper.rb index e66b9c628c79d4053d927e553acedab6a6f95976..cdf7038b2f27770d97b1b830a9011932d471be30 100644 --- a/app/helpers/issues_helper.rb +++ b/app/helpers/issues_helper.rb @@ -121,6 +121,6 @@ module IssuesHelper end end - # Required for Gitlab::Markdown::IssueReferenceFilter + # Required for Banzai::Filter::IssueReferenceFilter module_function :url_for_issue end diff --git a/app/helpers/labels_helper.rb b/app/helpers/labels_helper.rb index 795fb439f256ba5bba14acda80f938fbd61b91c7..a2c3d4d2f327d2aba74684daba41300b5f8c233a 100644 --- a/app/helpers/labels_helper.rb +++ b/app/helpers/labels_helper.rb @@ -107,6 +107,6 @@ module LabelsHelper options_from_collection_for_select(grouped_labels, 'name', 'title', params[:label_name]) end - # Required for Gitlab::Markdown::LabelReferenceFilter + # Required for Banzai::Filter::LabelReferenceFilter module_function :render_colored_label, :text_color_for_bg, :escape_once end diff --git a/app/models/concerns/mentionable.rb b/app/models/concerns/mentionable.rb index d2ea9ab731332638c09dfa176d86612e479aad7e..d4e3099453dce57e0a7b7a4188c4ff625fea2517 100644 --- a/app/models/concerns/mentionable.rb +++ b/app/models/concerns/mentionable.rb @@ -23,7 +23,7 @@ module Mentionable included do if self < Participable - participant ->(current_user) { mentioned_users(current_user, load_lazy_references: false) } + participant ->(current_user) { mentioned_users(current_user) } end end @@ -43,9 +43,9 @@ module Mentionable self end - def all_references(current_user = self.author, text = nil, load_lazy_references: true) - ext = Gitlab::ReferenceExtractor.new(self.project, current_user, load_lazy_references: load_lazy_references) - + def all_references(current_user = self.author, text = nil) + ext = Gitlab::ReferenceExtractor.new(self.project, current_user) + if text ext.analyze(text) else @@ -59,13 +59,13 @@ module Mentionable ext end - def mentioned_users(current_user = nil, load_lazy_references: true) - all_references(current_user, load_lazy_references: load_lazy_references).users + def mentioned_users(current_user = nil) + all_references(current_user).users end # Extract GFM references to other Mentionables from this Mentionable. Always excludes its #local_reference. - def referenced_mentionables(current_user = self.author, text = nil, load_lazy_references: true) - refs = all_references(current_user, text, load_lazy_references: load_lazy_references) + def referenced_mentionables(current_user = self.author, text = nil) + refs = all_references(current_user, text) refs = (refs.issues + refs.merge_requests + refs.commits) # We're using this method instead of Array diffing because that requires diff --git a/app/models/concerns/participable.rb b/app/models/concerns/participable.rb index 85367f89f4f381f4f8d46e2266479eacefb86904..808d80b0530fb417885ae5cf2524d77bbd0c09bc 100644 --- a/app/models/concerns/participable.rb +++ b/app/models/concerns/participable.rb @@ -38,20 +38,21 @@ module Participable # Be aware that this method makes a lot of sql queries. # Save result into variable if you are going to reuse it inside same request def participants(current_user = self.author, load_lazy_references: true) - participants = self.class.participant_attrs.flat_map do |attr| - value = - if attr.respond_to?(:call) - instance_exec(current_user, &attr) - else - send(attr) - end + participants = + Gitlab::ReferenceExtractor.lazily do + self.class.participant_attrs.flat_map do |attr| + value = + if attr.respond_to?(:call) + instance_exec(current_user, &attr) + else + send(attr) + end - participants_for(value, current_user) - end.compact.uniq - - if load_lazy_references - participants = Gitlab::Markdown::ReferenceFilter::LazyReference.load(participants).uniq + participants_for(value, current_user) + end.compact.uniq + end + unless Gitlab::ReferenceExtractor.lazy? participants.select! do |user| user.can?(:read_project, project) end @@ -64,12 +65,12 @@ module Participable def participants_for(value, current_user = nil) case value - when User, Gitlab::Markdown::ReferenceFilter::LazyReference + when User, Banzai::LazyReference [value] when Enumerable, ActiveRecord::Relation value.flat_map { |v| participants_for(v, current_user) } when Participable - value.participants(current_user, load_lazy_references: false) + value.participants(current_user) end end end diff --git a/app/models/issue.rb b/app/models/issue.rb index e04035b3af8cbb268f44be802cb0a69f0888188d..4571d7f0ee10bed4688e06811318984dd779fa6f 100644 --- a/app/models/issue.rb +++ b/app/models/issue.rb @@ -84,11 +84,11 @@ class Issue < ActiveRecord::Base end def referenced_merge_requests - references = [self, *notes].flat_map do |note| - note.all_references(load_lazy_references: false).merge_requests - end.uniq - - Gitlab::Markdown::ReferenceFilter::LazyReference.load(references).uniq.sort_by(&:iid) + Gitlab::ReferenceExtractor.lazily do + [self, *notes].flat_map do |note| + note.all_references(load_lazy_references: false).merge_requests + end + end.sort_by(&:iid) end # Reset issue events cache diff --git a/app/models/note.rb b/app/models/note.rb index 04053ccc61e0462d77a657b9d777c94f8020ef88..8c5b5836f9a2cbcf2d2b569b2042cc36629d3c6a 100644 --- a/app/models/note.rb +++ b/app/models/note.rb @@ -373,11 +373,11 @@ class Note < ActiveRecord::Base end def contains_emoji_only? - note =~ /\A#{Gitlab::Markdown::EmojiFilter.emoji_pattern}\s?\Z/ + note =~ /\A#{Banzai::Filter::EmojiFilter.emoji_pattern}\s?\Z/ end def award_emoji_name - original_name = note.match(Gitlab::Markdown::EmojiFilter.emoji_pattern)[1] + original_name = note.match(Banzai::Filter::EmojiFilter.emoji_pattern)[1] AwardEmoji.normilize_emoji_name(original_name) end end diff --git a/app/views/projects/blob/_editor.html.haml b/app/views/projects/blob/_editor.html.haml index 333f5d470ed310c771b109d9dcc2c7384355e757..10b02813733de0af679b8b8b281e6e020ede97a8 100644 --- a/app/views/projects/blob/_editor.html.haml +++ b/app/views/projects/blob/_editor.html.haml @@ -16,8 +16,7 @@ = select_tag :encoding, options_for_select([ "base64", "text" ], "text"), class: 'select2' .file-content.code - %pre.js-edit-mode-pane#editor - = params[:content] || local_assigns[:blob_data] + %pre.js-edit-mode-pane#editor #{params[:content] || local_assigns[:blob_data]} - if local_assigns[:path] .js-edit-mode-pane#preview.hide .center diff --git a/app/views/projects/notes/_notes_with_form.html.haml b/app/views/projects/notes/_notes_with_form.html.haml index 99c1b0fa43eb8135cd5c572d4d8710e17a9e1815..eb378b4260367a15996999c525430642ae2660fa 100644 --- a/app/views/projects/notes/_notes_with_form.html.haml +++ b/app/views/projects/notes/_notes_with_form.html.haml @@ -7,4 +7,4 @@ = render "projects/notes/form", view: diff_view :javascript - new Notes("#{namespace_project_notes_path(namespace_id: @project.namespace, target_id: @noteable.id, target_type: @noteable.class.name.underscore)}", #{@notes.map(&:id).to_json}, #{Time.now.to_i}, "#{diff_view}") + var notes = new Notes("#{namespace_project_notes_path(namespace_id: @project.namespace, target_id: @noteable.id, target_type: @noteable.class.name.underscore)}", #{@notes.map(&:id).to_json}, #{Time.now.to_i}, "#{diff_view}") diff --git a/doc/raketasks/README.md b/doc/raketasks/README.md index a8dc5c24df265454ac52a935df444c6d41af6631..cc8a22cd003269b388c25adfe007ff1f8ab2a3d8 100644 --- a/doc/raketasks/README.md +++ b/doc/raketasks/README.md @@ -1,10 +1,11 @@ # Rake tasks - [Backup restore](backup_restore.md) +- [Check](check.md) - [Cleanup](cleanup.md) - [Features](features.md) - [Maintenance](maintenance.md) and self-checks - [User management](user_management.md) - [Web hooks](web_hooks.md) - [Import](import.md) of git repositories in bulk -- [Rebuild authorized_keys file](http://doc.gitlab.com/ce/raketasks/maintenance.html#rebuild-authorized_keys-file) task for administrators \ No newline at end of file +- [Rebuild authorized_keys file](http://doc.gitlab.com/ce/raketasks/maintenance.html#rebuild-authorized_keys-file) task for administrators diff --git a/doc/raketasks/check.md b/doc/raketasks/check.md new file mode 100644 index 0000000000000000000000000000000000000000..3ff3fee6a40335d256a810d30054a67df6e50afd --- /dev/null +++ b/doc/raketasks/check.md @@ -0,0 +1,63 @@ +# Check Rake Tasks + +## Repository Integrity + +Even though Git is very resilient and tries to prevent data integrity issues, +there are times when things go wrong. The following Rake tasks intend to +help GitLab administrators diagnose problem repositories so they can be fixed. + +There are 3 things that are checked to determine integrity. + +1. Git repository file system check ([git fsck](https://git-scm.com/docs/git-fsck)). + This step verifies the connectivity and validity of objects in the repository. +1. Check for `config.lock` in the repository directory. +1. Check for any branch/references lock files in `refs/heads`. + +It's important to note that the existence of `config.lock` or reference locks +alone do not necessarily indicate a problem. Lock files are routinely created +and removed as Git and GitLab perform operations on the repository. They serve +to prevent data integrity issues. However, if a Git operation is interrupted these +locks may not be cleaned up properly. + +The following symptoms may indicate a problem with repository integrity. If users +experience these symptoms you may use the rake tasks described below to determine +exactly which repositories are causing the trouble. + +- Receiving an error when trying to push code - `remote: error: cannot lock ref` +- A 500 error when viewing the GitLab dashboard or when accessing a specific project. + +### Check all GitLab repositories + +This task loops through all repositories on the GitLab server and runs the +3 integrity checks described previously. + +``` +# omnibus-gitlab +sudo gitlab-rake gitlab:repo:check + +# installation from source +bundle exec rake gitlab:repo:check RAILS_ENV=production +``` + +### Check repositories for a specific user + +This task checks all repositories that a specific user has access to. This is important +because sometimes you know which user is experiencing trouble but you don't know +which project might be the cause. + +If the rake task is executed without brackets at the end, you will be prompted +to enter a username. + +```bash +# omnibus-gitlab +sudo gitlab-rake gitlab:user:check_repos +sudo gitlab-rake gitlab:user:check_repos[<username>] + +# installation from source +bundle exec rake gitlab:user:check_repos RAILS_ENV=production +bundle exec rake gitlab:user:check_repos[<username>] RAILS_ENV=production +``` + +Example output: + + diff --git a/doc/raketasks/check_repos_output.png b/doc/raketasks/check_repos_output.png new file mode 100644 index 0000000000000000000000000000000000000000..916b16851018bd6de0258f465e6e125ea56d1e0c Binary files /dev/null and b/doc/raketasks/check_repos_output.png differ diff --git a/features/project/issues/issues.feature b/features/project/issues/issues.feature index f08b30e0b88888f3feeb3299ef57b2573230b909..ab234bc7507dc3766aaa944e2d238c051f35ca89 100644 --- a/features/project/issues/issues.feature +++ b/features/project/issues/issues.feature @@ -197,3 +197,9 @@ Feature: Project Issues And I should not see labels field And I submit new issue "500 error on profile" Then I should see issue "500 error on profile" + + @javascript + Scenario: Another user adds a comment to issue I'm currently viewing + Given I visit issue page "Release 0.4" + And another user adds a comment with text "Yay!" to issue "Release 0.4" + Then I should see a new comment with text "Yay!" diff --git a/features/project/source/browse_files.feature b/features/project/source/browse_files.feature index 439787f2641e5b44c3ecec19462a6aacfe62fb94..02159ee3776e9dafa46905e7f0bb248946b31ba8 100644 --- a/features/project/source/browse_files.feature +++ b/features/project/source/browse_files.feature @@ -34,6 +34,17 @@ Feature: Project Source Browse Files Then I am redirected to the new file And I should see its new content + @javascript + Scenario: I can create and commit file with new lines at the end of file + Given I click on "New file" link in repo + And I edit code with new lines at end of file + And I fill the new file name + And I fill the commit message + And I click on "Commit Changes" + Then I am redirected to the new file + And I click button "Edit" + And I should see its content with new lines preserved at end of file + @javascript Scenario: I can upload file and commit Given I click on "Upload file" link in repo diff --git a/features/steps/project/issues/issues.rb b/features/steps/project/issues/issues.rb index a13044c3ae123a04a7e1b1d61a0ed11c9aa7e7ac..4a7ff21d385334f159f83034dea163727efa9ee8 100644 --- a/features/steps/project/issues/issues.rb +++ b/features/steps/project/issues/issues.rb @@ -284,6 +284,16 @@ class Spinach::Features::ProjectIssues < Spinach::FeatureSteps end end + step 'another user adds a comment with text "Yay!" to issue "Release 0.4"' do + issue = Issue.find_by!(title: 'Release 0.4') + create(:note_on_issue, noteable: issue, note: 'Yay!') + end + + step 'I should see a new comment with text "Yay!"' do + page.within '#notes' do + expect(page).to have_content('Yay!') + end + end def filter_issue(text) fill_in 'issue_search', with: text end diff --git a/features/steps/project/source/browse_files.rb b/features/steps/project/source/browse_files.rb index f2b957642673ed0a02b8ad9a47ec3b9a678c90db..b88709620ab82f7e90c1cd21f5c32eed629236aa 100644 --- a/features/steps/project/source/browse_files.rb +++ b/features/steps/project/source/browse_files.rb @@ -37,6 +37,10 @@ class Spinach::Features::ProjectSourceBrowseFiles < Spinach::FeatureSteps expect(page).to have_content new_gitignore_content end + step 'I should see its content with new lines preserved at end of file' do + expect(evaluate_script('blob.editor.getValue()')).to eq "Sample\n\n\n" + end + step 'I click link "Raw"' do click_link 'Raw' end @@ -62,6 +66,10 @@ class Spinach::Features::ProjectSourceBrowseFiles < Spinach::FeatureSteps set_new_content end + step 'I edit code with new lines at end of file' do + execute_script('blob.editor.setValue("Sample\n\n\n")') + end + step 'I fill the new file name' do fill_in :file_name, with: new_file_name end diff --git a/features/support/capybara.rb b/features/support/capybara.rb index 31dbf0feb2fc57897ad34de32426bc7e8ae65e31..4156c7ec484611624902b615884bb19e962312be 100644 --- a/features/support/capybara.rb +++ b/features/support/capybara.rb @@ -2,7 +2,7 @@ require 'spinach/capybara' require 'capybara/poltergeist' # Give CI some extra time -timeout = (ENV['CI'] || ENV['CI_SERVER']) ? 90 : 10 +timeout = (ENV['CI'] || ENV['CI_SERVER']) ? 90 : 15 Capybara.javascript_driver = :poltergeist Capybara.register_driver :poltergeist do |app| diff --git a/lib/banzai.rb b/lib/banzai.rb new file mode 100644 index 0000000000000000000000000000000000000000..093382261ae8552645b1c3cd2cb44ce8c0bb3538 --- /dev/null +++ b/lib/banzai.rb @@ -0,0 +1,13 @@ +module Banzai + def self.render(text, context = {}) + Renderer.render(text, context) + end + + def self.render_result(text, context = {}) + Renderer.render_result(text, context) + end + + def self.post_process(html, context) + Renderer.post_process(html, context) + end +end diff --git a/lib/banzai/cross_project_reference.rb b/lib/banzai/cross_project_reference.rb new file mode 100644 index 0000000000000000000000000000000000000000..ba2866e1efaa2f49222c41a64fd7599afb2ee94a --- /dev/null +++ b/lib/banzai/cross_project_reference.rb @@ -0,0 +1,22 @@ +require 'banzai' + +module Banzai + # Common methods for ReferenceFilters that support an optional cross-project + # reference. + module CrossProjectReference + # Given a cross-project reference string, get the Project record + # + # Defaults to value of `context[:project]` if: + # * No reference is given OR + # * Reference given doesn't exist + # + # ref - String reference. + # + # Returns a Project, or nil if the reference can't be found + def project_from_ref(ref) + return context[:project] unless ref + + Project.find_with_namespace(ref) + end + end +end diff --git a/lib/banzai/filter.rb b/lib/banzai/filter.rb new file mode 100644 index 0000000000000000000000000000000000000000..fd4fe024252db0605edda3d7c5e71170801e7030 --- /dev/null +++ b/lib/banzai/filter.rb @@ -0,0 +1,10 @@ +require 'active_support/core_ext/string/output_safety' +require 'banzai' + +module Banzai + module Filter + def self.[](name) + const_get("#{name.to_s.camelize}Filter") + end + end +end diff --git a/lib/gitlab/markdown/abstract_reference_filter.rb b/lib/banzai/filter/abstract_reference_filter.rb similarity index 98% rename from lib/gitlab/markdown/abstract_reference_filter.rb rename to lib/banzai/filter/abstract_reference_filter.rb index 9488e980c086f22756e2f59eb6ec2fee3d9ff501..bdaa4721b4bcdc863f07f1dab60f3bc4bd22f292 100644 --- a/lib/gitlab/markdown/abstract_reference_filter.rb +++ b/lib/banzai/filter/abstract_reference_filter.rb @@ -1,7 +1,7 @@ -require 'gitlab/markdown' +require 'banzai' -module Gitlab - module Markdown +module Banzai + module Filter # Issues, Merge Requests, Snippets, Commits and Commit Ranges share # similar functionality in reference filtering. class AbstractReferenceFilter < ReferenceFilter diff --git a/lib/gitlab/markdown/filter/autolink_filter.rb b/lib/banzai/filter/autolink_filter.rb similarity index 98% rename from lib/gitlab/markdown/filter/autolink_filter.rb rename to lib/banzai/filter/autolink_filter.rb index c37c3bc55bf5ca79bb5da2cbfeaccfd8c7698d32..da4ee80c1b5cadf5de6ae385251052390b5f8d72 100644 --- a/lib/gitlab/markdown/filter/autolink_filter.rb +++ b/lib/banzai/filter/autolink_filter.rb @@ -1,9 +1,9 @@ -require 'gitlab/markdown' +require 'banzai' require 'html/pipeline/filter' require 'uri' -module Gitlab - module Markdown +module Banzai + module Filter # HTML Filter for auto-linking URLs in HTML. # # Based on HTML::Pipeline::AutolinkFilter diff --git a/lib/gitlab/markdown/filter/commit_range_reference_filter.rb b/lib/banzai/filter/commit_range_reference_filter.rb similarity index 96% rename from lib/gitlab/markdown/filter/commit_range_reference_filter.rb rename to lib/banzai/filter/commit_range_reference_filter.rb index 36b3258ef761077974e1d070684bae07d5bf6dd6..e67cd45ab9bd1159c6bcd5ea3f6fc762d0ee0a69 100644 --- a/lib/gitlab/markdown/filter/commit_range_reference_filter.rb +++ b/lib/banzai/filter/commit_range_reference_filter.rb @@ -1,7 +1,7 @@ -require 'gitlab/markdown' +require 'banzai' -module Gitlab - module Markdown +module Banzai + module Filter # HTML filter that replaces commit range references with links. # # This filter supports cross-project references. diff --git a/lib/gitlab/markdown/filter/commit_reference_filter.rb b/lib/banzai/filter/commit_reference_filter.rb similarity index 96% rename from lib/gitlab/markdown/filter/commit_reference_filter.rb rename to lib/banzai/filter/commit_reference_filter.rb index e3066a89b0488b30b5621677a8b4c7e4a7519a9f..9e57608b483651dec1449ee72d2121cbee59cfb9 100644 --- a/lib/gitlab/markdown/filter/commit_reference_filter.rb +++ b/lib/banzai/filter/commit_reference_filter.rb @@ -1,7 +1,7 @@ -require 'gitlab/markdown' +require 'banzai' -module Gitlab - module Markdown +module Banzai + module Filter # HTML filter that replaces commit references with links. # # This filter supports cross-project references. diff --git a/lib/gitlab/markdown/filter/emoji_filter.rb b/lib/banzai/filter/emoji_filter.rb similarity index 97% rename from lib/gitlab/markdown/filter/emoji_filter.rb rename to lib/banzai/filter/emoji_filter.rb index da10e4d3760c6775722734a4636ae6b553ea4bd8..86838e1483c40511a15cdd03c7eb3d3e72dc6e2f 100644 --- a/lib/gitlab/markdown/filter/emoji_filter.rb +++ b/lib/banzai/filter/emoji_filter.rb @@ -1,10 +1,10 @@ require 'action_controller' -require 'gitlab/markdown' +require 'banzai' require 'gitlab_emoji' require 'html/pipeline/filter' -module Gitlab - module Markdown +module Banzai + module Filter # HTML filter that replaces :emoji: with images. # # Based on HTML::Pipeline::EmojiFilter diff --git a/lib/gitlab/markdown/filter/external_issue_reference_filter.rb b/lib/banzai/filter/external_issue_reference_filter.rb similarity index 97% rename from lib/gitlab/markdown/filter/external_issue_reference_filter.rb rename to lib/banzai/filter/external_issue_reference_filter.rb index 14bdf5521fc5fd1ddae486ba496d323cb75a1c18..f5737a7ac193afb9d40d96e7838371adefd72154 100644 --- a/lib/gitlab/markdown/filter/external_issue_reference_filter.rb +++ b/lib/banzai/filter/external_issue_reference_filter.rb @@ -1,7 +1,7 @@ -require 'gitlab/markdown' +require 'banzai' -module Gitlab - module Markdown +module Banzai + module Filter # HTML filter that replaces external issue tracker references with links. # References are ignored if the project doesn't use an external issue # tracker. diff --git a/lib/gitlab/markdown/filter/external_link_filter.rb b/lib/banzai/filter/external_link_filter.rb similarity index 91% rename from lib/gitlab/markdown/filter/external_link_filter.rb rename to lib/banzai/filter/external_link_filter.rb index e09dfcb83c87ac8d5cc295ca2e4b81d3b3ff196c..ac87b9820afe7635cd89ed2ffe98782f6e56c727 100644 --- a/lib/gitlab/markdown/filter/external_link_filter.rb +++ b/lib/banzai/filter/external_link_filter.rb @@ -1,8 +1,8 @@ -require 'gitlab/markdown' +require 'banzai' require 'html/pipeline/filter' -module Gitlab - module Markdown +module Banzai + module Filter # HTML Filter to add a `rel="nofollow"` attribute to external links # class ExternalLinkFilter < HTML::Pipeline::Filter diff --git a/lib/gitlab/markdown/filter/issue_reference_filter.rb b/lib/banzai/filter/issue_reference_filter.rb similarity index 89% rename from lib/gitlab/markdown/filter/issue_reference_filter.rb rename to lib/banzai/filter/issue_reference_filter.rb index 1ed69e2f43195a6ea4c5ad02482ec4fbba908142..51180cb901a62f4eeb72853e7f9098e748bf26e4 100644 --- a/lib/gitlab/markdown/filter/issue_reference_filter.rb +++ b/lib/banzai/filter/issue_reference_filter.rb @@ -1,7 +1,7 @@ -require 'gitlab/markdown' +require 'banzai' -module Gitlab - module Markdown +module Banzai + module Filter # HTML filter that replaces issue references with links. References to # issues that do not exist are ignored. # diff --git a/lib/gitlab/markdown/filter/label_reference_filter.rb b/lib/banzai/filter/label_reference_filter.rb similarity index 98% rename from lib/gitlab/markdown/filter/label_reference_filter.rb rename to lib/banzai/filter/label_reference_filter.rb index a2026eecaeb9018488378dc619f99d71dad4037d..07bac2dd7fd4897fcee8ea09567f803ceff03c58 100644 --- a/lib/gitlab/markdown/filter/label_reference_filter.rb +++ b/lib/banzai/filter/label_reference_filter.rb @@ -1,7 +1,7 @@ -require 'gitlab/markdown' +require 'banzai' -module Gitlab - module Markdown +module Banzai + module Filter # HTML filter that replaces label references with links. class LabelReferenceFilter < ReferenceFilter # Public: Find label references in text diff --git a/lib/gitlab/markdown/filter/markdown_filter.rb b/lib/banzai/filter/markdown_filter.rb similarity index 91% rename from lib/gitlab/markdown/filter/markdown_filter.rb rename to lib/banzai/filter/markdown_filter.rb index 921e2a0794e62c75945084628e43ba98371c7fe4..0072bab1f99e2c3b06561a4823f64bcb94846f61 100644 --- a/lib/gitlab/markdown/filter/markdown_filter.rb +++ b/lib/banzai/filter/markdown_filter.rb @@ -1,5 +1,8 @@ -module Gitlab - module Markdown +require 'banzai' +require 'html/pipeline/filter' + +module Banzai + module Filter class MarkdownFilter < HTML::Pipeline::TextFilter def initialize(text, context = nil, result = nil) super text, context, result @@ -11,8 +14,8 @@ module Gitlab html.rstrip! html end - - private + + private def self.redcarpet_options # https://github.com/vmg/redcarpet#and-its-like-really-simple-to-use diff --git a/lib/gitlab/markdown/filter/merge_request_reference_filter.rb b/lib/banzai/filter/merge_request_reference_filter.rb similarity index 94% rename from lib/gitlab/markdown/filter/merge_request_reference_filter.rb rename to lib/banzai/filter/merge_request_reference_filter.rb index 2eb77c46da7898c042a7693ea02581df04f6e135..755b946a34ba8124d73a25633f9f0913c494b94a 100644 --- a/lib/gitlab/markdown/filter/merge_request_reference_filter.rb +++ b/lib/banzai/filter/merge_request_reference_filter.rb @@ -1,7 +1,7 @@ -require 'gitlab/markdown' +require 'banzai' -module Gitlab - module Markdown +module Banzai + module Filter # HTML filter that replaces merge request references with links. References # to merge requests that do not exist are ignored. # diff --git a/lib/gitlab/markdown/filter/redactor_filter.rb b/lib/banzai/filter/redactor_filter.rb similarity index 88% rename from lib/gitlab/markdown/filter/redactor_filter.rb rename to lib/banzai/filter/redactor_filter.rb index 33ef7ce18b51a86daf12db49f2a69ed30ace8404..89e7a79789a7990feecab47884a224c31427930a 100644 --- a/lib/gitlab/markdown/filter/redactor_filter.rb +++ b/lib/banzai/filter/redactor_filter.rb @@ -1,8 +1,8 @@ -require 'gitlab/markdown' +require 'banzai' require 'html/pipeline/filter' -module Gitlab - module Markdown +module Banzai + module Filter # HTML filter that removes references to records that the current user does # not have permission to view. # @@ -27,7 +27,7 @@ module Gitlab def user_can_reference?(node) if node.has_attribute?('data-reference-filter') reference_type = node.attr('data-reference-filter') - reference_filter = Gitlab::Markdown.const_get(reference_type) + reference_filter = Banzai::Filter.const_get(reference_type) reference_filter.user_can_reference?(current_user, node, context) else diff --git a/lib/gitlab/markdown/reference_filter.rb b/lib/banzai/filter/reference_filter.rb similarity index 90% rename from lib/gitlab/markdown/reference_filter.rb rename to lib/banzai/filter/reference_filter.rb index 3b83b8bd8f880da24d42eb58152edbf51cf05ff7..33457a3f361837e6daa228047fa48080ab80d09e 100644 --- a/lib/gitlab/markdown/reference_filter.rb +++ b/lib/banzai/filter/reference_filter.rb @@ -1,9 +1,9 @@ require 'active_support/core_ext/string/output_safety' -require 'gitlab/markdown' +require 'banzai' require 'html/pipeline/filter' -module Gitlab - module Markdown +module Banzai + module Filter # Base class for GitLab Flavored Markdown reference filters. # # References within <pre>, <code>, <a>, and <style> elements are ignored. @@ -12,27 +12,6 @@ module Gitlab # :project (required) - Current project, ignored if reference is cross-project. # :only_path - Generate path-only links. class ReferenceFilter < HTML::Pipeline::Filter - LazyReference = Struct.new(:klass, :ids) do - def self.load(refs) - lazy_references, values = refs.partition { |ref| ref.is_a?(self) } - - lazy_values = lazy_references.group_by(&:klass).flat_map do |klass, refs| - ids = refs.flat_map(&:ids) - klass.where(id: ids) - end - - values + lazy_values - end - - def load - self.klass.where(id: self.ids) - end - end - - def self.[](name) - Markdown.const_get("#{name.to_s.camelize}ReferenceFilter") - end - def self.user_can_reference?(user, node, context) if node.has_attribute?('data-project') project_id = node.attr('data-project').to_i diff --git a/lib/gitlab/markdown/filter/reference_gatherer_filter.rb b/lib/banzai/filter/reference_gatherer_filter.rb similarity index 80% rename from lib/gitlab/markdown/filter/reference_gatherer_filter.rb rename to lib/banzai/filter/reference_gatherer_filter.rb index 62f241b4967df49a10bfe2be40931cb8b58f4efd..855f238ac1ebf4d79c7f8c396aab45911b730846 100644 --- a/lib/gitlab/markdown/filter/reference_gatherer_filter.rb +++ b/lib/banzai/filter/reference_gatherer_filter.rb @@ -1,8 +1,8 @@ -require 'gitlab/markdown' +require 'banzai' require 'html/pipeline/filter' -module Gitlab - module Markdown +module Banzai + module Filter # HTML filter that gathers all referenced records that the current user has # permission to view. # @@ -20,7 +20,7 @@ module Gitlab gather_references(node) end - load_lazy_references unless context[:load_lazy_references] == false + load_lazy_references unless ReferenceExtractor.lazy? doc end @@ -31,7 +31,7 @@ module Gitlab return unless node.has_attribute?('data-reference-filter') reference_type = node.attr('data-reference-filter') - reference_filter = Gitlab::Markdown.const_get(reference_type) + reference_filter = Banzai::Filter.const_get(reference_type) return if context[:reference_filter] && reference_filter != context[:reference_filter] @@ -47,11 +47,10 @@ module Gitlab end end - # Will load all references of one type using one query. def load_lazy_references refs = result[:references] refs.each do |type, values| - refs[type] = ReferenceFilter::LazyReference.load(values) + refs[type] = ReferenceExtractor.lazily(values) end end diff --git a/lib/gitlab/markdown/filter/relative_link_filter.rb b/lib/banzai/filter/relative_link_filter.rb similarity index 98% rename from lib/gitlab/markdown/filter/relative_link_filter.rb rename to lib/banzai/filter/relative_link_filter.rb index 81f60120fcd786dd1a675b557dc512fb9cb64817..5a081125f21dcd67e147f237de4d2ffe7e13ea52 100644 --- a/lib/gitlab/markdown/filter/relative_link_filter.rb +++ b/lib/banzai/filter/relative_link_filter.rb @@ -1,9 +1,9 @@ -require 'gitlab/markdown' +require 'banzai' require 'html/pipeline/filter' require 'uri' -module Gitlab - module Markdown +module Banzai + module Filter # HTML filter that "fixes" relative links to files in a repository. # # Context options: diff --git a/lib/gitlab/markdown/filter/sanitization_filter.rb b/lib/banzai/filter/sanitization_filter.rb similarity index 97% rename from lib/gitlab/markdown/filter/sanitization_filter.rb rename to lib/banzai/filter/sanitization_filter.rb index cf153f30622b03f3cd5d70f1cc65b799fdac41cd..d03e3ae4b3c9996d12823215bb31aa3d30bd5800 100644 --- a/lib/gitlab/markdown/filter/sanitization_filter.rb +++ b/lib/banzai/filter/sanitization_filter.rb @@ -1,9 +1,9 @@ -require 'gitlab/markdown' +require 'banzai' require 'html/pipeline/filter' require 'html/pipeline/sanitization_filter' -module Gitlab - module Markdown +module Banzai + module Filter # Sanitize HTML # # Extends HTML::Pipeline::SanitizationFilter with a custom whitelist. diff --git a/lib/gitlab/markdown/filter/snippet_reference_filter.rb b/lib/banzai/filter/snippet_reference_filter.rb similarity index 91% rename from lib/gitlab/markdown/filter/snippet_reference_filter.rb rename to lib/banzai/filter/snippet_reference_filter.rb index f7bd07c2a34f210d0c71bcab78daa02cce11e693..1ad5df96f85c8cb7ca222b91f60793084b48059a 100644 --- a/lib/gitlab/markdown/filter/snippet_reference_filter.rb +++ b/lib/banzai/filter/snippet_reference_filter.rb @@ -1,7 +1,7 @@ -require 'gitlab/markdown' +require 'banzai' -module Gitlab - module Markdown +module Banzai + module Filter # HTML filter that replaces snippet references with links. References to # snippets that do not exist are ignored. # diff --git a/lib/gitlab/markdown/filter/syntax_highlight_filter.rb b/lib/banzai/filter/syntax_highlight_filter.rb similarity index 94% rename from lib/gitlab/markdown/filter/syntax_highlight_filter.rb rename to lib/banzai/filter/syntax_highlight_filter.rb index 8597e02f0dec8c09d9903c084d0d44c660e8b555..c889cc1e97cd3ea62eaffb7715e20da2244ddd9d 100644 --- a/lib/gitlab/markdown/filter/syntax_highlight_filter.rb +++ b/lib/banzai/filter/syntax_highlight_filter.rb @@ -1,9 +1,9 @@ -require 'gitlab/markdown' +require 'banzai' require 'html/pipeline/filter' require 'rouge/plugins/redcarpet' -module Gitlab - module Markdown +module Banzai + module Filter # HTML Filter to highlight fenced code blocks # class SyntaxHighlightFilter < HTML::Pipeline::Filter diff --git a/lib/gitlab/markdown/filter/table_of_contents_filter.rb b/lib/banzai/filter/table_of_contents_filter.rb similarity index 96% rename from lib/gitlab/markdown/filter/table_of_contents_filter.rb rename to lib/banzai/filter/table_of_contents_filter.rb index bbb3bf7fc8b3e6ddb1c95cf62dda1ff76a298d9a..92d130074dcd4d93c8ac382c0e1366c9174562a0 100644 --- a/lib/gitlab/markdown/filter/table_of_contents_filter.rb +++ b/lib/banzai/filter/table_of_contents_filter.rb @@ -1,8 +1,8 @@ -require 'gitlab/markdown' +require 'banzai' require 'html/pipeline/filter' -module Gitlab - module Markdown +module Banzai + module Filter # HTML filter that adds an anchor child element to all Headers in a # document, so that they can be linked to. # diff --git a/lib/gitlab/markdown/filter/task_list_filter.rb b/lib/banzai/filter/task_list_filter.rb similarity index 91% rename from lib/gitlab/markdown/filter/task_list_filter.rb rename to lib/banzai/filter/task_list_filter.rb index 2f133ae850060fc0d72e18a3ce0c7a9ad0749f76..bdf7c2ebdfc6c2904372fd72390801a634a55c32 100644 --- a/lib/gitlab/markdown/filter/task_list_filter.rb +++ b/lib/banzai/filter/task_list_filter.rb @@ -1,8 +1,8 @@ -require 'gitlab/markdown' +require 'banzai' require 'task_list/filter' -module Gitlab - module Markdown +module Banzai + module Filter # Work around a bug in the default TaskList::Filter that adds a `task-list` # class to every list element, regardless of whether or not it contains a # task list. diff --git a/lib/gitlab/markdown/filter/upload_link_filter.rb b/lib/banzai/filter/upload_link_filter.rb similarity index 94% rename from lib/gitlab/markdown/filter/upload_link_filter.rb rename to lib/banzai/filter/upload_link_filter.rb index fbada73ab865c9a677863164f8a1b814839fdf13..1a1d0aad8ca6efb35ded2fb9fbb3d292b53833a8 100644 --- a/lib/gitlab/markdown/filter/upload_link_filter.rb +++ b/lib/banzai/filter/upload_link_filter.rb @@ -1,9 +1,9 @@ -require 'gitlab/markdown' +require 'banzai' require 'html/pipeline/filter' require 'uri' -module Gitlab - module Markdown +module Banzai + module Filter # HTML filter that "fixes" relative upload links to files. # Context options: # :project (required) - Current project diff --git a/lib/gitlab/markdown/filter/user_reference_filter.rb b/lib/banzai/filter/user_reference_filter.rb similarity index 98% rename from lib/gitlab/markdown/filter/user_reference_filter.rb rename to lib/banzai/filter/user_reference_filter.rb index 0a20d9c034729e660e51f1f211307f1b98bd2f76..67c24faf991243f4aa167fbde94ff17a9ccbc129 100644 --- a/lib/gitlab/markdown/filter/user_reference_filter.rb +++ b/lib/banzai/filter/user_reference_filter.rb @@ -1,7 +1,7 @@ -require 'gitlab/markdown' +require 'banzai' -module Gitlab - module Markdown +module Banzai + module Filter # HTML filter that replaces user or group references with links. # # A special `@all` reference is also supported. diff --git a/lib/banzai/lazy_reference.rb b/lib/banzai/lazy_reference.rb new file mode 100644 index 0000000000000000000000000000000000000000..073ec5d9801f0ba466662b82a81afdb0f68f6596 --- /dev/null +++ b/lib/banzai/lazy_reference.rb @@ -0,0 +1,27 @@ +require 'banzai' + +module Banzai + class LazyReference + def self.load(refs) + lazy_references, values = refs.partition { |ref| ref.is_a?(self) } + + lazy_values = lazy_references.group_by(&:klass).flat_map do |klass, refs| + ids = refs.flat_map(&:ids) + klass.where(id: ids) + end + + values + lazy_values + end + + attr_reader :klass, :ids + + def initialize(klass, ids) + @klass = klass + @ids = Array.wrap(ids).map(&:to_i) + end + + def load + self.klass.where(id: self.ids) + end + end +end diff --git a/lib/banzai/pipeline.rb b/lib/banzai/pipeline.rb new file mode 100644 index 0000000000000000000000000000000000000000..4e017809d9d3c85d578f1173182485986aee21c2 --- /dev/null +++ b/lib/banzai/pipeline.rb @@ -0,0 +1,10 @@ +require 'banzai' + +module Banzai + module Pipeline + def self.[](name) + name ||= :full + const_get("#{name.to_s.camelize}Pipeline") + end + end +end diff --git a/lib/banzai/pipeline/asciidoc_pipeline.rb b/lib/banzai/pipeline/asciidoc_pipeline.rb new file mode 100644 index 0000000000000000000000000000000000000000..5e76a817be512e619a63bff9c70adbe717306d7f --- /dev/null +++ b/lib/banzai/pipeline/asciidoc_pipeline.rb @@ -0,0 +1,13 @@ +require 'banzai' + +module Banzai + module Pipeline + class AsciidocPipeline < BasePipeline + def self.filters + [ + Filter::RelativeLinkFilter + ] + end + end + end +end diff --git a/lib/banzai/pipeline/atom_pipeline.rb b/lib/banzai/pipeline/atom_pipeline.rb new file mode 100644 index 0000000000000000000000000000000000000000..957f352aec5f2d149e89db0b09ee041b0b5da759 --- /dev/null +++ b/lib/banzai/pipeline/atom_pipeline.rb @@ -0,0 +1,14 @@ +require 'banzai' + +module Banzai + module Pipeline + class AtomPipeline < FullPipeline + def self.transform_context(context) + super(context).merge( + only_path: false, + xhtml: true + ) + end + end + end +end diff --git a/lib/banzai/pipeline/base_pipeline.rb b/lib/banzai/pipeline/base_pipeline.rb new file mode 100644 index 0000000000000000000000000000000000000000..cd30009e5c097e0cc5045750e44f9dc9eef59865 --- /dev/null +++ b/lib/banzai/pipeline/base_pipeline.rb @@ -0,0 +1,30 @@ +require 'banzai' +require 'html/pipeline' + +module Banzai + module Pipeline + class BasePipeline + def self.filters + [] + end + + def self.transform_context(context) + context + end + + def self.html_pipeline + @html_pipeline ||= HTML::Pipeline.new(filters) + end + + class << self + %i(call to_document to_html).each do |meth| + define_method(meth) do |text, context| + context = transform_context(context) + + html_pipeline.send(meth, text, context) + end + end + end + end + end +end diff --git a/lib/gitlab/markdown/combined_pipeline.rb b/lib/banzai/pipeline/combined_pipeline.rb similarity index 84% rename from lib/gitlab/markdown/combined_pipeline.rb rename to lib/banzai/pipeline/combined_pipeline.rb index 6b08a5e9f728cf182de467e812b3f558b5375000..f3bf1809d18dc431be986ffe795a2ebfc46679d0 100644 --- a/lib/gitlab/markdown/combined_pipeline.rb +++ b/lib/banzai/pipeline/combined_pipeline.rb @@ -1,10 +1,10 @@ -require 'gitlab/markdown' +require 'banzai' -module Gitlab - module Markdown +module Banzai + module Pipeline module CombinedPipeline def self.new(*pipelines) - Class.new(Pipeline) do + Class.new(BasePipeline) do const_set :PIPELINES, pipelines def self.pipelines diff --git a/lib/gitlab/markdown/pipeline/description_pipeline.rb b/lib/banzai/pipeline/description_pipeline.rb similarity index 68% rename from lib/gitlab/markdown/pipeline/description_pipeline.rb rename to lib/banzai/pipeline/description_pipeline.rb index 76f6948af8f3f9a8745080ab471faf1ff2070654..94c2cb165a5646d021e5b9b829e7e6b843954d2c 100644 --- a/lib/gitlab/markdown/pipeline/description_pipeline.rb +++ b/lib/banzai/pipeline/description_pipeline.rb @@ -1,10 +1,10 @@ -require 'gitlab/markdown' +require 'banzai' -module Gitlab - module Markdown +module Banzai + module Pipeline class DescriptionPipeline < FullPipeline def self.transform_context(context) - super(context).merge( + super(context).merge( # SanitizationFilter inline_sanitization: true ) diff --git a/lib/gitlab/markdown/pipeline/email_pipeline.rb b/lib/banzai/pipeline/email_pipeline.rb similarity index 62% rename from lib/gitlab/markdown/pipeline/email_pipeline.rb rename to lib/banzai/pipeline/email_pipeline.rb index b88cb790270cafb3a7b0df646e05aeb8d6ac4528..14356145a357791ebca63db494a4e8fdde183c46 100644 --- a/lib/gitlab/markdown/pipeline/email_pipeline.rb +++ b/lib/banzai/pipeline/email_pipeline.rb @@ -1,10 +1,10 @@ -require 'gitlab/markdown' +require 'banzai' -module Gitlab - module Markdown +module Banzai + module Pipeline class EmailPipeline < FullPipeline def self.transform_context(context) - super(context).merge( + super(context).merge( only_path: false ) end diff --git a/lib/gitlab/markdown/pipeline/full_pipeline.rb b/lib/banzai/pipeline/full_pipeline.rb similarity index 63% rename from lib/gitlab/markdown/pipeline/full_pipeline.rb rename to lib/banzai/pipeline/full_pipeline.rb index b3b7a3c27c016115c2b75383ea99894d368b3dfa..72395a5d50ef223860877c76706f73a912cbdef1 100644 --- a/lib/gitlab/markdown/pipeline/full_pipeline.rb +++ b/lib/banzai/pipeline/full_pipeline.rb @@ -1,7 +1,7 @@ -require 'gitlab/markdown' +require 'banzai' -module Gitlab - module Markdown +module Banzai + module Pipeline class FullPipeline < CombinedPipeline.new(PlainMarkdownPipeline, GfmPipeline) end diff --git a/lib/banzai/pipeline/gfm_pipeline.rb b/lib/banzai/pipeline/gfm_pipeline.rb new file mode 100644 index 0000000000000000000000000000000000000000..38750b55ec7115f4d91f24d2bc83933093d08370 --- /dev/null +++ b/lib/banzai/pipeline/gfm_pipeline.rb @@ -0,0 +1,41 @@ +require 'banzai' + +module Banzai + module Pipeline + class GfmPipeline < BasePipeline + def self.filters + @filters ||= [ + Filter::SyntaxHighlightFilter, + Filter::SanitizationFilter, + + Filter::UploadLinkFilter, + Filter::EmojiFilter, + Filter::TableOfContentsFilter, + Filter::AutolinkFilter, + Filter::ExternalLinkFilter, + + Filter::UserReferenceFilter, + Filter::IssueReferenceFilter, + Filter::ExternalIssueReferenceFilter, + Filter::MergeRequestReferenceFilter, + Filter::SnippetReferenceFilter, + Filter::CommitRangeReferenceFilter, + Filter::CommitReferenceFilter, + Filter::LabelReferenceFilter, + + Filter::TaskListFilter + ] + end + + def self.transform_context(context) + context.merge( + only_path: true, + + # EmojiFilter + asset_host: Gitlab::Application.config.asset_host, + asset_root: Gitlab.config.gitlab.base_url + ) + end + end + end +end diff --git a/lib/gitlab/markdown/pipeline/note_pipeline.rb b/lib/banzai/pipeline/note_pipeline.rb similarity index 67% rename from lib/gitlab/markdown/pipeline/note_pipeline.rb rename to lib/banzai/pipeline/note_pipeline.rb index a8bf5f42d8e18700abd0bf83a64238a0d5e4aaa6..893351438525c4ec7de8c894e428d134e92f9bcd 100644 --- a/lib/gitlab/markdown/pipeline/note_pipeline.rb +++ b/lib/banzai/pipeline/note_pipeline.rb @@ -1,10 +1,10 @@ -require 'gitlab/markdown' +require 'banzai' -module Gitlab - module Markdown +module Banzai + module Pipeline class NotePipeline < FullPipeline def self.transform_context(context) - super(context).merge( + super(context).merge( # TableOfContentsFilter no_header_anchors: true ) diff --git a/lib/banzai/pipeline/plain_markdown_pipeline.rb b/lib/banzai/pipeline/plain_markdown_pipeline.rb new file mode 100644 index 0000000000000000000000000000000000000000..998fd75daa2d57b1efbd9b8d6cfa78e3bc10f7bd --- /dev/null +++ b/lib/banzai/pipeline/plain_markdown_pipeline.rb @@ -0,0 +1,13 @@ +require 'banzai' + +module Banzai + module Pipeline + class PlainMarkdownPipeline < BasePipeline + def self.filters + [ + Filter::MarkdownFilter + ] + end + end + end +end diff --git a/lib/banzai/pipeline/post_process_pipeline.rb b/lib/banzai/pipeline/post_process_pipeline.rb new file mode 100644 index 0000000000000000000000000000000000000000..148f24b6ce1d0c29259f13b4bb6f0609e7200e8f --- /dev/null +++ b/lib/banzai/pipeline/post_process_pipeline.rb @@ -0,0 +1,20 @@ +require 'banzai' + +module Banzai + module Pipeline + class PostProcessPipeline < BasePipeline + def self.filters + [ + Filter::RelativeLinkFilter, + Filter::RedactorFilter + ] + end + + def self.transform_context(context) + context.merge( + post_process: true + ) + end + end + end +end diff --git a/lib/banzai/pipeline/reference_extraction_pipeline.rb b/lib/banzai/pipeline/reference_extraction_pipeline.rb new file mode 100644 index 0000000000000000000000000000000000000000..4f9bc9fcccc501fb5d3386358fe13934047c331c --- /dev/null +++ b/lib/banzai/pipeline/reference_extraction_pipeline.rb @@ -0,0 +1,13 @@ +require 'banzai' + +module Banzai + module Pipeline + class ReferenceExtractionPipeline < BasePipeline + def self.filters + [ + Filter::ReferenceGathererFilter + ] + end + end + end +end diff --git a/lib/banzai/pipeline/single_line_pipeline.rb b/lib/banzai/pipeline/single_line_pipeline.rb new file mode 100644 index 0000000000000000000000000000000000000000..6725c9039a9ff0ecca91610adc4302eb02a84c15 --- /dev/null +++ b/lib/banzai/pipeline/single_line_pipeline.rb @@ -0,0 +1,9 @@ +require 'banzai' + +module Banzai + module Pipeline + class SingleLinePipeline < GfmPipeline + + end + end +end diff --git a/lib/banzai/reference_extractor.rb b/lib/banzai/reference_extractor.rb new file mode 100644 index 0000000000000000000000000000000000000000..2c197d31898cb39b21f695de15c4d6daee91a6a0 --- /dev/null +++ b/lib/banzai/reference_extractor.rb @@ -0,0 +1,55 @@ +require 'banzai' + +module Banzai + # Extract possible GFM references from an arbitrary String for further processing. + class ReferenceExtractor + class << self + LAZY_KEY = :banzai_reference_extractor_lazy + + def lazy? + Thread.current[LAZY_KEY] + end + + def lazily(values = nil, &block) + return (values || block.call).uniq if lazy? + + begin + Thread.current[LAZY_KEY] = true + + values ||= block.call + + Banzai::LazyReference.load(values.uniq).uniq + ensure + Thread.current[LAZY_KEY] = false + end + end + end + + def initialize + @texts = [] + end + + def analyze(text, context = {}) + @texts << Renderer.render(text, context) + end + + def references(type, context = {}) + filter = Banzai::Filter["#{type}_reference"] + + context.merge!( + pipeline: :reference_extraction, + + # ReferenceGathererFilter + reference_filter: filter + ) + + self.class.lazily do + @texts.flat_map do |html| + text_context = context.dup + result = Renderer.render_result(html, text_context) + result[:references][type] + end.uniq + end + end + end +end diff --git a/lib/banzai/renderer.rb b/lib/banzai/renderer.rb new file mode 100644 index 0000000000000000000000000000000000000000..891c0fd7749aac0f984d41ecfe572054596dcea9 --- /dev/null +++ b/lib/banzai/renderer.rb @@ -0,0 +1,76 @@ +module Banzai + module Renderer + # Convert a Markdown String into an HTML-safe String of HTML + # + # Note that while the returned HTML will have been sanitized of dangerous + # HTML, it may post a risk of information leakage if it's not also passed + # through `post_process`. + # + # Also note that the returned String is always HTML, not XHTML. Views + # requiring XHTML, such as Atom feeds, need to call `post_process` on the + # result, providing the appropriate `pipeline` option. + # + # markdown - Markdown String + # context - Hash of context options passed to our HTML Pipeline + # + # Returns an HTML-safe String + def self.render(text, context = {}) + cache_key = context.delete(:cache_key) + cache_key = full_cache_key(cache_key, context[:pipeline]) + + if cache_key + Rails.cache.fetch(cache_key) do + cacheless_render(text, context) + end + else + cacheless_render(text, context) + end + end + + def self.render_result(text, context = {}) + Pipeline[context[:pipeline]].call(text, context) + end + + # Perform post-processing on an HTML String + # + # This method is used to perform state-dependent changes to a String of + # HTML, such as removing references that the current user doesn't have + # permission to make (`RedactorFilter`). + # + # html - String to process + # context - Hash of options to customize output + # :pipeline - Symbol pipeline type + # :project - Project + # :user - User object + # + # Returns an HTML-safe String + def self.post_process(html, context) + context = Pipeline[context[:pipeline]].transform_context(context) + + pipeline = Pipeline[:post_process] + if context[:xhtml] + pipeline.to_document(html, context).to_html(save_with: Nokogiri::XML::Node::SaveOptions::AS_XHTML) + else + pipeline.to_html(html, context) + end.html_safe + end + + private + + def self.cacheless_render(text, context = {}) + result = render_result(text, context) + + output = result[:output] + if output.respond_to?(:to_html) + output.to_html + else + output.to_s + end + end + + def self.full_cache_key(cache_key, pipeline_name) + return unless cache_key + ["banzai", *cache_key, pipeline_name || :full] + end + end +end diff --git a/lib/gitlab/asciidoc.rb b/lib/gitlab/asciidoc.rb index 330d3342dd17f42db2b9dde389f2b32342e9ca5f..b203b9d70e4a149277dfa30096391d60746a7f85 100644 --- a/lib/gitlab/asciidoc.rb +++ b/lib/gitlab/asciidoc.rb @@ -32,7 +32,7 @@ module Gitlab html = ::Asciidoctor.convert(input, asciidoc_opts) if context[:project] - html = Gitlab::Markdown.render(html, context.merge(pipeline: :asciidoc)) + html = Banzai.render(html, context.merge(pipeline: :asciidoc)) end html.html_safe diff --git a/lib/gitlab/markdown.rb b/lib/gitlab/markdown.rb deleted file mode 100644 index f4e2cefca51745875b745d3c46d069e7078ccf5c..0000000000000000000000000000000000000000 --- a/lib/gitlab/markdown.rb +++ /dev/null @@ -1,115 +0,0 @@ -require 'html/pipeline' - -module Gitlab - # Custom parser for GitLab-flavored Markdown - # - # See the files in `lib/gitlab/markdown/` for specific processing information. - module Markdown - # Convert a Markdown String into an HTML-safe String of HTML - # - # Note that while the returned HTML will have been sanitized of dangerous - # HTML, it may post a risk of information leakage if it's not also passed - # through `post_process`. - # - # Also note that the returned String is always HTML, not XHTML. Views - # requiring XHTML, such as Atom feeds, need to call `post_process` on the - # result, providing the appropriate `pipeline` option. - # - # markdown - Markdown String - # context - Hash of context options passed to our HTML Pipeline - # - # Returns an HTML-safe String - def self.render(text, context = {}) - cache_key = context.delete(:cache_key) - cache_key = full_cache_key(cache_key, context[:pipeline]) - - if cache_key - Rails.cache.fetch(cache_key) do - cacheless_render(text, context) - end - else - cacheless_render(text, context) - end - end - - def self.render_result(text, context = {}) - Pipeline[context[:pipeline]].call(text, context) - end - - # Perform post-processing on an HTML String - # - # This method is used to perform state-dependent changes to a String of - # HTML, such as removing references that the current user doesn't have - # permission to make (`RedactorFilter`). - # - # html - String to process - # context - Hash of options to customize output - # :pipeline - Symbol pipeline type - # :project - Project - # :user - User object - # - # Returns an HTML-safe String - def self.post_process(html, context) - context = Pipeline[context[:pipeline]].transform_context(context) - - pipeline = Pipeline[:post_process] - if context[:xhtml] - pipeline.to_document(html, context).to_html(save_with: Nokogiri::XML::Node::SaveOptions::AS_XHTML) - else - pipeline.to_html(html, context) - end.html_safe - end - - private - - def self.cacheless_render(text, context = {}) - result = render_result(text, context) - - output = result[:output] - if output.respond_to?(:to_html) - output.to_html - else - output.to_s - end - end - - def self.full_cache_key(cache_key, pipeline_name) - return unless cache_key - ["markdown", *cache_key, pipeline_name || :full] - end - - # Provide autoload paths for filters to prevent a circular dependency error - autoload :AutolinkFilter, 'gitlab/markdown/filter/autolink_filter' - autoload :CommitRangeReferenceFilter, 'gitlab/markdown/filter/commit_range_reference_filter' - autoload :CommitReferenceFilter, 'gitlab/markdown/filter/commit_reference_filter' - autoload :EmojiFilter, 'gitlab/markdown/filter/emoji_filter' - autoload :ExternalIssueReferenceFilter, 'gitlab/markdown/filter/external_issue_reference_filter' - autoload :ExternalLinkFilter, 'gitlab/markdown/filter/external_link_filter' - autoload :IssueReferenceFilter, 'gitlab/markdown/filter/issue_reference_filter' - autoload :LabelReferenceFilter, 'gitlab/markdown/filter/label_reference_filter' - autoload :MarkdownFilter, 'gitlab/markdown/filter/markdown_filter' - autoload :MergeRequestReferenceFilter, 'gitlab/markdown/filter/merge_request_reference_filter' - autoload :RedactorFilter, 'gitlab/markdown/filter/redactor_filter' - autoload :ReferenceGathererFilter, 'gitlab/markdown/filter/reference_gatherer_filter' - autoload :RelativeLinkFilter, 'gitlab/markdown/filter/relative_link_filter' - autoload :SanitizationFilter, 'gitlab/markdown/filter/sanitization_filter' - autoload :SnippetReferenceFilter, 'gitlab/markdown/filter/snippet_reference_filter' - autoload :SyntaxHighlightFilter, 'gitlab/markdown/filter/syntax_highlight_filter' - autoload :TableOfContentsFilter, 'gitlab/markdown/filter/table_of_contents_filter' - autoload :TaskListFilter, 'gitlab/markdown/filter/task_list_filter' - autoload :UserReferenceFilter, 'gitlab/markdown/filter/user_reference_filter' - autoload :UploadLinkFilter, 'gitlab/markdown/filter/upload_link_filter' - - autoload :AsciidocPipeline, 'gitlab/markdown/pipeline/asciidoc_pipeline' - autoload :AtomPipeline, 'gitlab/markdown/pipeline/atom_pipeline' - autoload :DescriptionPipeline, 'gitlab/markdown/pipeline/description_pipeline' - autoload :EmailPipeline, 'gitlab/markdown/pipeline/email_pipeline' - autoload :FullPipeline, 'gitlab/markdown/pipeline/full_pipeline' - autoload :GfmPipeline, 'gitlab/markdown/pipeline/gfm_pipeline' - autoload :NotePipeline, 'gitlab/markdown/pipeline/note_pipeline' - autoload :PlainMarkdownPipeline, 'gitlab/markdown/pipeline/plain_markdown_pipeline' - autoload :PostProcessPipeline, 'gitlab/markdown/pipeline/post_process_pipeline' - autoload :ReferenceExtractionPipeline, 'gitlab/markdown/pipeline/reference_extraction_pipeline' - autoload :SingleLinePipeline, 'gitlab/markdown/pipeline/single_line_pipeline' - end -end diff --git a/lib/gitlab/markdown/cross_project_reference.rb b/lib/gitlab/markdown/cross_project_reference.rb deleted file mode 100644 index 6ab04a584b0c8e8166a9e5cc908b5ac7e6140897..0000000000000000000000000000000000000000 --- a/lib/gitlab/markdown/cross_project_reference.rb +++ /dev/null @@ -1,24 +0,0 @@ -require 'gitlab/markdown' - -module Gitlab - module Markdown - # Common methods for ReferenceFilters that support an optional cross-project - # reference. - module CrossProjectReference - # Given a cross-project reference string, get the Project record - # - # Defaults to value of `context[:project]` if: - # * No reference is given OR - # * Reference given doesn't exist - # - # ref - String reference. - # - # Returns a Project, or nil if the reference can't be found - def project_from_ref(ref) - return context[:project] unless ref - - Project.find_with_namespace(ref) - end - end - end -end diff --git a/lib/gitlab/markdown/pipeline.rb b/lib/gitlab/markdown/pipeline.rb index d683756f95ad7b2425d26d39d603f6b4ec479af3..8f3f43c0e914d72151d91189783b6a49810834cb 100644 --- a/lib/gitlab/markdown/pipeline.rb +++ b/lib/gitlab/markdown/pipeline.rb @@ -1,11 +1,11 @@ -require 'gitlab/markdown' +require 'banzai' module Gitlab module Markdown class Pipeline def self.[](name) name ||= :full - Markdown.const_get("#{name.to_s.camelize}Pipeline") + const_get("#{name.to_s.camelize}Pipeline") end def self.filters diff --git a/lib/gitlab/markdown/pipeline/asciidoc_pipeline.rb b/lib/gitlab/markdown/pipeline/asciidoc_pipeline.rb deleted file mode 100644 index 6829b4acb9596ceab1b078a09e05b8f397cc1225..0000000000000000000000000000000000000000 --- a/lib/gitlab/markdown/pipeline/asciidoc_pipeline.rb +++ /dev/null @@ -1,13 +0,0 @@ -require 'gitlab/markdown' - -module Gitlab - module Markdown - class AsciidocPipeline < Pipeline - def self.filters - [ - Gitlab::Markdown::RelativeLinkFilter - ] - end - end - end -end diff --git a/lib/gitlab/markdown/pipeline/atom_pipeline.rb b/lib/gitlab/markdown/pipeline/atom_pipeline.rb deleted file mode 100644 index e151f8f5e5aec8e4e9afe4aa470a2f9eb97b7603..0000000000000000000000000000000000000000 --- a/lib/gitlab/markdown/pipeline/atom_pipeline.rb +++ /dev/null @@ -1,14 +0,0 @@ -require 'gitlab/markdown' - -module Gitlab - module Markdown - class AtomPipeline < FullPipeline - def self.transform_context(context) - super(context).merge( - only_path: false, - xhtml: true - ) - end - end - end -end diff --git a/lib/gitlab/markdown/pipeline/gfm_pipeline.rb b/lib/gitlab/markdown/pipeline/gfm_pipeline.rb deleted file mode 100644 index ca90bd75d7748e9db6457192e73dd366f6131501..0000000000000000000000000000000000000000 --- a/lib/gitlab/markdown/pipeline/gfm_pipeline.rb +++ /dev/null @@ -1,41 +0,0 @@ -require 'gitlab/markdown' - -module Gitlab - module Markdown - class GfmPipeline < Pipeline - def self.filters - @filters ||= [ - Gitlab::Markdown::SyntaxHighlightFilter, - Gitlab::Markdown::SanitizationFilter, - - Gitlab::Markdown::UploadLinkFilter, - Gitlab::Markdown::EmojiFilter, - Gitlab::Markdown::TableOfContentsFilter, - Gitlab::Markdown::AutolinkFilter, - Gitlab::Markdown::ExternalLinkFilter, - - Gitlab::Markdown::UserReferenceFilter, - Gitlab::Markdown::IssueReferenceFilter, - Gitlab::Markdown::ExternalIssueReferenceFilter, - Gitlab::Markdown::MergeRequestReferenceFilter, - Gitlab::Markdown::SnippetReferenceFilter, - Gitlab::Markdown::CommitRangeReferenceFilter, - Gitlab::Markdown::CommitReferenceFilter, - Gitlab::Markdown::LabelReferenceFilter, - - Gitlab::Markdown::TaskListFilter - ] - end - - def self.transform_context(context) - context.merge( - only_path: true, - - # EmojiFilter - asset_host: Gitlab::Application.config.asset_host, - asset_root: Gitlab.config.gitlab.base_url - ) - end - end - end -end diff --git a/lib/gitlab/markdown/pipeline/plain_markdown_pipeline.rb b/lib/gitlab/markdown/pipeline/plain_markdown_pipeline.rb deleted file mode 100644 index 0abb93f8a033de44f2516c914cdeadd8cc6fae43..0000000000000000000000000000000000000000 --- a/lib/gitlab/markdown/pipeline/plain_markdown_pipeline.rb +++ /dev/null @@ -1,13 +0,0 @@ -require 'gitlab/markdown' - -module Gitlab - module Markdown - class PlainMarkdownPipeline < Pipeline - def self.filters - [ - Gitlab::Markdown::MarkdownFilter - ] - end - end - end -end diff --git a/lib/gitlab/markdown/pipeline/post_process_pipeline.rb b/lib/gitlab/markdown/pipeline/post_process_pipeline.rb deleted file mode 100644 index 60cc32f490e4a66696b32201e6114313ddb52b4f..0000000000000000000000000000000000000000 --- a/lib/gitlab/markdown/pipeline/post_process_pipeline.rb +++ /dev/null @@ -1,20 +0,0 @@ -require 'gitlab/markdown' - -module Gitlab - module Markdown - class PostProcessPipeline < Pipeline - def self.filters - [ - Gitlab::Markdown::RelativeLinkFilter, - Gitlab::Markdown::RedactorFilter - ] - end - - def self.transform_context(context) - context.merge( - post_process: true - ) - end - end - end -end diff --git a/lib/gitlab/markdown/pipeline/reference_extraction_pipeline.rb b/lib/gitlab/markdown/pipeline/reference_extraction_pipeline.rb deleted file mode 100644 index a89ab462bac3f83c0f7de1b89a4f89b62729fd80..0000000000000000000000000000000000000000 --- a/lib/gitlab/markdown/pipeline/reference_extraction_pipeline.rb +++ /dev/null @@ -1,13 +0,0 @@ -require 'gitlab/markdown' - -module Gitlab - module Markdown - class ReferenceExtractionPipeline < Pipeline - def self.filters - [ - Gitlab::Markdown::ReferenceGathererFilter - ] - end - end - end -end diff --git a/lib/gitlab/markdown/pipeline/single_line_pipeline.rb b/lib/gitlab/markdown/pipeline/single_line_pipeline.rb deleted file mode 100644 index 2f24927b8798f68a87ba97b7adff3bc06ac72438..0000000000000000000000000000000000000000 --- a/lib/gitlab/markdown/pipeline/single_line_pipeline.rb +++ /dev/null @@ -1,9 +0,0 @@ -require 'gitlab/markdown' - -module Gitlab - module Markdown - class SingleLinePipeline < GfmPipeline - - end - end -end diff --git a/lib/gitlab/reference_extractor.rb b/lib/gitlab/reference_extractor.rb index e83167fa7d79f13010a0b9404ef612c9b5b975fa..42f7c26f3c4a10a8d0b0834c81daa2beab2f2bd5 100644 --- a/lib/gitlab/reference_extractor.rb +++ b/lib/gitlab/reference_extractor.rb @@ -1,62 +1,27 @@ -require 'gitlab/markdown' +require 'banzai' module Gitlab # Extract possible GFM references from an arbitrary String for further processing. - class ReferenceExtractor - attr_accessor :project, :current_user, :load_lazy_references + class ReferenceExtractor < Banzai::ReferenceExtractor + attr_accessor :project, :current_user - def initialize(project, current_user = nil, load_lazy_references: true) + def initialize(project, current_user = nil) @project = project @current_user = current_user - @load_lazy_references = load_lazy_references - @texts = [] @references = {} + + super() end - def analyze(text, options = {}) - @texts << Gitlab::Markdown.render(text, options.merge(project: project)) + def analyze(text, context = {}) + super(text, context.merge(project: project)) end %i(user label issue merge_request snippet commit commit_range).each do |type| define_method("#{type}s") do - @references[type] ||= pipeline_result(type) + @references[type] ||= references(type, project: project, current_user: current_user) end end - - private - - # Instantiate and call HTML::Pipeline with a single reference filter type, - # returning the result - # - # filter_type - Symbol reference type (e.g., :commit, :issue, etc.) - # - # Returns the results Array for the requested filter type - def pipeline_result(filter_type) - filter = Gitlab::Markdown::ReferenceFilter[filter_type] - - context = { - pipeline: :reference_extraction, - - project: project, - current_user: current_user, - - # ReferenceGathererFilter - load_lazy_references: false, - reference_filter: filter - } - - values = @texts.flat_map do |html| - text_context = context.dup - result = Gitlab::Markdown.render_result(html, text_context) - result[:references][filter_type] - end.uniq - - if @load_lazy_references - values = Gitlab::Markdown::ReferenceFilter::LazyReference.load(values).uniq - end - - values - end end end diff --git a/lib/tasks/gitlab/check.rake b/lib/tasks/gitlab/check.rake index b5af3d88b4cff203a435c147f691fb4fb6338e8c..0469c5a61c38b980c5ef50367916abcc1e8f6049 100644 --- a/lib/tasks/gitlab/check.rake +++ b/lib/tasks/gitlab/check.rake @@ -822,10 +822,27 @@ namespace :gitlab do namespace_dirs.each do |namespace_dir| repo_dirs = Dir.glob(File.join(namespace_dir, '*')) - repo_dirs.each do |dir| - puts "\nChecking repo at #{dir}" - system(*%W(#{Gitlab.config.git.bin_path} fsck), chdir: dir) - end + repo_dirs.each { |repo_dir| check_repo_integrity(repo_dir) } + end + end + end + + namespace :user do + desc "GitLab | Check the integrity of a specific user's repositories" + task :check_repos, [:username] => :environment do |t, args| + username = args[:username] || prompt("Check repository integrity for which username? ".blue) + user = User.find_by(username: username) + if user + repo_dirs = user.authorized_projects.map do |p| + File.join( + Gitlab.config.gitlab_shell.repos_path, + "#{p.path_with_namespace}.git" + ) + end + + repo_dirs.each { |repo_dir| check_repo_integrity(repo_dir) } + else + puts "\nUser '#{username}' not found".red end end end @@ -952,4 +969,35 @@ namespace :gitlab do false end end + + def check_repo_integrity(repo_dir) + puts "\nChecking repo at #{repo_dir.yellow}" + + git_fsck(repo_dir) + check_config_lock(repo_dir) + check_ref_locks(repo_dir) + end + + def git_fsck(repo_dir) + puts "Running `git fsck`".yellow + system(*%W(#{Gitlab.config.git.bin_path} fsck), chdir: repo_dir) + end + + def check_config_lock(repo_dir) + config_exists = File.exist?(File.join(repo_dir,'config.lock')) + config_output = config_exists ? 'yes'.red : 'no'.green + puts "'config.lock' file exists?".yellow + " ... #{config_output}" + end + + def check_ref_locks(repo_dir) + lock_files = Dir.glob(File.join(repo_dir,'refs/heads/*.lock')) + if lock_files.present? + puts "Ref lock files exist:".red + lock_files.each do |lock_file| + puts " #{lock_file}" + end + else + puts "No ref lock files exist".green + end + end end diff --git a/spec/benchmarks/lib/gitlab/markdown/reference_filter_spec.rb b/spec/benchmarks/lib/gitlab/markdown/reference_filter_spec.rb index 34cd9f7e4eb398bd64d8d65226d15bc7488767c4..3855763b200b8ffafd01adc0f7d324f117c3b8a9 100644 --- a/spec/benchmarks/lib/gitlab/markdown/reference_filter_spec.rb +++ b/spec/benchmarks/lib/gitlab/markdown/reference_filter_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -describe Gitlab::Markdown::ReferenceFilter, benchmark: true do +describe Banzai::Filter::ReferenceFilter, benchmark: true do let(:input) do html = <<-EOF <p>Hello @alice and @bob, how are you doing today?</p> diff --git a/spec/features/issues/note_polling_spec.rb b/spec/features/issues/note_polling_spec.rb new file mode 100644 index 0000000000000000000000000000000000000000..e4efdbe2421d0dfc5838dcba1bac30cb705c4e2b --- /dev/null +++ b/spec/features/issues/note_polling_spec.rb @@ -0,0 +1,16 @@ +require 'spec_helper' + +feature 'Issue notes polling' do + let!(:project) { create(:project, :public) } + let!(:issue) { create(:issue, project: project) } + + background do + visit namespace_project_issue_path(project.namespace, project, issue) + end + + scenario 'Another user adds a comment to an issue', js: true do + note = create(:note_on_issue, noteable: issue, note: 'Looks good!') + page.execute_script('notes.refresh();') + expect(page).to have_selector("#note_#{note.id}", text: 'Looks good!') + end +end diff --git a/spec/lib/gitlab/markdown/cross_project_reference_spec.rb b/spec/lib/banzai/cross_project_reference_spec.rb similarity index 93% rename from spec/lib/gitlab/markdown/cross_project_reference_spec.rb rename to spec/lib/banzai/cross_project_reference_spec.rb index f594fe4ccf638552211a05451652e01f0d1aa7c9..81b9a513ce37f12ae72a6419bd6eb2bef81502b0 100644 --- a/spec/lib/gitlab/markdown/cross_project_reference_spec.rb +++ b/spec/lib/banzai/cross_project_reference_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -describe Gitlab::Markdown::CrossProjectReference, lib: true do +describe Banzai::CrossProjectReference, lib: true do include described_class describe '#project_from_ref' do diff --git a/spec/lib/gitlab/markdown/filter/autolink_filter_spec.rb b/spec/lib/banzai/filter/autolink_filter_spec.rb similarity index 98% rename from spec/lib/gitlab/markdown/filter/autolink_filter_spec.rb rename to spec/lib/banzai/filter/autolink_filter_spec.rb index a0844aee55915b4332e8009e34351ba4c32e9974..84c2ddf444e6f071944825c7f7be554b3383f6f7 100644 --- a/spec/lib/gitlab/markdown/filter/autolink_filter_spec.rb +++ b/spec/lib/banzai/filter/autolink_filter_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -describe Gitlab::Markdown::AutolinkFilter, lib: true do +describe Banzai::Filter::AutolinkFilter, lib: true do include FilterSpecHelper let(:link) { 'http://about.gitlab.com/' } diff --git a/spec/lib/gitlab/markdown/filter/commit_range_reference_filter_spec.rb b/spec/lib/banzai/filter/commit_range_reference_filter_spec.rb similarity index 98% rename from spec/lib/gitlab/markdown/filter/commit_range_reference_filter_spec.rb rename to spec/lib/banzai/filter/commit_range_reference_filter_spec.rb index 570c976762859fe8051dea363cb889ae03e4765f..c2a8ad36c3057fd4acd06cb329f6ead560b288bd 100644 --- a/spec/lib/gitlab/markdown/filter/commit_range_reference_filter_spec.rb +++ b/spec/lib/banzai/filter/commit_range_reference_filter_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -describe Gitlab::Markdown::CommitRangeReferenceFilter, lib: true do +describe Banzai::Filter::CommitRangeReferenceFilter, lib: true do include FilterSpecHelper let(:project) { create(:project, :public) } diff --git a/spec/lib/gitlab/markdown/filter/commit_reference_filter_spec.rb b/spec/lib/banzai/filter/commit_reference_filter_spec.rb similarity index 98% rename from spec/lib/gitlab/markdown/filter/commit_reference_filter_spec.rb rename to spec/lib/banzai/filter/commit_reference_filter_spec.rb index 76e7957bbb9e6c0cdc01148bb4d65c6a4508a4a9..473534ba68a66d26a5e0afd5e22ad8ad169f3271 100644 --- a/spec/lib/gitlab/markdown/filter/commit_reference_filter_spec.rb +++ b/spec/lib/banzai/filter/commit_reference_filter_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -describe Gitlab::Markdown::CommitReferenceFilter, lib: true do +describe Banzai::Filter::CommitReferenceFilter, lib: true do include FilterSpecHelper let(:project) { create(:project, :public) } diff --git a/spec/lib/gitlab/markdown/filter/emoji_filter_spec.rb b/spec/lib/banzai/filter/emoji_filter_spec.rb similarity index 98% rename from spec/lib/gitlab/markdown/filter/emoji_filter_spec.rb rename to spec/lib/banzai/filter/emoji_filter_spec.rb index ea9b81862cfb04fbb178399f8d853a1de32ca834..cf3140581584d45b8f8c34acecb0ff69dc9af141 100644 --- a/spec/lib/gitlab/markdown/filter/emoji_filter_spec.rb +++ b/spec/lib/banzai/filter/emoji_filter_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -describe Gitlab::Markdown::EmojiFilter, lib: true do +describe Banzai::Filter::EmojiFilter, lib: true do include FilterSpecHelper before do diff --git a/spec/lib/gitlab/markdown/filter/external_issue_reference_filter_spec.rb b/spec/lib/banzai/filter/external_issue_reference_filter_spec.rb similarity index 96% rename from spec/lib/gitlab/markdown/filter/external_issue_reference_filter_spec.rb rename to spec/lib/banzai/filter/external_issue_reference_filter_spec.rb index d84201026489bf819e6c122c81fd5d596cba02f2..953466679e4beb276f65b5a1a6adb06f01d91b6f 100644 --- a/spec/lib/gitlab/markdown/filter/external_issue_reference_filter_spec.rb +++ b/spec/lib/banzai/filter/external_issue_reference_filter_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -describe Gitlab::Markdown::ExternalIssueReferenceFilter, lib: true do +describe Banzai::Filter::ExternalIssueReferenceFilter, lib: true do include FilterSpecHelper def helper diff --git a/spec/lib/gitlab/markdown/filter/external_link_filter_spec.rb b/spec/lib/banzai/filter/external_link_filter_spec.rb similarity index 92% rename from spec/lib/gitlab/markdown/filter/external_link_filter_spec.rb rename to spec/lib/banzai/filter/external_link_filter_spec.rb index e559f5741cc43a16c16cba6a9789d9dd96db3063..e3a8e15330e228f448986f6c0615fff6a4dcea72 100644 --- a/spec/lib/gitlab/markdown/filter/external_link_filter_spec.rb +++ b/spec/lib/banzai/filter/external_link_filter_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -describe Gitlab::Markdown::ExternalLinkFilter, lib: true do +describe Banzai::Filter::ExternalLinkFilter, lib: true do include FilterSpecHelper it 'ignores elements without an href attribute' do diff --git a/spec/lib/gitlab/markdown/filter/issue_reference_filter_spec.rb b/spec/lib/banzai/filter/issue_reference_filter_spec.rb similarity index 99% rename from spec/lib/gitlab/markdown/filter/issue_reference_filter_spec.rb rename to spec/lib/banzai/filter/issue_reference_filter_spec.rb index 1aa5d44568e321228f1fd71f318d80746b824c52..5a0d3d577a83294ef014a04da2bf1f799fb660ac 100644 --- a/spec/lib/gitlab/markdown/filter/issue_reference_filter_spec.rb +++ b/spec/lib/banzai/filter/issue_reference_filter_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -describe Gitlab::Markdown::IssueReferenceFilter, lib: true do +describe Banzai::Filter::IssueReferenceFilter, lib: true do include FilterSpecHelper def helper diff --git a/spec/lib/gitlab/markdown/filter/label_reference_filter_spec.rb b/spec/lib/banzai/filter/label_reference_filter_spec.rb similarity index 98% rename from spec/lib/gitlab/markdown/filter/label_reference_filter_spec.rb rename to spec/lib/banzai/filter/label_reference_filter_spec.rb index 4fcbb329fe475f491a2a44b1e3f54f2473287bc0..b46ccc4760509f809da2a597e474c4ecfff72537 100644 --- a/spec/lib/gitlab/markdown/filter/label_reference_filter_spec.rb +++ b/spec/lib/banzai/filter/label_reference_filter_spec.rb @@ -1,7 +1,7 @@ require 'spec_helper' require 'html/pipeline' -describe Gitlab::Markdown::LabelReferenceFilter, lib: true do +describe Banzai::Filter::LabelReferenceFilter, lib: true do include FilterSpecHelper let(:project) { create(:empty_project, :public) } diff --git a/spec/lib/gitlab/markdown/filter/merge_request_reference_filter_spec.rb b/spec/lib/banzai/filter/merge_request_reference_filter_spec.rb similarity index 98% rename from spec/lib/gitlab/markdown/filter/merge_request_reference_filter_spec.rb rename to spec/lib/banzai/filter/merge_request_reference_filter_spec.rb index 589550e15c4514c3df5fadd671e9d5fdc48b37c0..352710df3071fcc7949ba5ca3452a32eec018786 100644 --- a/spec/lib/gitlab/markdown/filter/merge_request_reference_filter_spec.rb +++ b/spec/lib/banzai/filter/merge_request_reference_filter_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -describe Gitlab::Markdown::MergeRequestReferenceFilter, lib: true do +describe Banzai::Filter::MergeRequestReferenceFilter, lib: true do include FilterSpecHelper let(:project) { create(:project, :public) } diff --git a/spec/lib/gitlab/markdown/filter/redactor_filter_spec.rb b/spec/lib/banzai/filter/redactor_filter_spec.rb similarity index 97% rename from spec/lib/gitlab/markdown/filter/redactor_filter_spec.rb rename to spec/lib/banzai/filter/redactor_filter_spec.rb index 9e6ee9f0d61884d84f8f7d5831cfbc05e8217485..e9bb388e361b44743f791ad087411799049df26b 100644 --- a/spec/lib/gitlab/markdown/filter/redactor_filter_spec.rb +++ b/spec/lib/banzai/filter/redactor_filter_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -describe Gitlab::Markdown::RedactorFilter, lib: true do +describe Banzai::Filter::RedactorFilter, lib: true do include ActionView::Helpers::UrlHelper include FilterSpecHelper diff --git a/spec/lib/gitlab/markdown/filter/reference_gatherer_filter_spec.rb b/spec/lib/banzai/filter/reference_gatherer_filter_spec.rb similarity index 97% rename from spec/lib/gitlab/markdown/filter/reference_gatherer_filter_spec.rb rename to spec/lib/banzai/filter/reference_gatherer_filter_spec.rb index abfb5ad5e49fb1d17644ab2cec91f5485b8b773a..c8b1dfdf9448d5e4a5df45968e7db0d8c0e0b2d5 100644 --- a/spec/lib/gitlab/markdown/filter/reference_gatherer_filter_spec.rb +++ b/spec/lib/banzai/filter/reference_gatherer_filter_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -describe Gitlab::Markdown::ReferenceGathererFilter, lib: true do +describe Banzai::Filter::ReferenceGathererFilter, lib: true do include ActionView::Helpers::UrlHelper include FilterSpecHelper diff --git a/spec/lib/gitlab/markdown/filter/relative_link_filter_spec.rb b/spec/lib/banzai/filter/relative_link_filter_spec.rb similarity index 98% rename from spec/lib/gitlab/markdown/filter/relative_link_filter_spec.rb rename to spec/lib/banzai/filter/relative_link_filter_spec.rb index e0f53e2a533e335690817298fa8bb0d727d01c8a..0b3e5ecbc9fc3c929682e3f79a533cffdf2e0ac8 100644 --- a/spec/lib/gitlab/markdown/filter/relative_link_filter_spec.rb +++ b/spec/lib/banzai/filter/relative_link_filter_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Gitlab::Markdown::RelativeLinkFilter, lib: true do +describe Banzai::Filter::RelativeLinkFilter, lib: true do def filter(doc, contexts = {}) contexts.reverse_merge!({ commit: project.commit, diff --git a/spec/lib/gitlab/markdown/filter/sanitization_filter_spec.rb b/spec/lib/banzai/filter/sanitization_filter_spec.rb similarity index 99% rename from spec/lib/gitlab/markdown/filter/sanitization_filter_spec.rb rename to spec/lib/banzai/filter/sanitization_filter_spec.rb index a5e5ee0e08a7b0c1541c92c06b3731591c623a71..760d60a41908cedc8d72a04bef89e944034f0414 100644 --- a/spec/lib/gitlab/markdown/filter/sanitization_filter_spec.rb +++ b/spec/lib/banzai/filter/sanitization_filter_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -describe Gitlab::Markdown::SanitizationFilter, lib: true do +describe Banzai::Filter::SanitizationFilter, lib: true do include FilterSpecHelper describe 'default whitelist' do diff --git a/spec/lib/gitlab/markdown/filter/snippet_reference_filter_spec.rb b/spec/lib/banzai/filter/snippet_reference_filter_spec.rb similarity index 98% rename from spec/lib/gitlab/markdown/filter/snippet_reference_filter_spec.rb rename to spec/lib/banzai/filter/snippet_reference_filter_spec.rb index 51526b58597909e5601a269f7447e8ff83e12b75..26466fbb180138b8ce28755faf51d35bc8cb0ecf 100644 --- a/spec/lib/gitlab/markdown/filter/snippet_reference_filter_spec.rb +++ b/spec/lib/banzai/filter/snippet_reference_filter_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -describe Gitlab::Markdown::SnippetReferenceFilter, lib: true do +describe Banzai::Filter::SnippetReferenceFilter, lib: true do include FilterSpecHelper let(:project) { create(:empty_project, :public) } diff --git a/spec/lib/gitlab/markdown/filter/syntax_highlight_filter_spec.rb b/spec/lib/banzai/filter/syntax_highlight_filter_spec.rb similarity index 89% rename from spec/lib/gitlab/markdown/filter/syntax_highlight_filter_spec.rb rename to spec/lib/banzai/filter/syntax_highlight_filter_spec.rb index 8b76048f3e3a28b5c4dd116bbdbef5c1e3d51a65..407617f3307289a8c0de9c8caeeb1fcc669db0f4 100644 --- a/spec/lib/gitlab/markdown/filter/syntax_highlight_filter_spec.rb +++ b/spec/lib/banzai/filter/syntax_highlight_filter_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -describe Gitlab::Markdown::SyntaxHighlightFilter, lib: true do +describe Banzai::Filter::SyntaxHighlightFilter, lib: true do include FilterSpecHelper it 'highlights valid code blocks' do diff --git a/spec/lib/gitlab/markdown/filter/table_of_contents_filter_spec.rb b/spec/lib/banzai/filter/table_of_contents_filter_spec.rb similarity index 97% rename from spec/lib/gitlab/markdown/filter/table_of_contents_filter_spec.rb rename to spec/lib/banzai/filter/table_of_contents_filter_spec.rb index c8c79c41847314102a36190b2d36d5a5029b6d4d..6a5d003e87f048190f15202478b7bcb2ec9f7161 100644 --- a/spec/lib/gitlab/markdown/filter/table_of_contents_filter_spec.rb +++ b/spec/lib/banzai/filter/table_of_contents_filter_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Gitlab::Markdown::TableOfContentsFilter, lib: true do +describe Banzai::Filter::TableOfContentsFilter, lib: true do include FilterSpecHelper def header(level, text) diff --git a/spec/lib/gitlab/markdown/filter/task_list_filter_spec.rb b/spec/lib/banzai/filter/task_list_filter_spec.rb similarity index 78% rename from spec/lib/gitlab/markdown/filter/task_list_filter_spec.rb rename to spec/lib/banzai/filter/task_list_filter_spec.rb index 1b1714ef8821dd5998489ee8b6a862e7fc00d8c3..f2e3a44478dc5ed0a88905e3f2b6c51c2b645793 100644 --- a/spec/lib/gitlab/markdown/filter/task_list_filter_spec.rb +++ b/spec/lib/banzai/filter/task_list_filter_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -describe Gitlab::Markdown::TaskListFilter, lib: true do +describe Banzai::Filter::TaskListFilter, lib: true do include FilterSpecHelper it 'does not apply `task-list` class to non-task lists' do diff --git a/spec/lib/gitlab/markdown/filter/upload_link_filter_spec.rb b/spec/lib/banzai/filter/upload_link_filter_spec.rb similarity index 97% rename from spec/lib/gitlab/markdown/filter/upload_link_filter_spec.rb rename to spec/lib/banzai/filter/upload_link_filter_spec.rb index 38a007b5beeaeae18aa4a91fa345c7131815e033..3b073a90a95739387d6a4b99583a87556e2c5a24 100644 --- a/spec/lib/gitlab/markdown/filter/upload_link_filter_spec.rb +++ b/spec/lib/banzai/filter/upload_link_filter_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Gitlab::Markdown::UploadLinkFilter, lib: true do +describe Banzai::Filter::UploadLinkFilter, lib: true do def filter(doc, contexts = {}) contexts.reverse_merge!({ project: project diff --git a/spec/lib/gitlab/markdown/filter/user_reference_filter_spec.rb b/spec/lib/banzai/filter/user_reference_filter_spec.rb similarity index 98% rename from spec/lib/gitlab/markdown/filter/user_reference_filter_spec.rb rename to spec/lib/banzai/filter/user_reference_filter_spec.rb index 277037cf68aa1f765f1b94de4554393b0ad2fdf2..3534bf977846c9ea62dbfcaa3c7eecf40c01c76e 100644 --- a/spec/lib/gitlab/markdown/filter/user_reference_filter_spec.rb +++ b/spec/lib/banzai/filter/user_reference_filter_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -describe Gitlab::Markdown::UserReferenceFilter, lib: true do +describe Banzai::Filter::UserReferenceFilter, lib: true do include FilterSpecHelper let(:project) { create(:empty_project, :public) } diff --git a/spec/lib/gitlab/asciidoc_spec.rb b/spec/lib/gitlab/asciidoc_spec.rb index 3a860899e1856479b14fe9d2be2d15c374cef902..6beb21c6d2ba2bee1c6bf029d4169d1db8ad31e7 100644 --- a/spec/lib/gitlab/asciidoc_spec.rb +++ b/spec/lib/gitlab/asciidoc_spec.rb @@ -50,7 +50,7 @@ module Gitlab filtered_html = '<b>ASCII</b>' allow(Asciidoctor).to receive(:convert).and_return(html) - expect(Gitlab::Markdown).to receive(:render) + expect(Banzai).to receive(:render) .with(html, context.merge(pipeline: :asciidoc)) .and_return(filtered_html) diff --git a/spec/support/filter_spec_helper.rb b/spec/support/filter_spec_helper.rb index 91e3bee13c1a987d28e22fd493ff8bebadbf8284..d6e03cbef3dbb940c8e97349c8c9bbb8aac2ba2f 100644 --- a/spec/support/filter_spec_helper.rb +++ b/spec/support/filter_spec_helper.rb @@ -1,4 +1,4 @@ -# Helper methods for Gitlab::Markdown filter specs +# Helper methods for Banzai filter specs # # Must be included into specs manually module FilterSpecHelper @@ -10,49 +10,49 @@ module FilterSpecHelper # if none is provided. # # html - HTML String to pass to the filter's `call` method. - # contexts - Hash context for the filter. (default: {project: project}) + # context - Hash context for the filter. (default: {project: project}) # # Returns a Nokogiri::XML::DocumentFragment - def filter(html, contexts = {}) + def filter(html, context = {}) if defined?(project) - contexts.reverse_merge!(project: project) + context.reverse_merge!(project: project) end - described_class.call(html, contexts) + described_class.call(html, context) end # Run text through HTML::Pipeline with the current filter and return the # result Hash # # body - String text to run through the pipeline - # contexts - Hash context for the filter. (default: {project: project}) + # context - Hash context for the filter. (default: {project: project}) # # Returns the Hash - def pipeline_result(body, contexts = {}) - contexts.reverse_merge!(project: project) if defined?(project) + def pipeline_result(body, context = {}) + context.reverse_merge!(project: project) if defined?(project) - pipeline = HTML::Pipeline.new([described_class], contexts) + pipeline = HTML::Pipeline.new([described_class], context) pipeline.call(body) end - def reference_pipeline(contexts = {}) - contexts.reverse_merge!(project: project) if defined?(project) + def reference_pipeline(context = {}) + context.reverse_merge!(project: project) if defined?(project) filters = [ - Gitlab::Markdown::AutolinkFilter, + Banzai::Filter::AutolinkFilter, described_class, - Gitlab::Markdown::ReferenceGathererFilter + Banzai::Filter::ReferenceGathererFilter ] - HTML::Pipeline.new(filters, contexts) + HTML::Pipeline.new(filters, context) end - def reference_pipeline_result(body, contexts = {}) - reference_pipeline(contexts).call(body) + def reference_pipeline_result(body, context = {}) + reference_pipeline(context).call(body) end - def reference_filter(html, contexts = {}) - reference_pipeline(contexts).to_document(html) + def reference_filter(html, context = {}) + reference_pipeline(context).to_document(html) end # Modify a String reference to make it invalid