Skip to content

Commit 06b569c

Browse files
authored
Merge pull request #11 from badasswp/release-1.2.0
Release 1.2.0
2 parents 2711a89 + 4371ae2 commit 06b569c

32 files changed

+1163
-852
lines changed

.deployignore

+4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
.babelrc
22
.editorconfig
3+
.eslintignore
4+
.eslintrc.js
35
.gitignore
46
.github
7+
.wp-env.json
58
CHANGELOG.md
69
jest.config.js
710
jest.setup.js
@@ -14,6 +17,7 @@ phpstan.neon
1417
src
1518
assets
1619
tests
20+
bin
1721
vendor/orhanerday/open-ai/files/assistant-file.txt
1822
vendor/orhanerday/open-ai/files/en-marvel-endgame.m4a
1923
vendor/orhanerday/open-ai/files/sample_file_1.jsonl

.editorconfig

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,4 @@ trim_trailing_whitespace = true
1010

1111
[*.{js,jsx,ts,tsx,json,yml,yaml,babelrc,md}]
1212
indent_size = 2
13-
indent_style = space
13+
indent_style = tab

.eslintignore

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
node_modules/
2+
vendor/
3+
build/
4+
dist/

.eslintrc.js

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
module.exports = {
2+
root: true,
3+
extends: [ 'plugin:@wordpress/recommended' ],
4+
rules: {
5+
'import/no-extraneous-dependencies': 'off',
6+
},
7+
};

.github/workflows/ci.yml

+11-3
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,13 @@ jobs:
2323
run: |
2424
yarn install
2525
26-
- name: Run JS Tests
26+
- name: Check JS Linting
2727
run: |
28-
yarn test
28+
yarn lint:js
29+
30+
- name: Run JS Unit Tests
31+
run: |
32+
yarn test:js
2933
3034
- name: Set up PHP v8.2
3135
uses: shivammathur/setup-php@v2
@@ -40,6 +44,10 @@ jobs:
4044
run: |
4145
composer install --prefer-dist --no-progress
4246
43-
- name: Run Linting
47+
- name: Check PHP Linting
4448
run: |
4549
composer run lint
50+
51+
- name: Run PHP Unit Tests
52+
run: |
53+
composer run test

.wp-env.json

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"plugins": [
3+
"."
4+
],
5+
"phpVersion": "8.2",
6+
"port": 5487,
7+
"testsPort": 5488,
8+
"config": {
9+
"WP_SITEURL": "http://apbe.localhost",
10+
"WP_HOME": "http://apbe.localhost"
11+
},
12+
"lifecycleScripts": {
13+
"afterStart": "./bin/setup.sh"
14+
}
15+
}

CHANGELOG.md

+8
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
# Changelog
22

3+
## 1.2.0
4+
* Feat: Add local development environment setup.
5+
* Fix: Gracefully deal with WP REST error responses.
6+
* Fix: AI sidebar feature save buttons not working correctly.
7+
* Fix: Deal with the issue of super-imposed notices.
8+
* Chore: Enforce WP linting style across plugin.
9+
* Tested up to WP 6.7.2.
10+
311
## 1.1.2
412
* Refactor: AI client instance, make interchangeable.
513
* Fix: Minor syntax typos.

README.md

+29
Original file line numberDiff line numberDiff line change
@@ -164,3 +164,32 @@ public function custom_route( $rest_routes ) {
164164
- rest_routes _`{array}`_ By default this will be an array containing the plugin's REST routes.
165165
<br/>
166166

167+
---
168+
169+
## Contribute
170+
171+
Contributions are __welcome__ and will be fully __credited__. To contribute, please fork this repo and raise a PR (Pull Request) against the `master` branch.
172+
173+
### Pre-requisites
174+
175+
You should have the following tools before proceeding to the next steps:
176+
177+
- Composer
178+
- Yarn
179+
- Docker
180+
181+
To enable you start development, please run:
182+
183+
```bash
184+
yarn start
185+
```
186+
187+
This should spin up a local WP env instance for you to work with at:
188+
189+
```bash
190+
http://apbe.localhost:5487
191+
```
192+
193+
You should now have a functioning local WP env to work with. To login to the `wp-admin` backend, please username as `admin` & password as `password`.
194+
195+
__Awesome!__ - Thanks for being interested in contributing your time and code to this project!

ai-plus-block-editor.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* Plugin Name: AI + Block Editor
44
* Plugin URI: https://github.com/badasswp/ai-plus-block-editor
55
* Description: Add AI Capabilities to the WP Block Editor.
6-
* Version: 1.1.2
6+
* Version: 1.2.0
77
* Author: badasswp
88
* Author URI: https://github.com/badasswp
99
* License: GPL v2 or later

bin/setup.sh

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/bin/bash
2+
3+
wp-env run cli wp theme activate twentytwentythree
4+
wp-env run cli wp rewrite structure /%postname%

inc/Providers/OpenAI.php

+25-16
Original file line numberDiff line numberDiff line change
@@ -62,33 +62,42 @@ public function run( $payload ) {
6262
$this->get_default_args()
6363
)
6464
);
65+
66+
$response = json_decode( $response, true );
67+
68+
// Deal gracefully, with API error.
69+
if ( isset( $response['error'] ) ) {
70+
return $this->get_json_error( $response['error']['message'] ?? '' );
71+
}
6572
} catch ( \Exception $e ) {
6673
$error_msg = sprintf(
6774
'Error: OpenAI API call failed... %s',
6875
$e->getMessage()
6976
);
7077

71-
error_log( $error_msg );
72-
73-
// Deal gracefully, with error.
74-
return new \WP_Error(
75-
'ai-plus-block-editor-open-ai-error',
76-
$error_msg,
77-
[ 'status' => 500 ]
78-
);
78+
return $this->get_json_error( $error_msg );
7979
}
8080

81-
$response = json_decode( $response, true );
82-
83-
// Deal gracefully, with error.
8481
if ( is_null( $response ) ) {
85-
return new \WP_Error(
86-
'ai-plus-block-editor-json-error',
87-
'Error: Malformed JSON output.',
88-
[ 'status' => 500 ]
89-
);
82+
return $this->get_json_error( 'Error: Malformed JSON output.' );
9083
}
9184

9285
return $response['choices'][0]['message']['content'] ?? '';
9386
}
87+
88+
/**
89+
* Get JSON Error.
90+
*
91+
* @since 1.0.0
92+
*
93+
* @param string $message Error Message.
94+
* @return \WP_Error
95+
*/
96+
protected function get_json_error( $message ) {
97+
return new \WP_Error(
98+
'ai-plus-block-editor-json-error',
99+
$message,
100+
[ 'status' => 500 ]
101+
);
102+
}
94103
}

jest.config.js

+4-6
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,14 @@
1-
const baseConfig = require('@wordpress/scripts/config/jest-unit.config.js');
1+
const baseConfig = require( '@wordpress/scripts/config/jest-unit.config.js' );
22

33
module.exports = {
44
...baseConfig,
55
preset: 'ts-jest',
66
testEnvironment: 'jsdom',
7-
setupFilesAfterEnv: [
8-
'./jest.setup.js'
9-
],
7+
setupFilesAfterEnv: [ './jest.setup.js' ],
108
transform: {
119
'^.+\\.jsx?$': 'babel-jest',
1210
},
1311
moduleNameMapper: {
14-
'uuid': require.resolve('uuid'),
12+
uuid: require.resolve( 'uuid' ),
1513
},
16-
};
14+
};

jest.setup.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
import '@testing-library/jest-dom';
22
import '@testing-library/jest-dom/extend-expect.js';
3-
import '@wordpress/jest-preset-default/scripts/setup-globals';
3+
import '@wordpress/jest-preset-default/scripts/setup-globals';

package.json

+16-5
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,26 @@
11
{
22
"name": "ai-plus-block-editor",
3-
"version": "1.1.2",
3+
"version": "1.2.0",
44
"description": "Add AI Capabilities to the Block Editor.",
55
"author": "badasswp",
66
"license": "GPL-2.0-or-later",
77
"homepage": "https://github.com/badasswp/ai-plus-block-editor#readme",
88
"scripts": {
9-
"start": "npm install && composer install",
10-
"dev": "webpack --watch",
9+
"start": "yarn boot && yarn build && yarn wp-env start",
10+
"stop": "yarn wp-env stop",
11+
"watch": "webpack --watch",
1112
"build": "webpack",
13+
"boot": "composer install && yarn install",
1214
"test": "npm-run-all --parallel test:*",
13-
"test:js": "jest --passWithNoTests"
15+
"test:js": "jest --passWithNoTests",
16+
"test:php": "composer run test",
17+
"lint:js": "eslint . --ext .js,.jsx,.ts,.tsx",
18+
"lint:js:fix": "eslint . --ext .js,.jsx,.ts,.tsx --fix",
19+
"lint:php": "composer run lint",
20+
"lint:php:fix": "composer run lint:fix",
21+
"ci": "yarn test:js && yarn lint:js && yarn test:php && yarn lint:php",
22+
"wp-env": "wp-env",
23+
"bash": "wp-env run cli bash"
1424
},
1525
"devDependencies": {
1626
"@babel/core": "^7.22.11",
@@ -21,7 +31,8 @@
2131
"@testing-library/jest-dom": "5.17",
2232
"@testing-library/react": "15.0.6",
2333
"@types/jest": "^29.5.4",
24-
"@wordpress/eslint-plugin": "^15.0.0",
34+
"@wordpress/env": "^10.20.0",
35+
"@wordpress/eslint-plugin": "^22.6.0",
2536
"@wordpress/scripts": "^26.9.0",
2637
"css-loader": "^6.8.1",
2738
"file-loader": "^6.2.0",

phpcs.xml

+2-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
1212
<arg name="colors" />
1313
<file>.</file>
1414

15+
<exclude-pattern>/dist/</exclude-pattern>
1516
<exclude-pattern>/vendor/</exclude-pattern>
1617
<exclude-pattern>/languages/</exclude-pattern>
1718
<exclude-pattern>/node_modules/</exclude-pattern>
18-
</ruleset>
19+
</ruleset>

readme.txt

+9-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ Contributors: badasswp
33
Tags: ai, block, editor, chat-gpt, assistant.
44
Requires at least: 6.0
55
Tested up to: 6.7.1
6-
Stable tag: 1.1.2
6+
Stable tag: 1.2.0
77
Requires PHP: 7.4
88
License: GPLv2 or later
99
License URI: http://www.gnu.org/licenses/gpl-2.0.html
@@ -67,6 +67,14 @@ Want to add your personal touch? All of our documentation can be found [here](ht
6767

6868
== Changelog ==
6969

70+
= 1.2.0 =
71+
* Feat: Add local development environment setup.
72+
* Fix: Gracefully deal with WP REST error responses.
73+
* Fix: AI sidebar feature save buttons not working correctly.
74+
* Fix: Deal with the issue of super-imposed notices.
75+
* Chore: Enforce WP linting style across plugin.
76+
* Tested up to WP 6.7.2.
77+
7078
= 1.1.2 =
7179
* Refactor: AI client instance, make interchangeable.
7280
* Fix: Minor syntax typos.

0 commit comments

Comments
 (0)