Skip to content

Commit

Permalink
Merge pull request #17 from artemeon/feat/configuration-import
Browse files Browse the repository at this point in the history
Introduce config importer
  • Loading branch information
marcreichel authored Feb 17, 2022
2 parents b666092 + b2c669c commit ba39540
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 3 deletions.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,14 @@ mantis2github configure

The command will direct you through the installation process.

### Quick setup

If you have used a previous version of this package and already have a `config.yaml` file, you can skip the configuration by running:

```shell
mantis2github configure path/to/config.yaml
```

## Usage

```shell
Expand Down
42 changes: 40 additions & 2 deletions src/Command/ConfigurationCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

use Artemeon\M2G\Config\ConfigReader;
use Artemeon\M2G\Service\GithubConnector;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Yaml\Yaml;

use function Termwind\{render, terminal};

Expand All @@ -25,12 +27,15 @@ public function __construct(GithubConnector $mantisConnector)

protected function configure()
{
$this->setName('configure');
$this->setDescription('Configure the tool');
$this->setName('configure')
->setDescription('Configure the tool')
->addArgument('file', InputArgument::OPTIONAL, 'The config.yaml to use for setting up the tool.');
}

protected function handle(): int
{
$this->readExistingConfigFromPath();

terminal()->clear();

$this->header();
Expand Down Expand Up @@ -159,4 +164,37 @@ protected function saveConfig(): void

$this->success(" Synchronize your first issue by running `mantis2github sync`!\n");
}

protected function readExistingConfigFromPath()
{
if (!$this->argument('file')) {
return;
}

if (!file_exists($this->argument('file'))) {
$this->error('The given config file does not exist.');

exit(1);
}

$config = Yaml::parseFile($this->argument('file'));

if (!$config['MANTIS_URL'] || !$config['MANTIS_TOKEN'] || !$config['GITHUB_TOKEN'] || !$config['GITHUB_REPOSITORY']) {
$this->error('The given config file is incomplete.');
$this->info('Please configure the tool without the file parameter.');

exit(1);
}

$this->config = [
'mantisUrl' => $config['MANTIS_URL'],
'mantisToken' => $config['MANTIS_TOKEN'],
'githubToken' => $config['GITHUB_TOKEN'],
'githubRepository' => $config['GITHUB_REPOSITORY'],
];

$this->saveConfig();

exit(0);
}
}
2 changes: 1 addition & 1 deletion src/Command/CreateGithubIssueFromMantisIssue.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public function __construct(MantisConnector $mantisConnector, GithubConnector $g
protected function configure()
{
$this->setName('sync')
->setDescription('Synchronize a Mantis issue to GitHub')
->setDescription('Synchronize a list of Mantis issues to GitHub')
->addArgument('ids', InputArgument::IS_ARRAY | InputArgument::REQUIRED, 'Mantis issue ids');
}

Expand Down

0 comments on commit ba39540

Please sign in to comment.