Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
11 changes: 11 additions & 0 deletions .github/workflows/pr.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -176,3 +176,14 @@ jobs:
sed -i '/^\s*"require":/,/^\s*}/d' composer.json
composer --no-interaction install
composer code-analysis

coding-standards-markdown:
name: Markdown coding standards
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@master

- 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
}
}
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ about writing changes to this log.

## [Unreleased]

* [PR-14](https://github.com/OS2Forms/os2forms_get_organized/pull/14)
Added support for [Key](https://www.drupal.org/project/key)
* [PR-22](https://github.com/OS2Forms/os2forms_get_organized/pull/22)
Normalized `composer.json`

Expand Down
39 changes: 27 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,24 +11,39 @@ 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
# Update to make sure that we use the latest versions of tools.
docker run --rm --volume ${PWD}:/app --workdir /app itkdev/php8.3-fpm composer update
# Fix (some) coding standards issues
docker run --rm --volume ${PWD}:/app --workdir /app itkdev/php8.3-fpm composer coding-standards-apply
# Check that code adheres to the coding standards
docker run --rm --volume ${PWD}:/app --workdir /app itkdev/php8.3-fpm composer coding-standards-check
```

### Markdown

```shell
docker pull peterdavehello/markdownlint
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.3-fpm ./scripts/code-analysis
```
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
],
"require": {
"drupal/advancedqueue": "^1.2",
"drupal/key": "^1.20",
"drupal/webform": "^6.2",
"itk-dev/getorganized-api-client-php": "^1.2.2",
"os2forms/os2forms": "^3.17 || ^4.0",
Expand Down
9 changes: 7 additions & 2 deletions drush.services.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
services:
drush_command_example.commands:
class: \Drupal\os2forms_get_organized\Commands\ArchiveCommands
Drupal\os2forms_get_organized\Commands\ArchiveCommands:
arguments:
- '@Drupal\os2forms_get_organized\Helper\ArchiveHelper'
tags:
- { name: drush.command }

Drupal\os2forms_get_organized\Drush\Commands\GetOrganizedTestCommands:
arguments:
- '@Drupal\os2forms_get_organized\Helper\ArchiveHelper'
tags:
- { name: drush.command }
4 changes: 3 additions & 1 deletion os2forms_get_organized.info.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@ description: 'GetOrganized integration'
package: OS2Forms
core_version_requirement: ^9 || ^10
dependencies:
- drupal:webform
- drupal:advancedqueue
- drupal:key
- drupal:webform
- drupal:webform_entity_print_attachment
- os2forms:os2forms_attachment
- os2web:os2web_audit

configure: os2forms_get_organized.admin.settings
15 changes: 15 additions & 0 deletions os2forms_get_organized.install
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

/**
* @file
* Install hooks for os2forms_get_organized.
*/

/**
* Implements hook_update_N().
*/
function os2forms_get_organized_update_9001(): void {
\Drupal::service('module_installer')->install([
'key',
], TRUE);
}
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
Loading