Skip to content

Commit

Permalink
Pull request 323: AG-34945: Add deprecated field to metadata
Browse files Browse the repository at this point in the history
Merge in ADGUARD-FILTERS/compiler from AG-34945 to master

Squashed commit of the following:

commit 84107af
Author: Vladimir Bachinskiy <[email protected]>
Date:   Thu Aug 29 14:59:27 2024 +0300

    AG-34945: No need to reflect old changes in changelog

commit b721a9a
Author: Slava Leleka <[email protected]>
Date:   Thu Aug 29 14:57:37 2024 +0300

    CHANGELOG.md edited online with Bitbucket

commit df1e292
Author: Vladimir Bachinskiy <[email protected]>
Date:   Thu Aug 29 14:43:31 2024 +0300

    AG-34945: Changelog

commit a1049d3
Author: Vladimir Bachinskiy <[email protected]>
Date:   Thu Aug 29 14:35:25 2024 +0300

    AG-34945: Add deprecated field to metadata
  • Loading branch information
forcomprehension committed Aug 29, 2024
1 parent f64c6e7 commit 4add672
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 7 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,14 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [v1.1.146] - 2024-08-29

### Added

- `deprecated` property to the built filters metadata

[v1.1.146]: https://github.com/AdguardTeam/FiltersCompiler/compare/v1.1.144...v1.1.146

## [v1.1.144] - 2024-08-14

### Fixed
Expand Down
7 changes: 7 additions & 0 deletions schemas/filters.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@
"downloadUrl",
"version",
"timeUpdated",
"deprecated",
"languages",
"tags"
],
Expand Down Expand Up @@ -154,6 +155,12 @@
],
"pattern": "^(.*)$"
},
"deprecated": {
"$id": "#/properties/filters/items/properties/deprecated",
"type": "boolean",
"title": "Filter is deprecated and shoudln't be used",
"default": false
},
"homepage": {
"$id": "#/properties/filters/items/properties/homepage",
"type": "string",
Expand Down
22 changes: 15 additions & 7 deletions src/main/platforms/generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -338,17 +338,24 @@ module.exports = (() => {
};

/**
* In case of backward compatibility
* Adds 'languages' metadata field parsed from 'lang:' tags
* First step of processing filters metadata
*
* @param rawFilters
* @param filtersMetadata
*/
const parseLangTags = function (rawFilters) {
const processFiltersFromMetadata = function (filtersMetadata) {
// do not mutate input parameters
const filters = [];
// eslint-disable-next-line no-restricted-syntax
for (const filter of rawFilters) {
const newFilter = { ...filter };
for (const filter of filtersMetadata) {
const newFilter = {
...filter,
deprecated: Boolean(filter.deprecated),
};

/**
* In case of backward compatibility
* Adds 'languages' metadata field parsed from 'lang:' tags
*/
if (newFilter.tags) {
const filterLanguages = [];
let hasRecommended = false;
Expand All @@ -366,6 +373,7 @@ module.exports = (() => {
// Languages will be added for recommended filters only
newFilter.languages = hasRecommended ? filterLanguages : [];
}

filters.push(newFilter);
}

Expand Down Expand Up @@ -617,7 +625,7 @@ module.exports = (() => {
}

// do not mutate input parameters
const parsedLangTagsFiltersMetadata = parseLangTags(filtersMetadata);
const parsedLangTagsFiltersMetadata = processFiltersFromMetadata(filtersMetadata);
const replacedTagKeywordsFiltersMetadata = replaceTagKeywords(parsedLangTagsFiltersMetadata, tags);

const localizations = loadLocales(path.join(filtersDir, '../locales'));
Expand Down
2 changes: 2 additions & 0 deletions src/main/utils/workaround.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,8 @@ module.exports = (() => {
delete copy.timeAdded;
delete copy.trustLevel;
delete copy.downloadUrl;
delete copy.deprecated;

result.filters.push(copy);
}

Expand Down
5 changes: 5 additions & 0 deletions src/test/builder.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,11 @@ describe('Test builder', () => {
expect(filtersMetadata.filters[0].tags[0]).toEqual(1);
expect(filtersMetadata.filters[0].trustLevel).toEqual('full');

// Deprecated
filtersMetadata.filters.forEach((filter) => {
expect(filter.deprecated).toBe(filter.filterId === 2);
});

// Obsolete Filter test
expect(filtersMetadata.filters.some((filter) => filter.filterId === 6)).toBeFalsy();
expect(filtersMetadata.filters.some((filter) => filter.name === 'Obsolete Test Filter')).toBeFalsy();
Expand Down
1 change: 1 addition & 0 deletions src/test/resources/filters/filter_2_English/metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"expires": "2 days",
"displayNumber": 101,
"groupId": 2,
"deprecated": true,
"subscriptionUrl": "https://filters.adtidy.org/extension/chromium/filters/2.txt",
"tags": [
"purpose:ads", "lang:en", "lang:pl", "recommended"
Expand Down

0 comments on commit 4add672

Please sign in to comment.