Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -72,6 +74,7 @@ const releasers: Record<string, ReleaseBuilder> = {
'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 =>
Expand Down
72 changes: 72 additions & 0 deletions src/strategies/mediawiki-extension.ts
Original file line number Diff line number Diff line change
@@ -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<Update[]> {
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;
}
}
72 changes: 72 additions & 0 deletions src/strategies/mediawiki-skin.ts
Original file line number Diff line number Diff line change
@@ -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<Update[]> {
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;
}
}
58 changes: 58 additions & 0 deletions src/updaters/php/mediawiki-extension-json.ts
Original file line number Diff line number Diff line change
@@ -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);
}
}