Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
aue
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
aue
Merge requests
!2
Issue
#3445189
add Git integration
Code
Review changes
Check out branch
Download
Patches
Plain diff
Open
Issue
#3445189
add Git integration
issue/aue-3445189:3445189-git
into
1.0.x
Overview
0
Commits
10
Pipelines
0
Changes
5
Open
Ted Bowman
requested to merge
issue/aue-3445189:3445189-git
into
1.0.x
1 year ago
Overview
0
Commits
10
Pipelines
0
Changes
5
Expand
Closes
#3445189
0
0
Merge request reports
Compare
1.0.x
version 4
9f62836d
1 year ago
version 3
34965b6d
1 year ago
version 2
c39266c0
1 year ago
version 1
d5f6bf4c
1 year ago
1.0.x (HEAD)
and
latest version
latest version
60cca765
10 commits,
1 year ago
version 4
9f62836d
6 commits,
1 year ago
version 3
34965b6d
2 commits,
1 year ago
version 2
c39266c0
1 commit,
1 year ago
version 1
d5f6bf4c
1 commit,
1 year ago
5 files
+
111
−
1
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
Files
5
Search (e.g. *.vue) (Ctrl+P)
modules/aue_git/src/GitCommitUpdater.php
0 → 100644
+
77
−
0
Options
<?php
namespace
Drupal\aue_git
;
use
CzProject\GitPhp\Git
;
use
CzProject\GitPhp\GitException
;
use
Drupal\Core\StringTranslation\StringTranslationTrait
;
use
Drupal\package_manager
\Event\PostApplyEvent
;
use
Drupal\package_manager
\Event\PreApplyEvent
;
use
Drupal\package_manager
\Event\StatusCheckEvent
;
use
Drupal\package_manager
\PathLocator
;
use
Symfony\Component\EventDispatcher\EventSubscriberInterface
;
class
GitCommitUpdater
implements
EventSubscriberInterface
{
/**
* {@inheritdoc}
*/
public
static
function
getSubscribedEvents
():
array
{
return
[
StatusCheckEvent
::
class
=>
'onStatusCheck'
,
// PreApplyEvent::class => 'checkGitStatus',
// PostApplyEvent::class => 'onPostApply',
];
}
use
StringTranslationTrait
;
public
function
__construct
(
private
PathLocator
$pathLocator
)
{
}
/**
* Ensure that the Git repository exists and that working directory is clean
*
* @param \Drupal\package_manager\Event\StatusCheckEvent $event
*/
public
function
onStatusCheck
(
StatusCheckEvent
$event
):
void
{
if
(
in_array
(
$event
->
stage
->
getType
(),
[
'automatic_updates:unattended'
,
'automatic_updates:attended'
]))
{
$git
=
new
Git
();
$project_root
=
$this
->
pathLocator
->
getProjectRoot
();
try
{
$repo
=
$git
->
open
(
$project_root
);
}
catch
(
GitException
$exception
)
{
// @TODO: Should this be an error or a warning?
$event
->
addWarning
([
t
(
"No Git repository detected."
)]);
return
;
}
if
(
$repo
->
hasChanges
())
{
$changes
=
$repo
->
execute
(
"status"
);
$imploded
=
implode
(
"
\n
"
,
$changes
);
$event
->
addError
([
t
(
$imploded
)],
t
(
"Cannot move forward with Package Manager operations: There are uncommitted changes in Git."
));
}
}
}
/**
* Make a Git commit after updating.
*
* @param \Drupal\package_manager\Event\PostApplyEvent $event
*/
public
function
onPostApply
(
PostApplyEvent
$event
):
void
{
if
(
$event
->
stage
->
getType
()
===
'automatic_updates:attended'
)
{
$this
->
makeGitCommit
(
$this
->
pathLocator
->
getProjectRoot
());
}
}
private
function
makeGitCommit
(
string
$projectRoot
)
{
}
}
Loading