Skip to content

Commit

Permalink
Merge pull request #535 from linear-b/tips-for-plugins-developers
Browse files Browse the repository at this point in the history
added tips section
  • Loading branch information
vim-zz authored Jun 16, 2024
2 parents c091a5c + f37d276 commit 32388d3
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 3 deletions.
26 changes: 25 additions & 1 deletion docs/plugins.md
Original file line number Diff line number Diff line change
Expand Up @@ -169,11 +169,35 @@ Filter function plugins can accept any number of arguments. The first argument m
}
module.exports = combineStrings;
```

In the following invocation, "Hello" is passed as `str1` and "world!" is passed as `str2`

`{{ "Hello" | combineStrings("world!") }}`

### Tips for Debugging Plugins

1. **Context Variable Insight:**
Utilize the [gitStream playground](https://app.gitstream.cm/playground) to see how the context variable appears in a real Pull Request (PR). Inspect the PR Context Variables at the bottom of the screen ![Playground](screenshots/playground-context-variables.png).



2. **Local Execution:**
- Run the plugin locally for testing, for example: Running `index.js` with Node.js.
```javascript
module.exports = (text) => {
return text.replaceAll('banana', '🍌');
};

const banana = require('./index.js');
console.assert(banana("hello banana!") === 'hello 🍌!', `banana("hello banana!") === 'hello 🍌!' but got ${banana("hello banana!")}`);
```
- Execute with:
```bash
$ node index.js
```

By following these steps, you can effectively debug and refine your gitStream plugins.

## Next Step

!!! tip "Check out the community plugin library."
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 5 additions & 2 deletions plugins/filters/banana/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,11 @@
* @example {{ pr.comment | banana }}
* @license MIT
**/
function banana(text) {


module.exports = (text) => {
return text.replaceAll('banana', '🍌');
};

module.exports = banana;
const banana = require('./index.js');
console.assert(banana("hello banana!") === 'hello 🍌!', `banana("hello banana!") === 'hello 🍌' but got ${banana("hello banana!")}`);

0 comments on commit 32388d3

Please sign in to comment.