-
Notifications
You must be signed in to change notification settings - Fork 0
/
assistant.module
executable file
·74 lines (63 loc) · 1.64 KB
/
assistant.module
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
<?php
/**
* @file
* Defines common functionality for ACC assistant.
*/
use Drupal\Core\Url;
/**
* Implements hook_toolbar().
*/
function assistant_toolbar() {
$tabs = [];
$env = acc_get_environment();
if ($env != 'dev' && $env != 'local') {
$tabs['git_info'] = [
'#type' => 'toolbar_item',
'tab' => [
'#type' => 'link',
'#title' => t('Release: @git', ['@git' => acc_get_git_state($env)]),
'#url' => Url::fromRoute('<nolink>', []),
'#attributes' => [
'style' => 'display: block; padding-left: 10px; background-color: inherit; cursor: inherit; color: #fc0; font-weight: 100;',
],
],
'#weight' => 999999,
'#cache' => [
'max-age' => 0,
],
];
}
return $tabs;
}
/**
* Get current state of git.
*
* @param $env string with current environment
*
* @return string , can be local, dev, stage, prod
*/
function acc_get_git_state($env) {
if ($env == 'dev' || $env == 'stage' || $env == 'prod') {
$git = shell_exec("drush @accuchekde." . $env . " ac-environment-info accuchekde " . $env . " | grep vcs_path | awk -F'/' '{print $2}'");
}
else {
$git = shell_exec("describe --tags --abbrev=0");
if ($git === NULL) {
$git = shell_exec("git log -1 --pretty=format:'%s (%ci)' --abbrev-commit `git merge-base local-dev dev`");
};
}
return $git;
}
/**
* Get a current environment name.
*
* @return string, can be local, dev, stage, prod
*/
function acc_get_environment() {
if (isset($_ENV['AH_SITE_ENVIRONMENT'])) {
return $_ENV['AH_SITE_ENVIRONMENT'];
}
else {
return 'local';
}
}