Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
V
violinist_teams
Manage
Activity
Members
Labels
Plan
Wiki
Custom issue tracker
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Model registry
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
project
violinist_teams
Commits
47969f52
Commit
47969f52
authored
1 year ago
by
Eirik Morland
Browse files
Options
Downloads
Patches
Plain Diff
Issue
#3418893
by eiriksm: Add support for pull request instructions
parent
0cd82d19
No related branches found
No related tags found
1 merge request
!28
Fix and test
Pipeline
#86848
passed
1 year ago
Stage: build
Stage: validate
Stage: test
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/TeamNode.php
+20
-0
20 additions, 0 deletions
src/TeamNode.php
tests/src/Kernel/KernelTestBase.php
+16
-0
16 additions, 0 deletions
tests/src/Kernel/KernelTestBase.php
tests/src/Kernel/TeamNodeTest.php
+18
-0
18 additions, 0 deletions
tests/src/Kernel/TeamNodeTest.php
with
54 additions
and
0 deletions
src/TeamNode.php
+
20
−
0
View file @
47969f52
...
...
@@ -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.
*
...
...
This diff is collapsed.
Click to expand it.
tests/src/Kernel/KernelTestBase.php
+
16
−
0
View file @
47969f52
...
...
@@ -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'
,
...
...
This diff is collapsed.
Click to expand it.
tests/src/Kernel/TeamNodeTest.php
+
18
−
0
View file @
47969f52
...
...
@@ -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.
*/
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment