Skip to content

Commit 4336303

Browse files
committed
Added support for Key
1 parent c4707bc commit 4336303

17 files changed

+408
-213
lines changed

.github/PULL_REQUEST_TEMPLATE.md

+25
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

+14
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
@@ -140,3 +143,14 @@ jobs:
140143
sed -i '/^\s*"require":/,/^\s*}/d' composer.json
141144
composer --no-interaction install
142145
composer code-analysis
146+
147+
coding-standards-markdown:
148+
name: Markdown coding standards
149+
runs-on: ubuntu-latest
150+
steps:
151+
- name: Checkout
152+
uses: actions/checkout@master
153+
154+
- name: Coding standards
155+
run: |
156+
docker run --rm --volume $PWD:/md peterdavehello/markdownlint markdownlint --ignore vendor --ignore LICENSE.md '**/*.md'

.markdownlint.jsonc

+13
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+
}

CHANGELOG.md

+3
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ about writing changes to this log.
88

99
## [Unreleased]
1010

11+
* [PR-1](https://github.com/itk-dev/os2forms_get_organized/pull/1)
12+
Added support for os2web_key
13+
1114
## [1.1.5] 04.01.2024
1215

1316
* Disallowed `webform_entity_print_attachment:pdf` attachment element.

README.md

+25-12
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

+33-30
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": "[email protected]"
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

+6
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.info.yml

+3-1
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@ description: 'GetOrganized integration'
44
package: OS2Forms
55
core_version_requirement: ^9
66
dependencies:
7-
- drupal:webform
87
- drupal:advancedqueue
8+
- drupal:key
9+
- drupal:webform
910
- drupal:webform_entity_print_attachment
1011
- os2forms:os2forms_attachment
12+
1113
configure: os2forms_get_organized.admin.settings

os2forms_get_organized.install

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?php
2+
3+
/**
4+
* @file
5+
* Install hooks for os2forms_get_organized.
6+
*/
7+
8+
/**
9+
* Implements hook_update_N().
10+
*/
11+
function os2forms_get_organized_update_9001(): void {
12+
\Drupal::service('module_installer')->install([
13+
'key',
14+
], TRUE);
15+
}

os2forms_get_organized.services.yml

+2-1
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

+11
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

+48
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)
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)