Skip to content
Snippets Groups Projects

Issue #3316721: Add script to convert this module into a core merge request

Merged Issue #3316721: Add script to convert this module into a core merge request
2 unresolved threads
2 unresolved threads
+ 25
15
@@ -234,10 +234,9 @@ class Converter {
* Ensures the git status is clean.
*
* @return bool
*
* @throws \Exception
* TRUE if git status is clean , otherwise returns a exception.
*/
private static function ensureGitClean() {
private static function ensureGitClean(): bool {
$status_output = shell_exec('git status');
if (strpos($status_output, 'nothing to commit, working tree clean') === FALSE) {
throw new \Exception("git not clean: " . $status_output);
@@ -249,8 +248,9 @@ class Converter {
* Gets the current git branch.
*
* @return string
* The current git branch.
*/
private static function getCurrentBranch() {
private static function getCurrentBranch(): string {
return trim(shell_exec('git rev-parse --abbrev-ref HEAD'));
}
@@ -258,10 +258,11 @@ class Converter {
* Switches to the branches we need.
*
* @param string $core_dir
* The path to the root of Drupal Core.
* @param string $core_branch
* The core merge request branch.
*/
private static function switchToBranches(string $core_dir, string $core_branch) {
private static function switchToBranches(string $core_dir, string $core_branch): void {
// @todo Don't switch while developing this script. Uncomment before commit.
// static::switchToBranch('8.x-2.x');
chdir($core_dir);
@@ -272,10 +273,9 @@ class Converter {
* Switches to a branches and makes sure it is clean.
*
* @param string $branch
*
* @throws \Exception
* The branch to switch to.
*/
private static function switchToBranch(string $branch) {
private static function switchToBranch(string $branch): void {
static::ensureGitClean();
shell_exec("git checkout $branch");
if ($branch !== static::getCurrentBranch()) {
@@ -284,9 +284,12 @@ class Converter {
}
/**
* Makes commit in the root of Drupal Core.
*
* @param string $core_dir
* The path to the root of Drupal Core.
*/
private static function makeCommit(string $core_dir) {
private static function makeCommit(string $core_dir): void {
chdir(self::getContribDir());
self::ensureGitClean();
$hash = trim(shell_exec('git rev-parse HEAD'));
@@ -297,9 +300,14 @@ class Converter {
}
/**
* Adds new words to cspell dictionary.
*
* @param string $core_dir
* The path to the root of Drupal Core.
* @param array $new_words
* An array of new words.
*/
private static function addWordsToDictionary(string $core_dir, array $new_words) {
private static function addWordsToDictionary(string $core_dir, array $new_words): void {
$dict_file = $core_dir . '/core/misc/cspell/dictionary.txt';
$contents = file_get_contents($dict_file);
$words = explode("\n", $contents);
@@ -312,15 +320,16 @@ class Converter {
}
asort($words);
file_put_contents($dict_file, implode("\n", $words));
}
/**
* Runs code quality checks.
*
* @param string $core_dir
* The path to the root of Drupal Core.
*/
private static function runCoreChecks(string $core_dir) {
private static function runCoreChecks(string $core_dir):void {
chdir($core_dir);
$output = NULL;
$result = NULL;
system(' sh ./core/scripts/dev/commit-code-check.sh --branch 9.5.x', $result);
if ($result !== 0) {
@@ -334,9 +343,10 @@ class Converter {
* Removes lines from the module based on a starting and ending token
* These are lines that are not need in core at all.
*
* @throws \Exception
* @param string $core_dir
* The path to the root of Drupal Core.
*/
private static function removeLines(string $core_dir) {
private static function removeLines(string $core_dir): void {
$files = static::getDirContents(static::getCoreModulePath($core_dir), TRUE);
foreach ($files as $file) {
$filePath = $file->getRealPath();
Loading