Skip to content

Commit

Permalink
code review
Browse files Browse the repository at this point in the history
  • Loading branch information
rdebleu committed Jul 30, 2022
1 parent a0bd1ce commit 5b327fc
Show file tree
Hide file tree
Showing 4 changed files with 166 additions and 5 deletions.
102 changes: 102 additions & 0 deletions .github/workflows/cron.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
name: Cron

on:
schedule:
- cron: "5 10 9 * *"

jobs:
ci:
name: ci
runs-on: ubuntu-latest

strategy:
fail-fast: false
matrix:
moodle-branch: ['master']
php: ['8.0']
database: ['mysqli']

steps:
- name: checkout plugin
uses: actions/checkout@v2
with:
path: this-plugin

- name: setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
extensions: mbstring, mysqli, gd, zip
ini-values: max_input_vars=5000
coverage: xdebug

- name: cache composer
uses: actions/cache@v2
with:
path: ~/.composer/cache/
key: composer-cache

- name: composer
run: |
composer create-project -n --no-dev --prefer-dist moodlehq/moodle-plugin-ci ci ^3
echo $(cd ci/bin; pwd) >> $GITHUB_PATH
echo $(cd ci/vendor/bin; pwd) >> $GITHUB_PATH
sudo locale-gen en_AU.UTF-8
sed -i 's/phpdbg -d memory_limit=-1 -qrr//g' ci/src/Command/PHPUnitCommand.php
sudo systemctl start mysql.service
echo "NVM_DIR=$HOME/.nvm" >> $GITHUB_ENV
- name: install Moodle
run: moodle-plugin-ci install --db-user=root --db-pass=root --db-host=127.0.0.1 --plugin this-plugin
env:
DB: ${{ matrix.database }}
MOODLE_BRANCH: ${{ matrix.moodle-branch }}

- name: phplint
if: ${{ always() }}
run: moodle-plugin-ci --ansi phplint

- name: phpcpd
if: ${{ always() }}
run: moodle-plugin-ci --ansi phpcpd

- name: phpmd
if: ${{ always() }}
run: moodle-plugin-ci --ansi phpmd

- name: phpdoc
if: ${{ always() }}
run: moodle-plugin-ci --ansi phpdoc

- name: codechecker
if: ${{ always() }}
run: moodle-plugin-ci --ansi codechecker

- name: validate
if: ${{ always() }}
run: moodle-plugin-ci --ansi validate

- name: savepoints
if: ${{ always() }}
run: moodle-plugin-ci --ansi savepoints

- name: grunt
if: ${{ always() }}
run: moodle-plugin-ci --ansi grunt

- name: mustache
if: ${{ always() }}
run: moodle-plugin-ci --ansi mustache

- name: phpunit
if: ${{ always() }}
run: moodle-plugin-ci --ansi phpunit --coverage-text --coverage-clover

- name: behat
if: ${{ always() }}
run: moodle-plugin-ci --ansi behat --profile=chrome

- name: privacy
if: ${{ always() }}
run: vendor/bin/phpunit --colors --no-coverage --testsuite tool_dataprivacy_testsuite,tool_policy_testsuite,core_privacy_testsuite
working-directory: moodle
59 changes: 59 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
name: Releasing in the Plugins directory

on:
push:
tags:
- v*

workflow_dispatch:
inputs:
tag:
description: 'Tag to be released'
required: true

defaults:
run:
shell: bash

jobs:
release-at-moodle-org:
runs-on: ubuntu-latest
env:
PLUGIN: enrol_coursecompleted
CURL: curl -s
ENDPOINT: https://moodle.org/webservice/rest/server.php
TOKEN: ${{ secrets.MOODLE_ORG_TOKEN }}
FUNCTION: local_plugins_add_version

steps:
- name: Call the service function
id: add-version
run: |
if [[ ! -z "${{ github.event.inputs.tag }}" ]]; then
TAGNAME="${{ github.event.inputs.tag }}"
elif [[ $GITHUB_REF = refs/tags/* ]]; then
TAGNAME="${GITHUB_REF##*/}"
fi
if [[ -z "${TAGNAME}" ]]; then
echo "No tag name has been provided!"
exit 1
fi
ZIPURL="https://api.github.com/repos/${{ github.repository }}/zipball/${TAGNAME}"
RESPONSE=$(${CURL} ${ENDPOINT} --data-urlencode "wstoken=${TOKEN}" \
--data-urlencode "wsfunction=${FUNCTION}" \
--data-urlencode "moodlewsrestformat=json" \
--data-urlencode "frankenstyle=${PLUGIN}" \
--data-urlencode "zipurl=${ZIPURL}" \
--data-urlencode "vcssystem=git" \
--data-urlencode "vcsrepositoryurl=${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}" \
--data-urlencode "vcstag=${TAGNAME}" \
--data-urlencode "changelogurl=${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}/commits/${TAGNAME}" \
--data-urlencode "altdownloadurl=${ZIPURL}")
echo "::set-output name=response::${RESPONSE}"
- name: Evaluate the response
id: evaluate-response
env:
RESPONSE: ${{ steps.add-version.outputs.response }}
run: |
jq <<< ${RESPONSE}
jq --exit-status ".id" <<< ${RESPONSE} > /dev/null
8 changes: 4 additions & 4 deletions lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ public function edit_instance_form($instance, MoodleQuickForm $mform, $context)
$mform->addElement('select', 'status', get_string('enabled', 'admin'), $options);
$mform->setDefault('status', $this->get_config('status'));

$role = ($instance and isset($instance->roleid)) ? $instance->roleid : $this->get_config('roleid');
$role = ($instance && isset($instance->roleid)) ? $instance->roleid : $this->get_config('roleid');
$roles = get_default_enrol_roles($context, $role);
$mform->addElement('select', 'roleid', get_string('assignrole', 'enrol_paypal'), $roles);
$mform->setDefault('roleid', $this->get_config('roleid'));
Expand All @@ -305,7 +305,7 @@ public function edit_instance_form($instance, MoodleQuickForm $mform, $context)
$mform->setDefault('enrolperiod', $this->get_config('enrolperiod'));
$mform->addHelpButton('enrolperiod', 'enrolperiod', 'enrol_paypal');

$start = ($instance and isset($instance->customint1)) ? get_course($instance->customint1)->startdate : time();
$start = ($instance && isset($instance->customint1)) ? get_course($instance->customint1)->startdate : time();
$arr = ['optional' => true, 'defaulttime' => $start];
$mform->addElement('date_time_selector', 'enrolstartdate', get_string('enrolstartdate', 'enrol_paypal'), $arr);
$mform->addHelpButton('enrolstartdate', 'enrolstartdate', 'enrol_paypal');
Expand Down Expand Up @@ -371,8 +371,8 @@ public function edit_instance_validation($data, $files, $instance, $context) {
if (!empty($data['enrolenddate']) && $data['enrolenddate'] < $data['enrolstartdate']) {
$errors['enrolenddate'] = get_string('enrolenddaterror', 'enrol_paypal');
}
if (empty($data['customint1']) or
$data['customint1'] == 1 or
if (empty($data['customint1']) ||
$data['customint1'] == 1 ||
!$DB->record_exists('course', ['id' => $data['customint1']])) {
$errors['customint'] = get_string('error_nonexistingcourse', 'tool_generator');
}
Expand Down
2 changes: 1 addition & 1 deletion manage.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
$canenrol = has_capability('enrol/coursecompleted:enrolpast', $context);
$canunenrol = has_capability('enrol/coursecompleted:unenrol', $context);

if (!$canenrol and !$canunenrol) {
if (!$canenrol && !$canunenrol) {
// No need to invent new error strings here...
require_capability('enrol/manual:enrol', $context);
}
Expand Down

0 comments on commit 5b327fc

Please sign in to comment.