Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a CLI command to unlock a project #247

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
58 changes: 58 additions & 0 deletions inc/CLI/ProjectCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -205,4 +205,62 @@

WP_CLI::warning( sprintf( 'Could not update translations for project (ID: %d)!', $project->get_id() ) );
}

/**
* Unlocks a project.
*
* Finds the project and removes the lock.
*
* ## OPTIONS
*
* <project|url>
* : Project path / ID or source code repository URL, e.g. https://github.com/wearerequired/required-valencia
*
* ## EXAMPLES
*
* # Unlock project with repository URL.
* $ wp traduttore project unlock https://github.com/wearerequired/required-valencia
* Success: Project unlocked (ID: 123)!
*
* # Unlock project with project path.
* $ wp traduttore project unlock wearerequired/required-valencia
* Success: Project unlocked (ID: 123)!
*
* # Unlock project with project ID.
* $ wp traduttore project unlock 123
* Success: Project unlocked (ID: 123)!
*
* @param string[] $args Command args.
*/
public function unlock( array $args ): void {

Check warning on line 235 in inc/CLI/ProjectCommand.php

View check run for this annotation

Codecov / codecov/patch

inc/CLI/ProjectCommand.php#L235

Added line #L235 was not covered by tests

$locator = new ProjectLocator( $args[0] );
$project = $locator->get_project();

Check warning on line 238 in inc/CLI/ProjectCommand.php

View check run for this annotation

Codecov / codecov/patch

inc/CLI/ProjectCommand.php#L237-L238

Added lines #L237 - L238 were not covered by tests

if ( ! $project ) {
WP_CLI::error( 'Project not found' );

Check warning on line 241 in inc/CLI/ProjectCommand.php

View check run for this annotation

Codecov / codecov/patch

inc/CLI/ProjectCommand.php#L240-L241

Added lines #L240 - L241 were not covered by tests
}

$repository = ( new RepositoryFactory() )->get_repository( $project );

Check warning on line 244 in inc/CLI/ProjectCommand.php

View check run for this annotation

Codecov / codecov/patch

inc/CLI/ProjectCommand.php#L244

Added line #L244 was not covered by tests

if ( ! $repository ) {
WP_CLI::error( 'Invalid project type' );

Check warning on line 247 in inc/CLI/ProjectCommand.php

View check run for this annotation

Codecov / codecov/patch

inc/CLI/ProjectCommand.php#L246-L247

Added lines #L246 - L247 were not covered by tests
}

$loader = ( new LoaderFactory() )->get_loader( $repository );

Check warning on line 250 in inc/CLI/ProjectCommand.php

View check run for this annotation

Codecov / codecov/patch

inc/CLI/ProjectCommand.php#L250

Added line #L250 was not covered by tests

if ( ! $loader ) {
WP_CLI::error( 'Invalid project type' );

Check warning on line 253 in inc/CLI/ProjectCommand.php

View check run for this annotation

Codecov / codecov/patch

inc/CLI/ProjectCommand.php#L252-L253

Added lines #L252 - L253 were not covered by tests
}

$updater = new Updater( $project );

Check warning on line 256 in inc/CLI/ProjectCommand.php

View check run for this annotation

Codecov / codecov/patch

inc/CLI/ProjectCommand.php#L256

Added line #L256 was not covered by tests

if ( ! $updater->has_lock() ) {
WP_CLI::error( sprintf( 'Project was not locked (ID: %d)!', $project->get_id() ) );

Check warning on line 259 in inc/CLI/ProjectCommand.php

View check run for this annotation

Codecov / codecov/patch

inc/CLI/ProjectCommand.php#L258-L259

Added lines #L258 - L259 were not covered by tests
}

$updater->remove_lock();

Check warning on line 262 in inc/CLI/ProjectCommand.php

View check run for this annotation

Codecov / codecov/patch

inc/CLI/ProjectCommand.php#L262

Added line #L262 was not covered by tests

WP_CLI::success( sprintf( 'Project unlocked (ID: %d)!', $project->get_id() ) );

Check warning on line 264 in inc/CLI/ProjectCommand.php

View check run for this annotation

Codecov / codecov/patch

inc/CLI/ProjectCommand.php#L264

Added line #L264 was not covered by tests
}
}