-
Notifications
You must be signed in to change notification settings - Fork 106
azure-prepare: Enforce function file naming and add post-generation README/test update steps #1001
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Copilot
wants to merge
6
commits into
main
Choose a base branch
from
copilot/update-function-file-naming
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+121
−1
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
e07559f
Initial plan
Copilot 80f677f
feat: add function file naming convention, README and test update gui…
Copilot eb2345a
fix: remove unit test guidance from post-generation, focus on test.ht…
Copilot 546c622
Merge branch 'main' into copilot/update-function-file-naming
paulyuk 484f782
Merge branch 'main' into copilot/update-function-file-naming
paulyuk 2ec5460
Bump azure-prepare version to 1.0.8
paulyuk File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
119 changes: 119 additions & 0 deletions
119
...epare/references/services/functions/templates/recipes/common/post-generation.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,119 @@ | ||
| # Post-Generation Updates | ||
|
|
||
| > **MANDATORY**: After creating or adding any Azure Function, perform these three steps. | ||
|
|
||
| ## 1. File Naming Convention | ||
|
|
||
| Name function source files after their **route or purpose**, not the generic trigger type. | ||
|
|
||
| | Route / Purpose | ✅ Correct filename | ❌ Avoid | | ||
| |-----------------|---------------------|---------| | ||
| | `/api/random` | `src/functions/random.js` | `httpTrigger.js` | | ||
| | `/api/users` | `src/functions/users.js` | `httpTrigger.js` | | ||
| | `/api/health` | `src/functions/health.js` | `httpTrigger.js` | | ||
| | Cosmos DB change feed | `src/functions/cosmosProcessor.js` | `function1.js` | | ||
| | Scheduled job | `src/functions/dailyReport.js` | `timerTrigger.js` | | ||
|
|
||
| **Rules:** | ||
| - Derive the name from the route segment (e.g., `/api/random` → `random`) or the purpose (e.g., `dailyReport`) | ||
| - Use camelCase for multi-word names (e.g., `userProfile.js`, `orderProcessor.js`) | ||
| - Trigger-type suffixes are optional; prefer the shortest descriptive name | ||
| - Do **not** use generic names like `httpTrigger`, `function1`, or `index` unless unavoidable | ||
|
|
||
| ## 2. README Update | ||
|
|
||
| After adding a new function, update (or create) the project's `README.md`: | ||
|
|
||
| 1. **Add to endpoints table** – include function name, route, method, auth level, and description | ||
| 2. **Add curl example** – provide a ready-to-run `curl` command for local and deployed testing | ||
| 3. **Document env variables** – list any new environment variables the function requires | ||
|
|
||
| ### Template | ||
|
|
||
| ````markdown | ||
| ## Available Endpoints | ||
|
|
||
| | Function | Route | Method | Auth | Description | | ||
| |----------|-------|--------|------|-------------| | ||
| | `<functionName>` | `/api/<route>` | GET/POST | anonymous/function | <description> | | ||
|
|
||
| ### Test locally | ||
|
|
||
| ```bash | ||
| curl http://localhost:7071/api/<route> | ||
| ``` | ||
|
|
||
| ### Test deployed | ||
|
|
||
| ```bash | ||
| curl https://<functionapp>.azurewebsites.net/api/<route> | ||
| ``` | ||
| ```` | ||
|
|
||
| ### Example (route `/api/random`) | ||
|
|
||
| ````markdown | ||
| ## Available Endpoints | ||
|
|
||
| | Function | Route | Method | Auth | Description | | ||
| |----------|-------|--------|------|-------------| | ||
| | `random` | `/api/random` | GET | anonymous | Returns a random number | | ||
|
|
||
| ### Test locally | ||
|
|
||
| ```bash | ||
| curl http://localhost:7071/api/random | ||
| ``` | ||
|
|
||
| ### Test deployed | ||
|
|
||
| ```bash | ||
| curl https://<functionapp>.azurewebsites.net/api/random | ||
| ``` | ||
| ```` | ||
|
|
||
| ## 3. Test File Updates | ||
|
|
||
| After adding a new function, update the project's test files. | ||
|
|
||
| ### If a `test.http` file exists | ||
|
|
||
| Append a request block for the new function: | ||
|
|
||
| ```http | ||
| ### <FunctionName> - local | ||
| GET http://localhost:7071/api/<route> | ||
|
|
||
| ### <FunctionName> - deployed | ||
| GET https://{{functionAppName}}.azurewebsites.net/api/<route> | ||
| ``` | ||
|
|
||
| For POST endpoints, include a body: | ||
|
|
||
| ```http | ||
| ### <FunctionName> POST - local | ||
| POST http://localhost:7071/api/<route> | ||
| Content-Type: application/json | ||
|
|
||
| { | ||
| "key": "value" | ||
| } | ||
| ``` | ||
|
|
||
| ### If a `testdata.json` (or similar data file used with curl) exists | ||
|
|
||
| Append an entry for the new function's expected input/output: | ||
|
|
||
| ```json | ||
| { | ||
| "<functionName>": { | ||
| "route": "/api/<route>", | ||
| "method": "GET", | ||
| "expectedStatus": 200 | ||
| } | ||
| } | ||
| ``` | ||
|
|
||
| ### If neither `test.http` nor a testdata file exists | ||
|
|
||
| Create a `test.http` file at the project root with a request block for the new function (see template above). | ||
paulyuk marked this conversation as resolved.
Show resolved
Hide resolved
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.