/** * Run the database seeds. * * @return void */ public function run() { $firstCondition = new Condition(['type' => 'if', 'field' => 'event.type', 'operator' => '==', 'value' => 'push']); $firstCondition->save(); $splitter = new Splitter(); $splitter->save(); $firstSplit = new Split(); $firstSplit->save(); $secondSplit = new Split(); $secondSplit->save(); $secondCondition = new Condition(['type' => 'contains', 'field' => '', 'operator' => '==', 'value' => '']); $secondCondition->save(); $firstAction = new Action(['type' => 'ssh']); $host = new Host(['host' => 'ssh', 'port' => '22']); $auth = new Auth(); $accountAuth = new AuthAccount(); $accountAuth->username = getenv('SSH_USERNAME'); $accountAuth->password = getenv('SSH_PASSWORD'); $accountAuth->save(); try { $file = new File(); $keyAuth = new AuthKey(); $keyAuth->username = '******'; $keyAuth->key = $file->get('.docker/builds/ssh/ssh_keys/id_rsa'); $keyAuth->key_public = $file->get('.docker/builds/ssh/ssh_keys/id_rsa.pub'); $keyAuth->save(); } catch (Illuminate\Filesystem\FileNotFoundException $exception) { dump("SSH Key Not Found"); } $auth->credentials()->associate($keyAuth); $auth->save(); $host->auth()->associate($auth); $host->save(); $firstAction->host()->associate($host); $firstAction->save(); $firstAction->addCommand('touch testing'); $firstAction->addCommand('ls'); $secondAction = new Action(); $secondAction->save(); $secondAction->addCommand('composer install'); $secondCondition->successPipeable()->associate($secondAction)->save(); $firstSplit->pipeable()->associate($secondCondition); $secondSplit->pipeable()->associate($firstAction); $splitter->splits()->save($firstSplit); $splitter->splits()->save($secondSplit); $firstCondition->successPipeable()->associate($splitter)->save(); $project = new Project(); $project->name = 'example'; $project->group = 'exampleGroup'; $project->url = 'http://localhost/exampleGroup/example'; $project->project_id = 2; $project->save(); $project->conditions()->save($firstCondition); }
/** * Attaches a relationship to the model * * @param String $relationshipName Name of relationship in request * @param Model $model Model that has the relationships * @param mixed $relationshipData Model(s) to associate * * @return Model */ public function attachRelationship($relationshipName, Model $model, $relationshipData) { if ($relationshipName === 'splits') { $relationshipData = array_map(function ($item) { $split = new Split(); $split->pipeable()->associate($item); $split->save(); return $split; }, $relationshipData); $model->splits()->saveMany($relationshipData); } return $model; }