Skip to content

Commit b7d085e

Browse files
feat(lookup): add lookup plugin for stable branch of Moodle version
1 parent 7cbf300 commit b7d085e

File tree

4 files changed

+80
-4
lines changed

4 files changed

+80
-4
lines changed

galaxy.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ namespace: geoffreyvanwyk
1010
name: moodle
1111

1212
# The version of the collection. Must be compatible with semantic versioning
13-
version: 1.0.0
13+
version: 1.1.0
1414

1515
# The path to the Markdown (.md) readme file. This path is relative to the root
1616
# of the collection

plugins/lookup/php_version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
DOCUMENTATION = """
2626
name: php_version
2727
author: Geoffrey Bernardo van Wyk (https://geoffreyvanwyk.dev)
28-
version_added: "1.0.0"
28+
version_added: 1.0.0
2929
short_description: Latest PHP version compatible with given Moodle version
3030
description:
3131
- This lookup plugin retrieves the latest PHP version that is compatible with

plugins/lookup/plugin_directory.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,12 @@
2020
# based on the frankenstyle name of the plugin.
2121
#
2222
# @copyright 2024 Geoffrey Bernardo van Wyk {@link https://geoffreyvanwyk.dev}
23-
# @link https://moodledev.io/general/releases
2423
##
2524

2625
DOCUMENTATION = """
2726
name: plugin_directory
2827
author: Geoffrey Bernardo van Wyk (https://geoffreyvanwyk.dev)
29-
version_added: "1.0.0"
28+
version_added: 1.0.0
3029
short_description: Path to plugin installation directory
3130
description:
3231
- This lookup plugin retrieves the path to a Moodle plugin's installation

plugins/lookup/stable_branch.py

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
# This file is part of Ansible collection geoffreyvanwyk.moodle.
2+
#
3+
# Ansible collection geoffreyvanwyk.moodle is free software: you can redistribute it
4+
# and/or modify it under the terms of the GNU General Public License as
5+
# published by the Free Software Foundation, either version 3 of the License, or
6+
# (at your option) any later version.
7+
#
8+
# Ansible collection geoffreyvanwyk.moodle is distributed in the hope that it will be
9+
# useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
10+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
11+
# Public License for more details.
12+
#
13+
# You should have received a copy of the GNU General Public License along with
14+
# Ansible collection geoffreyvanwyk.moodle. If not, see
15+
# <https://www.gnu.org/licenses/>.
16+
17+
##
18+
# Ansible lookup plugin that retrieves the name of the stable Git branch that
19+
# corresponds to the given Moodle major version.
20+
#
21+
# @copyright 2024 Geoffrey Bernardo van Wyk {@link https://geoffreyvanwyk.dev}
22+
# @link https://github.com/moodle/moodle
23+
##
24+
25+
DOCUMENTATION = """
26+
name: stable_branch
27+
author: Geoffrey Bernardo van Wyk (https://geoffreyvanwyk.dev)
28+
version_added: 1.1.0
29+
short_description: Stable branch for Moodle version
30+
description:
31+
- This lookup plugin retrieves the name of the stable Git branch that
32+
corresponds to the given Moodle version.
33+
- The Git branch is in Moodle's repository on GitHub (https://github.com/moodle/moodle).
34+
options:
35+
moodle_version:
36+
description:
37+
- The human-readable version of Moodle in the format x.y, where x is a
38+
single-digit number and y is a single or double-digit number.
39+
type: str
40+
required: true
41+
"""
42+
43+
EXAMPLE = """
44+
- name: Find stable branch for major Moodle version
45+
ansible.builtin.debug:
46+
msg: lookup('geoffreyvanwyk.moodle.stable_branch', moodle_version="3.11")
47+
"""
48+
49+
RETURN = """
50+
_raw:
51+
description:
52+
- A single-element list containing the name of a stable Git branch, e.g. V(['MOODLE_311_STABLE']).
53+
type: list
54+
elements: str
55+
"""
56+
57+
from ansible.errors import AnsibleLookupError
58+
from ansible.plugins.lookup import LookupBase
59+
60+
61+
class LookupModule(LookupBase):
62+
def run(self, terms, variables=None, **kwargs):
63+
self.set_options(var_options=variables, direct=kwargs)
64+
moodle_version = str(self.get_option("moodle_version"))
65+
major_version, minor_version = moodle_version.split(".", maxsplit=1)
66+
67+
if len(major_version) != 1:
68+
raise AnsibleLookupError("Invalid moodle_version")
69+
70+
if len(minor_version) not in [1, 2]:
71+
raise AnsibleLookupError("Invalid moodle_version")
72+
73+
branch_number = major_version + (
74+
minor_version if len(minor_version) == 2 else "0" + minor_version
75+
)
76+
77+
return ["MOODLE_" + branch_number + "_STABLE"]

0 commit comments

Comments
 (0)