Skip to content

Commit 76440a6

Browse files
authored
docs: Add how to contribute a built-in function
1 parent d115ad9 commit 76440a6

File tree

1 file changed

+37
-3
lines changed

1 file changed

+37
-3
lines changed

CONTRIBUTING.md

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,12 @@ If you have an idea of how to improve the project, please create a [new issue](h
1616

1717
Do you want to provide a bug fix or an inprovement? Great! :tada:
1818

19-
Before opening a pull request, make sure that there is a related issue. The issue helps to confirm that the behavior is unexpected, or the idea of the improvement is valid. (Following the rule "Talk, then code")
19+
Before you start coding, make sure that there is a related issue. The issue helps to confirm that the behavior is unexpected, or the idea of the improvement is valid. (Following the rule "Talk, then code")
2020

21-
In order to verify that you don't break anything, you should build the whole project and run all tests. This also apply the code formatting.
21+
Before you open a pull request:
22+
* Make sure that you write new tests for the changed behavior
23+
* Run all tests to verify you don't break anything
24+
* Build the project with Maven to format the code
2225

2326
## Building the project from source
2427

@@ -66,6 +69,37 @@ Available commit types:
6669
* `build` - changes to the build (e.g. to Maven's `pom.xml`)
6770
* `ci` - changes to the CI (e.g. to GitHub-related configs)
6871

72+
## Guide for common contributions
73+
74+
If you're new and want to contribute to the project, check out the following step-by-step guides for common contributions.
75+
76+
### Adding a new built-in function
77+
78+
The built-in functions are grouped by their main argument type, following the DMN specification.
79+
80+
Example: Add a new string function `reverse(value: string): string`
81+
82+
* Implement the function in [StringBuiltinFunctions.scala](src/main/scala/org/camunda/feel/impl/builtin/StringBuiltinFunctions.scala)
83+
* Add a new private method `reverseFunction` and use the method `builtinFunction()`
84+
* `params` returns the argument list: `params = List("value")`
85+
* `invoke` is called when the function is invoked
86+
* It uses pattern-matching for the function parameters, the parameter order is the same in the argument list: `invoke = { case List(ValString(value)) => ??? }`
87+
* Return the function result `ValString(value.reverse)`
88+
* If the function can't return a successful result, return `ValError("something went wrong")` instead
89+
* Verify the behavior by writing test cases in [BuiltinStringFunctionsTest.scala](src/test/scala/org/camunda/feel/impl/builtin/BuiltinStringFunctionsTest.scala)
90+
* Add a new test case following the pattern: `"A reverse() function" should "return a string in reverse order" in { ??? }`
91+
* Add more test cases for other results, alternative parameters, or covering edge cases
92+
* Group all test cases for a method using `it should "return null if the argument is not a string" in { ??? }`
93+
* Add one test case that invokes the function with named arguments: `reverse(value: "adnumac")`
94+
* Run all tests to verify the behavior
95+
* Run the Maven build to format the code
96+
* Open a pull request and link to the FEEL issue
97+
* Then, document the function in the [Camunda docs](https://docs.camunda.io/docs/next/components/modeler/feel/builtin-functions/feel-built-in-functions-introduction/)
98+
* Navigate to the page [String functions](https://docs.camunda.io/docs/next/components/modeler/feel/builtin-functions/feel-built-in-functions-string/)
99+
* Click on `Edit this page` at the bottom
100+
* Add the function to the page, describe the behavior, and provide a few examples
101+
* Open a pull request and link to the FEEL issue and your pull request
102+
69103
## Public API and backward compatibility
70104

71105
The FEEL engine is integrated into Camunda 7 and Camunda 8. It's important to keep the public API stable and stay backward compatible to avoid breaking the integration in Camunda 7/8 or the userspace (i.e. the application that uses FEEL expressions).
@@ -91,7 +125,7 @@ Technically:
91125
* The engine behavior is verified by the unit tests
92126
* The supported environments are checked via GibHub actions
93127

94-
Any change or violation of the above must be accepted by the maintainers of Camunda 7 and Camunda 8 to avoid that a team/product getting "locked out".
128+
Any change or violation of the above must be accepted by the maintainers of Camunda 7 and Camunda 8 to avoid a team/product getting "locked out".
95129

96130
## Building the documentation
97131

0 commit comments

Comments
 (0)