Skip to content

Commit 5443b2e

Browse files
committed
Added support for os2web_key
1 parent c4707bc commit 5443b2e

File tree

14 files changed

+385
-238
lines changed

14 files changed

+385
-238
lines changed

.github/PULL_REQUEST_TEMPLATE.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#### Link to ticket
2+
3+
Please add a link to the ticket being addressed by this change.
4+
5+
#### Description
6+
7+
Please include a short description of the suggested change and the reasoning behind the approach you have chosen.
8+
9+
#### Screenshot of the result
10+
11+
If your change affects the user interface you should include a screenshot of the result with the pull request.
12+
13+
#### Checklist
14+
15+
- [ ] My code is covered by test cases.
16+
- [ ] My code passes our test (all our tests).
17+
- [ ] My code passes our static analysis suite.
18+
- [ ] My code passes our continuous integration process.
19+
20+
If your code does not pass all the requirements on the checklist you have to add a comment explaining why this change
21+
should be exempt from the list.
22+
23+
#### Additional comments or questions
24+
25+
If you have any further comments or questions for the reviewer please add them here.

.github/workflows/pr.yaml

Lines changed: 14 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,9 @@ jobs:
4949
composer validate --strict composer.json
5050
# Check that dependencies resolve.
5151
composer update --${{ matrix.dependency-version }} --prefer-dist --no-interaction
52+
- name: Check that composer file is normalized
53+
run: |
54+
composer normalize --dry-run
5255
5356
php-check-coding-standards:
5457
name: PHP - Check Coding Standards
@@ -109,34 +112,17 @@ jobs:
109112
path: ${{ steps.composer-cache.outputs.dir }}
110113
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
111114
restore-keys: ${{ runner.os }}-composer-
112-
- name: drupal-check
115+
- name: Code analysis
113116
run: |
114-
# We need a Drupal project to run drupal-check (cf. https://github.com/mglaman/drupal-check#usage)
115-
# Install Drupal
116-
composer --no-interaction create-project drupal/recommended-project:^9 --stability=dev drupal
117-
# Copy our module source code into the Drupal module folder.
118-
mkdir -p drupal/web/modules/contrib/os2forms_get_organized
119-
cp -r os2forms_get_organized.* composer.json src drupal/web/modules/contrib/os2forms_get_organized
120-
# Add our module as a composer repository.
121-
composer --no-interaction --working-dir=drupal config repositories.os2forms/os2forms_get_organized path web/modules/contrib/os2forms_get_organized
122-
# Restore Drupal composer repository.
123-
composer --no-interaction --working-dir=drupal config repositories.drupal composer https://packages.drupal.org/8
124-
125-
composer --no-interaction --working-dir=drupal config --no-plugins allow-plugins.cweagans/composer-patches true
126-
composer --no-interaction --working-dir=drupal config --no-plugins allow-plugins.zaporylie/composer-drupal-optimizations true
127-
composer --no-interaction --working-dir=drupal config --no-plugins allow-plugins.simplesamlphp/composer-module-installer true
128-
# @see https://getcomposer.org/doc/03-cli.md#modifying-extra-values
129-
composer --no-interaction --working-dir=drupal config --no-plugins --json extra.enable-patching true
117+
./scripts/code-analysis
130118
131-
# Require our module.
132-
composer --no-interaction --working-dir=drupal require 'os2forms/os2forms_get_organized:*'
119+
coding-standards-markdown:
120+
name: Markdown coding standards
121+
runs-on: ubuntu-latest
122+
steps:
123+
- name: Checkout
124+
uses: actions/checkout@master
133125

134-
# Check code
135-
composer --no-interaction --working-dir=drupal require --dev drupal/core-dev
136-
cd drupal/web/modules/contrib/os2forms_get_organized
137-
# Remove our non-dev dependencies to prevent duplicated Drupal installation
138-
# PHP Fatal error: Cannot redeclare drupal_get_filename() (previously declared in /home/runner/work/os2forms_get_organized/os2forms_get_organized/drupal/web/modules/contrib/os2forms_get_organized/vendor/drupal/core/includes/bootstrap.inc:190) in /home/runner/work/os2forms_get_organized/os2forms_get_organized/drupal/web/core/includes/bootstrap.inc on line 190
139-
# Use sed to remove the "require" property in composer.json
140-
sed -i '/^\s*"require":/,/^\s*}/d' composer.json
141-
composer --no-interaction install
142-
composer code-analysis
126+
- name: Coding standards
127+
run: |
128+
docker run --rm --volume $PWD:/md peterdavehello/markdownlint markdownlint --ignore vendor --ignore LICENSE.md '**/*.md'

.markdownlint.jsonc

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"default": true,
3+
// https://github.com/DavidAnson/markdownlint/blob/main/doc/md013.md
4+
"line-length": {
5+
"line_length": 120,
6+
"code_blocks": false,
7+
"tables": false
8+
},
9+
// https://github.com/DavidAnson/markdownlint/blob/main/doc/md024.md
10+
"no-duplicate-heading": {
11+
"siblings_only": true
12+
}
13+
}

README.md

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,24 +11,37 @@ vendor/bin/drush pm:enable os2forms_get_organized
1111

1212
## Settings
1313

14-
Set GetOrganized `username`, `password` and `base url`
15-
on `/admin/os2forms_get_organized/settings`.
16-
17-
You can also test that the provided
18-
details work on `/admin/os2forms_get_organized/settings`.
14+
Go to `/admin/os2forms_get_organized/settings` and configure the module.
1915

2016
## Coding standards
2117

22-
Check coding standards:
18+
Our coding are checked by GitHub Actions (cf. [.github/workflows/pr.yml](.github/workflows/pr.yml)). Use the commands
19+
below to run the checks locally.
2320

24-
```sh
25-
docker run --rm --interactive --tty --volume ${PWD}:/app itkdev/php8.1-fpm:latest composer install
26-
docker run --rm --interactive --tty --volume ${PWD}:/app itkdev/php8.1-fpm:latest composer coding-standards-check
21+
### PHP
22+
23+
```shell
24+
docker run --rm --volume ${PWD}:/app --workdir /app itkdev/php8.1-fpm composer install
25+
# Fix (some) coding standards issues
26+
docker run --rm --volume ${PWD}:/app --workdir /app itkdev/php8.1-fpm composer coding-standards-apply
27+
# Check that code adheres to the coding standards
28+
docker run --rm --volume ${PWD}:/app --workdir /app itkdev/php8.1-fpm composer coding-standards-check
29+
```
30+
31+
### Markdown
32+
33+
```shell
34+
docker run --rm --volume $PWD:/md peterdavehello/markdownlint markdownlint --ignore vendor --ignore LICENSE.md '**/*.md' --fix
35+
docker run --rm --volume $PWD:/md peterdavehello/markdownlint markdownlint --ignore vendor --ignore LICENSE.md '**/*.md'
2736
```
2837

29-
Apply coding standards:
38+
## Code analysis
39+
40+
We use [PHPStan](https://phpstan.org/) for static code analysis.
41+
42+
Running statis code analysis on a standalone Drupal module is a bit tricky, so we use a helper script to run the
43+
analysis:
3044

3145
```shell
32-
docker run --rm --interactive --tty --volume ${PWD}:/app itkdev/php8.1-fpm:latest composer coding-standards-apply
33-
docker run --rm --interactive --tty --volume ${PWD}:/app node:18 yarn --cwd /app coding-standards-apply
46+
docker run --rm --volume ${PWD}:/app --workdir /app itkdev/php8.1-fpm ./scripts/code-analysis
3447
```

composer.json

Lines changed: 33 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,61 +1,64 @@
11
{
22
"name": "os2forms/os2forms_get_organized",
33
"description": "OS2Forms GetOrganized integration",
4-
"type": "drupal-module",
54
"license": "MIT",
5+
"type": "drupal-module",
66
"authors": [
77
{
88
"name": "Jeppe Kuhlmann Andersen",
99
"email": "jekua@aarhus.dk"
1010
}
1111
],
12-
"minimum-stability": "dev",
13-
"prefer-stable": true,
14-
"repositories": [
15-
{
16-
"type": "composer",
17-
"url": "https://packages.drupal.org/8"
18-
}
19-
],
2012
"require": {
21-
"itk-dev/getorganized-api-client-php": "^1.2",
22-
"drupal/webform": "^6.1",
2313
"drupal/advancedqueue": "^1.0",
24-
"symfony/options-resolver": "^5.4",
25-
"os2forms/os2forms": "^3.13"
14+
"drupal/key": "^1.17",
15+
"drupal/webform": "^6.1",
16+
"itk-dev/getorganized-api-client-php": "^1.2",
17+
"os2forms/os2forms": "^3.13",
18+
"symfony/options-resolver": "^5.4"
2619
},
2720
"require-dev": {
2821
"dealerdirect/phpcodesniffer-composer-installer": "^1.0",
2922
"drupal/coder": "^8.3",
23+
"ergebnis/composer-normalize": "^2.42",
3024
"mglaman/drupal-check": "^1.4"
3125
},
26+
"repositories": [
27+
{
28+
"type": "composer",
29+
"url": "https://packages.drupal.org/8"
30+
}
31+
],
32+
"minimum-stability": "dev",
33+
"prefer-stable": true,
34+
"config": {
35+
"allow-plugins": {
36+
"cweagans/composer-patches": true,
37+
"dealerdirect/phpcodesniffer-composer-installer": true,
38+
"ergebnis/composer-normalize": true,
39+
"simplesamlphp/composer-module-installer": true,
40+
"zaporylie/composer-drupal-optimizations": true
41+
}
42+
},
3243
"scripts": {
44+
"code-analysis": [
45+
"@code-analysis/drupal-check"
46+
],
3347
"code-analysis/drupal-check": [
3448
"# @see https://github.com/mglaman/drupal-check/issues/261#issuecomment-1030141772 for details on exclude-dir value",
3549
"drupal-check --deprecations --analysis --exclude-dir='vendor,*/Client/*' *.* src"
3650
],
37-
"code-analysis": [
38-
"@code-analysis/drupal-check"
51+
"coding-standards-apply": [
52+
"@coding-standards-apply/phpcs"
3953
],
40-
"coding-standards-check/phpcs": [
41-
"vendor/bin/phpcs --standard=phpcs.xml.dist"
54+
"coding-standards-apply/phpcs": [
55+
"vendor/bin/phpcbf --standard=phpcs.xml.dist"
4256
],
4357
"coding-standards-check": [
4458
"@coding-standards-check/phpcs"
4559
],
46-
"coding-standards-apply/phpcs": [
47-
"vendor/bin/phpcbf --standard=phpcs.xml.dist"
48-
],
49-
"coding-standards-apply": [
50-
"@coding-standards-apply/phpcs"
60+
"coding-standards-check/phpcs": [
61+
"vendor/bin/phpcs --standard=phpcs.xml.dist"
5162
]
52-
},
53-
"config": {
54-
"allow-plugins": {
55-
"dealerdirect/phpcodesniffer-composer-installer": true,
56-
"zaporylie/composer-drupal-optimizations": true,
57-
"cweagans/composer-patches": true,
58-
"simplesamlphp/composer-module-installer": true
59-
}
6063
}
6164
}

drush.services.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
services:
2+
Drupal\os2forms_get_organized\Drush\Commands\GetOrganizedTestCommands:
3+
arguments:
4+
- '@Drupal\os2forms_get_organized\Helper\ArchiveHelper'
5+
tags:
6+
- { name: drush.command }

os2forms_get_organized.services.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
services:
22
Drupal\os2forms_get_organized\Helper\Settings:
33
arguments:
4-
- "@keyvalue"
4+
- "@config.factory"
5+
- "@key.repository"
56

67
Drupal\os2forms_get_organized\Helper\ArchiveHelper:
78
arguments:

phpstan.neon

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
parameters:
2+
level: 6
3+
paths:
4+
- src
5+
6+
ignoreErrors:
7+
- '#Unsafe usage of new static\(\).#'
8+
9+
# Local Variables:
10+
# mode: yaml
11+
# End:

scripts/code-analysis

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
#!/usr/bin/env bash
2+
script_dir=$(pwd)
3+
module_name=$(basename "$script_dir")
4+
drupal_dir=vendor/drupal-module-code-analysis
5+
# Relative to $drupal_dir
6+
module_path=web/modules/contrib/$module_name
7+
8+
cd "$script_dir" || exit
9+
10+
drupal_composer() {
11+
composer --working-dir="$drupal_dir" --no-interaction "$@"
12+
}
13+
14+
# Create new Drupal 9 project
15+
if [ ! -f "$drupal_dir/composer.json" ]; then
16+
composer --no-interaction create-project drupal/recommended-project:^9 "$drupal_dir"
17+
fi
18+
# Copy our code into the modules folder
19+
20+
# Clean up
21+
rm -fr "${drupal_dir:?}/$module_path"
22+
23+
# https://stackoverflow.com/a/15373763
24+
# rsync --archive --compress . --filter=':- .gitignore' --exclude "$drupal_dir" --exclude .git "$drupal_dir/$module_path"
25+
26+
# The rsync command in not available in itkdev/php8.1-fpm
27+
28+
git config --global --add safe.directory /app
29+
# Copy all module files not ignored by git into module path
30+
# (cf. https://stackoverflow.com/a/77197460)
31+
for f in $(git ls-files --cached --others --exclude-standard); do
32+
mkdir -p "$drupal_dir/$module_path/$(dirname "$f")"
33+
cp "$f" "$drupal_dir/$module_path/$f"
34+
done
35+
36+
drupal_composer config minimum-stability dev
37+
38+
# Allow ALL plugins
39+
# https://getcomposer.org/doc/06-config.md#allow-plugins
40+
drupal_composer config --no-plugins allow-plugins true
41+
42+
drupal_composer require wikimedia/composer-merge-plugin
43+
drupal_composer config extra.merge-plugin.include "$module_path/composer.json"
44+
# https://www.drupal.org/project/drupal/issues/3220043#comment-14845434
45+
drupal_composer require --dev symfony/phpunit-bridge
46+
47+
# Run PHPStan
48+
(cd "$drupal_dir/$module_path" && ../../../../vendor/bin/phpstan)
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<?php
2+
3+
namespace Drupal\os2forms_get_organized\Drush\Commands;
4+
5+
use Drupal\os2forms_get_organized\Helper\ArchiveHelper;
6+
use Drush\Commands\DrushCommands;
7+
8+
/**
9+
* Test commands for get organized.
10+
*/
11+
class GetOrganizedTestCommands extends DrushCommands {
12+
13+
/**
14+
* Constructor.
15+
*/
16+
public function __construct(
17+
private readonly ArchiveHelper $helper,
18+
) {
19+
}
20+
21+
/**
22+
* Test API access.
23+
*
24+
* @command os2forms-get-organized:test:api
25+
* @usage os2forms-get-organized:test:api --help
26+
*/
27+
public function testApi(): void {
28+
try {
29+
$this->helper->pingApi();
30+
$this->io()->success('Successfully connected to Get Organized API');
31+
}
32+
catch (\Throwable $t) {
33+
$this->io()->error($t->getMessage());
34+
}
35+
36+
}
37+
38+
}

0 commit comments

Comments
 (0)