Skip to content
Snippets Groups Projects
Commit 47969f52 authored by Eirik Morland's avatar Eirik Morland
Browse files

Issue #3418893 by eiriksm: Add support for pull request instructions

parent 0cd82d19
No related branches found
No related tags found
1 merge request!28Fix and test
Pipeline #86848 passed
......@@ -186,6 +186,26 @@ class TeamNode extends Node {
return in_array($user->id(), $this->getAdministrators());
}
/**
* Getter for this field.
*/
public function getPullRequestInstructions() : ?string {
if (!$this->hasField('field_pull_request_template') || $this->get('field_pull_request_template')->isEmpty()) {
return FALSE;
}
return $this->get('field_pull_request_template')->first()->getString();
}
/**
* Setter for this field.
*/
public function setPullRequestInstructions(string $instructions) {
if (!$this->hasField('field_pull_request_template')) {
return;
}
$this->set('field_pull_request_template', $instructions);
}
/**
* Get all of the admins of a team.
*
......
......@@ -120,6 +120,22 @@ abstract class KernelTestBase extends CoreKernelTestBase {
]);
$field->save();
// The field we use for PR templates.
$fieldStorage = FieldStorageConfig::create([
'field_name' => 'field_pull_request_template',
'entity_type' => 'node',
'type' => 'string_long',
'cardinality' => 1,
]);
$fieldStorage->save();
$field = FieldConfig::create([
'field_storage' => $fieldStorage,
'bundle' => $this->nodeType->id(),
'field_type' => 'string_long',
'required' => FALSE,
]);
$field->save();
// Slack notifications.
$fieldStorage = FieldStorageConfig::create([
'field_name' => 'field_slack_notifications',
......
......@@ -116,6 +116,24 @@ class TeamNodeTest extends KernelTestBase {
self::assertEquals($expected_result, $node->getEnvironmentVariables());
}
/**
* Test logic for getting (and setting) the pull request instructions.
*/
public function testPullRequestInstructions() {
// First test an empty one.
/** @var \Drupal\violinist_teams\TeamNode $node */
$node = Node::create([
'type' => $this->nodeType->id(),
]);
self::assertEquals('', $node->getPullRequestInstructions());
// Now set a value and assume we get it back.
$node->set('field_pull_request_template', 'This is a test');
self::assertEquals('This is a test', $node->getPullRequestInstructions());
// Also make sure the setter work.
$node->setPullRequestInstructions('This is another test');
self::assertEquals('This is another test', $node->getPullRequestInstructions());
}
/**
* Dataprovider for environment variables.
*/
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment