diff --git a/src/factory.ts b/src/factory.ts index ae6f1bf8d..d7f7eab38 100644 --- a/src/factory.ts +++ b/src/factory.ts @@ -31,6 +31,8 @@ import {JavaYoshi} from './strategies/java-yoshi'; import {JavaYoshiMonoRepo} from './strategies/java-yoshi-mono-repo'; import {KRMBlueprint} from './strategies/krm-blueprint'; import {Maven} from './strategies/maven'; +import {MediaWikiSkin} from './strategies/mediawiki-skin'; +import {MediaWikiExtension} from './strategies/mediawiki-extension'; import {Node} from './strategies/node'; import {OCaml} from './strategies/ocaml'; import {PHP} from './strategies/php'; @@ -72,6 +74,7 @@ const releasers: Record = { 'go-yoshi': options => new GoYoshi(options), java: options => new Java(options), maven: options => new Maven(options), + 'mediawiki-skin': options => new MediaWikiSkin(options), 'java-yoshi': options => new JavaYoshi(options), 'java-yoshi-mono-repo': options => new JavaYoshiMonoRepo(options), 'java-backport': options => diff --git a/src/strategies/mediawiki-extension.ts b/src/strategies/mediawiki-extension.ts new file mode 100644 index 000000000..e0b5a4f9b --- /dev/null +++ b/src/strategies/mediawiki-extension.ts @@ -0,0 +1,72 @@ +// Copyright 2021 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// Generic +import {Changelog} from '../updaters/changelog'; +// MediaWiki Extension Specific. +import {MediaWikiExtensionJson} from '../updaters/php/mediawiki-extension-json'; +import {BaseStrategy, BuildUpdatesOptions, BaseStrategyOptions} from './base'; +import {DefaultUpdater} from '../updaters/default'; +import {Update} from '../update'; +import {VersionsMap} from '../version'; + +const CHANGELOG_SECTIONS = [ + {type: 'feat', section: 'Features'}, + {type: 'fix', section: 'Bug Fixes'}, + {type: 'perf', section: 'Performance Improvements'}, + {type: 'revert', section: 'Reverts'}, + {type: 'chore', section: 'Miscellaneous Chores'}, + {type: 'docs', section: 'Documentation', hidden: true}, + {type: 'style', section: 'Styles', hidden: true}, + {type: 'refactor', section: 'Code Refactoring', hidden: true}, + {type: 'test', section: 'Tests', hidden: true}, + {type: 'build', section: 'Build System', hidden: true}, + {type: 'ci', section: 'Continuous Integration', hidden: true}, +]; + +export class MediaWikiExtension extends BaseStrategy { + constructor(options: BaseStrategyOptions) { + options.changelogSections = options.changelogSections ?? CHANGELOG_SECTIONS; + super(options); + } + + protected async buildUpdates( + options: BuildUpdatesOptions + ): Promise { + const updates: Update[] = []; + const version = options.newVersion; + const versionsMap: VersionsMap = new Map(); + + updates.push({ + path: this.addPath(this.changelogPath), + createIfMissing: true, + updater: new Changelog({ + version, + changelogEntry: options.changelogEntry, + }), + }); + + // update composer.json + updates.push({ + path: this.addPath('extension.json'), + createIfMissing: false, + updater: new MediaWikiExtensionJson({ + version, + versionsMap, + }), + }); + + return updates; + } +} diff --git a/src/strategies/mediawiki-skin.ts b/src/strategies/mediawiki-skin.ts new file mode 100644 index 000000000..18797fba9 --- /dev/null +++ b/src/strategies/mediawiki-skin.ts @@ -0,0 +1,72 @@ +// Copyright 2021 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// Generic +import {Changelog} from '../updaters/changelog'; +// MediaWiki Skin Specific. +import {MediaWikiExtensionJson} from '../updaters/php/mediawiki-extension-json'; +import {BaseStrategy, BuildUpdatesOptions, BaseStrategyOptions} from './base'; +import {DefaultUpdater} from '../updaters/default'; +import {Update} from '../update'; +import {VersionsMap} from '../version'; + +const CHANGELOG_SECTIONS = [ + {type: 'feat', section: 'Features'}, + {type: 'fix', section: 'Bug Fixes'}, + {type: 'perf', section: 'Performance Improvements'}, + {type: 'revert', section: 'Reverts'}, + {type: 'chore', section: 'Miscellaneous Chores'}, + {type: 'docs', section: 'Documentation', hidden: true}, + {type: 'style', section: 'Styles', hidden: true}, + {type: 'refactor', section: 'Code Refactoring', hidden: true}, + {type: 'test', section: 'Tests', hidden: true}, + {type: 'build', section: 'Build System', hidden: true}, + {type: 'ci', section: 'Continuous Integration', hidden: true}, +]; + +export class MediaWikiSkin extends BaseStrategy { + constructor(options: BaseStrategyOptions) { + options.changelogSections = options.changelogSections ?? CHANGELOG_SECTIONS; + super(options); + } + + protected async buildUpdates( + options: BuildUpdatesOptions + ): Promise { + const updates: Update[] = []; + const version = options.newVersion; + const versionsMap: VersionsMap = new Map(); + + updates.push({ + path: this.addPath(this.changelogPath), + createIfMissing: true, + updater: new Changelog({ + version, + changelogEntry: options.changelogEntry, + }), + }); + + // update composer.json + updates.push({ + path: this.addPath('skin.json'), + createIfMissing: false, + updater: new MediaWikiExtensionJson({ + version, + versionsMap, + }), + }); + + return updates; + } +} diff --git a/src/updaters/php/mediawiki-extension-json.ts b/src/updaters/php/mediawiki-extension-json.ts new file mode 100644 index 000000000..21fdef772 --- /dev/null +++ b/src/updaters/php/mediawiki-extension-json.ts @@ -0,0 +1,58 @@ +// Copyright 2019 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +import {logger as defaultLogger, Logger} from '../../util/logger'; +import {jsonStringify} from '../../util/json-stringify'; +import {DefaultUpdater} from '../default'; + +/** + * Updates a extension.json + */ +export class MediaWikiExtensionJson extends DefaultUpdater { + /** + * Given initial file contents, return updated contents. + * @param {string} content The initial content + * @returns {string} The updated content + */ + updateContent(content: string, logger: Logger = defaultLogger): string { + if (!this.version && (!this.versionsMap || this.versionsMap.size === 0)) { + logger.info('no updates necessary'); + return content; + } + const parsed = JSON.parse(content); + if (parsed['version']) { + const fromVersion: string = parsed['version']; + const toVersion = this.version.toString() || '1.0.0'; + parsed['version'] = toVersion; + logger.info(`updating "version" from ${fromVersion} to ${toVersion}`); + } + if (this.versionsMap) { + for (const [key, version] of this.versionsMap.entries()) { + const toVersion = version.toString() || '1.0.0'; + let fromVersion: string | undefined; + if (parsed.replace) { + fromVersion = parsed.replace[key]; + parsed.replace[key] = toVersion; + } + if (parsed[key]) { + fromVersion ??= parsed[key]; + parsed[key] = toVersion; + } + + logger.info(`updating ${key} from ${fromVersion} to ${toVersion}`); + } + } + return jsonStringify(parsed, content); + } +}