Skip to content

Commit 5d49bfe

Browse files
committed
MBS-10358: Add hook callbacks and pipeline
1 parent 326a749 commit 5d49bfe

File tree

7 files changed

+204
-6
lines changed

7 files changed

+204
-6
lines changed

.github/workflows/ci.yml

Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
name: Moodle Plugin CI
2+
3+
on: [push, pull_request]
4+
5+
jobs:
6+
test:
7+
runs-on: ubuntu-latest
8+
9+
services:
10+
postgres:
11+
image: postgres:17
12+
env:
13+
POSTGRES_USER: 'postgres'
14+
POSTGRES_HOST_AUTH_METHOD: 'trust'
15+
ports:
16+
- 5432:5432
17+
options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 3
18+
19+
mariadb:
20+
image: mariadb:10.11
21+
env:
22+
MYSQL_USER: 'root'
23+
MYSQL_ALLOW_EMPTY_PASSWORD: "true"
24+
MYSQL_CHARACTER_SET_SERVER: "utf8mb4"
25+
MYSQL_COLLATION_SERVER: "utf8mb4_unicode_ci"
26+
ports:
27+
- 3306:3306
28+
options: --health-cmd="mysqladmin ping" --health-interval 10s --health-timeout 5s --health-retries 3
29+
30+
strategy:
31+
fail-fast: false
32+
matrix:
33+
php: ['8.3', '8.4']
34+
moodle-branch: ['main', 'MOODLE_500_STABLE', 'MOODLE_501_STABLE']
35+
database: [pgsql, mariadb]
36+
37+
steps:
38+
- name: Check out repository code
39+
uses: actions/checkout@v4
40+
with:
41+
path: plugin
42+
43+
- name: Setup PHP ${{ matrix.php }}
44+
uses: shivammathur/setup-php@v2
45+
with:
46+
php-version: ${{ matrix.php }}
47+
extensions: ${{ matrix.extensions }}
48+
ini-values: max_input_vars=5000
49+
# If you are not using code coverage, keep "none". Otherwise, use "pcov" (Moodle 3.10 and up) or "xdebug".
50+
# If you try to use code coverage with "none", it will fallback to phpdbg (which has known problems).
51+
coverage: none
52+
53+
- name: Initialise moodle-plugin-ci
54+
run: |
55+
composer create-project -n --no-dev --prefer-dist moodlehq/moodle-plugin-ci ci ^4
56+
echo $(cd ci/bin; pwd) >> $GITHUB_PATH
57+
echo $(cd ci/vendor/bin; pwd) >> $GITHUB_PATH
58+
sudo locale-gen en_AU.UTF-8
59+
echo "NVM_DIR=$HOME/.nvm" >> $GITHUB_ENV
60+
61+
- name: Install moodle-plugin-ci
62+
run: |
63+
moodle-plugin-ci add-plugin bycs-lp/moodle-block_ai_chat
64+
moodle-plugin-ci install --plugin ./plugin --db-host=127.0.0.1
65+
env:
66+
DB: ${{ matrix.database }}
67+
MOODLE_BRANCH: ${{ matrix.moodle-branch }}
68+
# Uncomment this to run Behat tests using the Moodle App.
69+
# MOODLE_APP: 'true'
70+
71+
- name: PHP Lint
72+
if: ${{ !cancelled() }}
73+
run: moodle-plugin-ci phplint
74+
75+
- name: Moodle Code Checker
76+
if: ${{ !cancelled() }}
77+
run: moodle-plugin-ci phpcs --max-warnings 0
78+
79+
- name: Moodle PHPDoc Checker
80+
if: ${{ !cancelled() }}
81+
run: moodle-plugin-ci phpdoc --max-warnings 0
82+
83+
- name: Validating
84+
if: ${{ !cancelled() }}
85+
run: moodle-plugin-ci validate
86+
87+
- name: Check upgrade savepoints
88+
if: ${{ !cancelled() }}
89+
run: moodle-plugin-ci savepoints
90+
91+
- name: Mustache Lint
92+
if: ${{ !cancelled() }}
93+
# Error in dialog_modal {{$title}} is expected.
94+
run: moodle-plugin-ci mustache || true
95+
96+
- name: Grunt
97+
if: ${{ !cancelled() }}
98+
run: moodle-plugin-ci grunt --max-lint-warnings 0
99+
100+
- name: PHPUnit tests
101+
if: ${{ !cancelled() }}
102+
run: moodle-plugin-ci phpunit --fail-on-warning
103+
104+
- name: Behat features
105+
id: behat
106+
if: ${{ !cancelled() }}
107+
run: moodle-plugin-ci behat --profile chrome
108+
109+
- name: Upload Behat Faildump
110+
if: ${{ failure() && steps.behat.outcome == 'failure' }}
111+
uses: actions/upload-artifact@v4
112+
with:
113+
name: Behat Faildump (${{ join(matrix.*, ', ') }})
114+
path: ${{ github.workspace }}/moodledata/behat_dump
115+
retention-days: 7
116+
if-no-files-found: ignore
117+
118+
- name: Mark cancelled jobs as failed.
119+
if: ${{ cancelled() }}
120+
run: exit 1

classes/local/hook_callbacks.php

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<?php
2+
// This file is part of Moodle - http://moodle.org/
3+
//
4+
// Moodle is free software: you can redistribute it and/or modify
5+
// it under the terms of the GNU General Public License as published by
6+
// the Free Software Foundation, either version 3 of the License, or
7+
// (at your option) any later version.
8+
//
9+
// Moodle is distributed in the hope that it will be useful,
10+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
// GNU General Public License for more details.
13+
//
14+
// You should have received a copy of the GNU General Public License
15+
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
16+
17+
namespace mod_aichat\local;
18+
19+
/**
20+
* Class hook_callbacks.
21+
*
22+
* @package mod_aichat
23+
* @copyright 2025 ISB Bayern
24+
* @author Philipp Memmel
25+
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
26+
*/
27+
class hook_callbacks {
28+
/**
29+
* Provide additional information about which purposes are being used by this plugin.
30+
*
31+
* @param \local_ai_manager\hook\purpose_usage $hook the purpose_usage hook object
32+
*/
33+
public static function handle_purpose_usage(\local_ai_manager\hook\purpose_usage $hook): void {
34+
$hook->set_component_displayname('mod_aichat', get_string('pluginname_userfaced', 'mod_aichat'));
35+
$hook->add_purpose_usage_description(
36+
'chat',
37+
'mod_aichat',
38+
get_string('purposeplacedescription_mainwindow', 'block_ai_chat')
39+
);
40+
foreach (\tiny_ai\local\utils::get_purpose_placedescriptions() as $description) {
41+
$altereddescription = get_string('toolsofaibutton', 'block_ai_chat', $description['placedescription']);
42+
$hook->add_purpose_usage_description($description['purpose'], 'mod_aichat', $altereddescription);
43+
}
44+
}
45+
}

db/hooks.php

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?php
2+
// This file is part of Moodle - http://moodle.org/
3+
//
4+
// Moodle is free software: you can redistribute it and/or modify
5+
// it under the terms of the GNU General Public License as published by
6+
// the Free Software Foundation, either version 3 of the License, or
7+
// (at your option) any later version.
8+
//
9+
// Moodle is distributed in the hope that it will be useful,
10+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
// GNU General Public License for more details.
13+
//
14+
// You should have received a copy of the GNU General Public License
15+
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
16+
17+
/**
18+
* Hook listener callbacks.
19+
*
20+
* @package mod_aichat
21+
* @copyright 2025 ISB Bayern
22+
* @author Philipp Memmel
23+
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
24+
*/
25+
26+
defined('MOODLE_INTERNAL') || die();
27+
28+
$callbacks = [
29+
[
30+
'hook' => \local_ai_manager\hook\purpose_usage::class,
31+
'callback' => \mod_aichat\local\hook_callbacks::class . '::handle_purpose_usage',
32+
],
33+
];

lang/en/aichat.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@
2626
defined('MOODLE_INTERNAL') || die();
2727

2828

29-
$string['aichat:addinstance'] = 'Add an AI chat';
30-
$string['aichat:view'] = 'View the AI chat';
29+
$string['aichat:addinstance'] = 'Add an AI chat activity';
30+
$string['aichat:view'] = 'View the AI chat activity';
3131
$string['modulename'] = 'AI chat';
3232
$string['modulename_help'] = 'This activity provides the student with an AI chat bot.';
3333
$string['modulenameplural'] = 'AI chats';
@@ -36,4 +36,4 @@
3636
$string['noaichatinstance'] = 'No instance of mod_aichat could be found.';
3737
$string['pluginadministration'] = 'AI chat administration';
3838
$string['pluginname'] = 'AI chat';
39-
39+
$string['pluginname_userfaced'] = 'AI chatbot activity';

styles.css

Whitespace-only changes.

templates/embedded_modal.mustache

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,4 +54,4 @@ along with Moodle. If not, see <http://www.gnu.org/licenses/>.
5454
</div>
5555
</div>
5656
</div>
57-
</div>
57+
</div>

version.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626

2727
$plugin->component = 'mod_aichat';
2828
$plugin->release = '0.1';
29-
$plugin->version = 2025112400;
29+
$plugin->version = 2025121300;
3030
$plugin->requires = 2022112800;
3131
$plugin->supported = [501, 501];
32-
$plugin->maturity = MATURITY_STABLE;
32+
$plugin->maturity = MATURITY_BETA;

0 commit comments

Comments
 (0)