Skip to content

Commit

Permalink
Added support for Key
Browse files Browse the repository at this point in the history
  • Loading branch information
rimi-itk committed May 3, 2024
1 parent c4707bc commit 3a96148
Show file tree
Hide file tree
Showing 15 changed files with 388 additions and 238 deletions.
25 changes: 25 additions & 0 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#### Link to ticket

Please add a link to the ticket being addressed by this change.

#### Description

Please include a short description of the suggested change and the reasoning behind the approach you have chosen.

#### Screenshot of the result

If your change affects the user interface you should include a screenshot of the result with the pull request.

#### Checklist

- [ ] My code is covered by test cases.
- [ ] My code passes our test (all our tests).
- [ ] My code passes our static analysis suite.
- [ ] My code passes our continuous integration process.

If your code does not pass all the requirements on the checklist you have to add a comment explaining why this change
should be exempt from the list.

#### Additional comments or questions

If you have any further comments or questions for the reviewer please add them here.
42 changes: 14 additions & 28 deletions .github/workflows/pr.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ jobs:
composer validate --strict composer.json
# Check that dependencies resolve.
composer update --${{ matrix.dependency-version }} --prefer-dist --no-interaction
- name: Check that composer file is normalized
run: |
composer normalize --dry-run
php-check-coding-standards:
name: PHP - Check Coding Standards
Expand Down Expand Up @@ -109,34 +112,17 @@ jobs:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
restore-keys: ${{ runner.os }}-composer-
- name: drupal-check
- name: Code analysis
run: |
# We need a Drupal project to run drupal-check (cf. https://github.com/mglaman/drupal-check#usage)
# Install Drupal
composer --no-interaction create-project drupal/recommended-project:^9 --stability=dev drupal
# Copy our module source code into the Drupal module folder.
mkdir -p drupal/web/modules/contrib/os2forms_get_organized
cp -r os2forms_get_organized.* composer.json src drupal/web/modules/contrib/os2forms_get_organized
# Add our module as a composer repository.
composer --no-interaction --working-dir=drupal config repositories.os2forms/os2forms_get_organized path web/modules/contrib/os2forms_get_organized
# Restore Drupal composer repository.
composer --no-interaction --working-dir=drupal config repositories.drupal composer https://packages.drupal.org/8
composer --no-interaction --working-dir=drupal config --no-plugins allow-plugins.cweagans/composer-patches true
composer --no-interaction --working-dir=drupal config --no-plugins allow-plugins.zaporylie/composer-drupal-optimizations true
composer --no-interaction --working-dir=drupal config --no-plugins allow-plugins.simplesamlphp/composer-module-installer true
# @see https://getcomposer.org/doc/03-cli.md#modifying-extra-values
composer --no-interaction --working-dir=drupal config --no-plugins --json extra.enable-patching true
./scripts/code-analysis
# Require our module.
composer --no-interaction --working-dir=drupal require 'os2forms/os2forms_get_organized:*'
coding-standards-markdown:
name: Markdown coding standards
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@master

# Check code
composer --no-interaction --working-dir=drupal require --dev drupal/core-dev
cd drupal/web/modules/contrib/os2forms_get_organized
# Remove our non-dev dependencies to prevent duplicated Drupal installation
# 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
# Use sed to remove the "require" property in composer.json
sed -i '/^\s*"require":/,/^\s*}/d' composer.json
composer --no-interaction install
composer code-analysis
- name: Coding standards
run: |
docker run --rm --volume $PWD:/md peterdavehello/markdownlint markdownlint --ignore vendor --ignore LICENSE.md '**/*.md'
13 changes: 13 additions & 0 deletions .markdownlint.jsonc
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"default": true,
// https://github.com/DavidAnson/markdownlint/blob/main/doc/md013.md
"line-length": {
"line_length": 120,
"code_blocks": false,
"tables": false
},
// https://github.com/DavidAnson/markdownlint/blob/main/doc/md024.md
"no-duplicate-heading": {
"siblings_only": true
}
}
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ about writing changes to this log.

## [Unreleased]

* [PR-1](https://github.com/itk-dev/os2forms_get_organized/pull/1)
Added support for os2web_key

## [1.1.5] 04.01.2024

* Disallowed `webform_entity_print_attachment:pdf` attachment element.
Expand Down
37 changes: 25 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,24 +11,37 @@ vendor/bin/drush pm:enable os2forms_get_organized

## Settings

Set GetOrganized `username`, `password` and `base url`
on `/admin/os2forms_get_organized/settings`.

You can also test that the provided
details work on `/admin/os2forms_get_organized/settings`.
Go to `/admin/os2forms_get_organized/settings` and configure the module.

## Coding standards

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

```sh
docker run --rm --interactive --tty --volume ${PWD}:/app itkdev/php8.1-fpm:latest composer install
docker run --rm --interactive --tty --volume ${PWD}:/app itkdev/php8.1-fpm:latest composer coding-standards-check
### PHP

```shell
docker run --rm --volume ${PWD}:/app --workdir /app itkdev/php8.1-fpm composer install
# Fix (some) coding standards issues
docker run --rm --volume ${PWD}:/app --workdir /app itkdev/php8.1-fpm composer coding-standards-apply
# Check that code adheres to the coding standards
docker run --rm --volume ${PWD}:/app --workdir /app itkdev/php8.1-fpm composer coding-standards-check
```

### Markdown

```shell
docker run --rm --volume $PWD:/md peterdavehello/markdownlint markdownlint --ignore vendor --ignore LICENSE.md '**/*.md' --fix
docker run --rm --volume $PWD:/md peterdavehello/markdownlint markdownlint --ignore vendor --ignore LICENSE.md '**/*.md'
```

Apply coding standards:
## Code analysis

We use [PHPStan](https://phpstan.org/) for static code analysis.

Running statis code analysis on a standalone Drupal module is a bit tricky, so we use a helper script to run the
analysis:

```shell
docker run --rm --interactive --tty --volume ${PWD}:/app itkdev/php8.1-fpm:latest composer coding-standards-apply
docker run --rm --interactive --tty --volume ${PWD}:/app node:18 yarn --cwd /app coding-standards-apply
docker run --rm --volume ${PWD}:/app --workdir /app itkdev/php8.1-fpm ./scripts/code-analysis
```
63 changes: 33 additions & 30 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,61 +1,64 @@
{
"name": "os2forms/os2forms_get_organized",
"description": "OS2Forms GetOrganized integration",
"type": "drupal-module",
"license": "MIT",
"type": "drupal-module",
"authors": [
{
"name": "Jeppe Kuhlmann Andersen",
"email": "[email protected]"
}
],
"minimum-stability": "dev",
"prefer-stable": true,
"repositories": [
{
"type": "composer",
"url": "https://packages.drupal.org/8"
}
],
"require": {
"itk-dev/getorganized-api-client-php": "^1.2",
"drupal/webform": "^6.1",
"drupal/advancedqueue": "^1.0",
"symfony/options-resolver": "^5.4",
"os2forms/os2forms": "^3.13"
"drupal/key": "^1.17",
"drupal/webform": "^6.1",
"itk-dev/getorganized-api-client-php": "^1.2",
"os2forms/os2forms": "^3.13",
"symfony/options-resolver": "^5.4"
},
"require-dev": {
"dealerdirect/phpcodesniffer-composer-installer": "^1.0",
"drupal/coder": "^8.3",
"ergebnis/composer-normalize": "^2.42",
"mglaman/drupal-check": "^1.4"
},
"repositories": [
{
"type": "composer",
"url": "https://packages.drupal.org/8"
}
],
"minimum-stability": "dev",
"prefer-stable": true,
"config": {
"allow-plugins": {
"cweagans/composer-patches": true,
"dealerdirect/phpcodesniffer-composer-installer": true,
"ergebnis/composer-normalize": true,
"simplesamlphp/composer-module-installer": true,
"zaporylie/composer-drupal-optimizations": true
}
},
"scripts": {
"code-analysis": [
"@code-analysis/drupal-check"
],
"code-analysis/drupal-check": [
"# @see https://github.com/mglaman/drupal-check/issues/261#issuecomment-1030141772 for details on exclude-dir value",
"drupal-check --deprecations --analysis --exclude-dir='vendor,*/Client/*' *.* src"
],
"code-analysis": [
"@code-analysis/drupal-check"
"coding-standards-apply": [
"@coding-standards-apply/phpcs"
],
"coding-standards-check/phpcs": [
"vendor/bin/phpcs --standard=phpcs.xml.dist"
"coding-standards-apply/phpcs": [
"vendor/bin/phpcbf --standard=phpcs.xml.dist"
],
"coding-standards-check": [
"@coding-standards-check/phpcs"
],
"coding-standards-apply/phpcs": [
"vendor/bin/phpcbf --standard=phpcs.xml.dist"
],
"coding-standards-apply": [
"@coding-standards-apply/phpcs"
"coding-standards-check/phpcs": [
"vendor/bin/phpcs --standard=phpcs.xml.dist"
]
},
"config": {
"allow-plugins": {
"dealerdirect/phpcodesniffer-composer-installer": true,
"zaporylie/composer-drupal-optimizations": true,
"cweagans/composer-patches": true,
"simplesamlphp/composer-module-installer": true
}
}
}
6 changes: 6 additions & 0 deletions drush.services.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
services:
Drupal\os2forms_get_organized\Drush\Commands\GetOrganizedTestCommands:
arguments:
- '@Drupal\os2forms_get_organized\Helper\ArchiveHelper'
tags:
- { name: drush.command }
3 changes: 2 additions & 1 deletion os2forms_get_organized.services.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
services:
Drupal\os2forms_get_organized\Helper\Settings:
arguments:
- "@keyvalue"
- "@config.factory"
- "@key.repository"

Drupal\os2forms_get_organized\Helper\ArchiveHelper:
arguments:
Expand Down
11 changes: 11 additions & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
parameters:
level: 6
paths:
- src

ignoreErrors:
- '#Unsafe usage of new static\(\).#'

# Local Variables:
# mode: yaml
# End:
48 changes: 48 additions & 0 deletions scripts/code-analysis
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#!/usr/bin/env bash
script_dir=$(pwd)
module_name=$(basename "$script_dir")
drupal_dir=vendor/drupal-module-code-analysis
# Relative to $drupal_dir
module_path=web/modules/contrib/$module_name

cd "$script_dir" || exit

drupal_composer() {
composer --working-dir="$drupal_dir" --no-interaction "$@"
}

# Create new Drupal 9 project
if [ ! -f "$drupal_dir/composer.json" ]; then
composer --no-interaction create-project drupal/recommended-project:^9 "$drupal_dir"
fi
# Copy our code into the modules folder

# Clean up
rm -fr "${drupal_dir:?}/$module_path"

# https://stackoverflow.com/a/15373763
# rsync --archive --compress . --filter=':- .gitignore' --exclude "$drupal_dir" --exclude .git "$drupal_dir/$module_path"

# The rsync command in not available in itkdev/php8.1-fpm

git config --global --add safe.directory /app
# Copy all module files not ignored by git into module path
# (cf. https://stackoverflow.com/a/77197460)
for f in $(git ls-files --cached --others --exclude-standard); do
mkdir -p "$drupal_dir/$module_path/$(dirname "$f")"
cp "$f" "$drupal_dir/$module_path/$f"
done

drupal_composer config minimum-stability dev

# Allow ALL plugins
# https://getcomposer.org/doc/06-config.md#allow-plugins
drupal_composer config --no-plugins allow-plugins true

drupal_composer require wikimedia/composer-merge-plugin
drupal_composer config extra.merge-plugin.include "$module_path/composer.json"
# https://www.drupal.org/project/drupal/issues/3220043#comment-14845434
drupal_composer require --dev symfony/phpunit-bridge

# Run PHPStan
(cd "$drupal_dir/$module_path" && ../../../../vendor/bin/phpstan)
38 changes: 38 additions & 0 deletions src/Drush/Commands/GetOrganizedTestCommands.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php

namespace Drupal\os2forms_get_organized\Drush\Commands;

use Drupal\os2forms_get_organized\Helper\ArchiveHelper;
use Drush\Commands\DrushCommands;

/**
* Test commands for get organized.
*/
class GetOrganizedTestCommands extends DrushCommands {

/**
* Constructor.
*/
public function __construct(
private readonly ArchiveHelper $helper,
) {
}

/**
* Test API access.
*
* @command os2forms-get-organized:test:api
* @usage os2forms-get-organized:test:api --help
*/
public function testApi(): void {
try {
$this->helper->pingApi();
$this->io()->success('Successfully connected to Get Organized API');
}
catch (\Throwable $t) {
$this->io()->error($t->getMessage());
}

}

}
Loading

0 comments on commit 3a96148

Please sign in to comment.