Skip to content

[GitHub Action] Automatically open a PR for accepted guideline issues #122

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
wants to merge 30 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
0e86d16
Triger workflow
x0rw May 30, 2025
fa85086
test auto-pr template
x0rw May 30, 2025
e970422
chores: minor stuffs
x0rw May 31, 2025
5072bb6
chores: proper pr title
x0rw May 31, 2025
53aaf2a
Add comments
x0rw Jun 4, 2025
1442007
Update .github/workflows/auto-pr-on-issue.yml
x0rw Jun 7, 2025
2c0a7c2
Fix
x0rw Jun 7, 2025
14e0f8d
Fix non compliant ex
x0rw Jul 12, 2025
286b9c4
refactor: address code review
x0rw Jul 12, 2025
49c32c7
Fix workflow, use uv instead
x0rw Jul 12, 2025
4a8ad42
Add snapshot tests workflow
x0rw Jul 12, 2025
cbcfad5
Update .github/workflows/auto-pr-on-issue.yml
x0rw Jul 13, 2025
f17f796
Apply suggestion from @PLeVasseur
x0rw Jul 13, 2025
f5e756d
Apply suggestion from @PLeVasseur
x0rw Jul 13, 2025
5b1d45b
address review comments
x0rw Jul 13, 2025
f4f0fe8
test ci snapshot error
x0rw Jul 13, 2025
3bd6382
Fix issues, refactor dedent, update worflow to use astral actions
x0rw Jul 13, 2025
b2f598d
Fix ci
x0rw Jul 13, 2025
81795ff
Inline compliant and non-compliant-exs in guideline template
x0rw Jul 13, 2025
d2d5f53
Address review comments and remove unused code
x0rw Jul 16, 2025
e293ce3
ci: add co-author info from issue author in auto-generated PRs
x0rw Jul 16, 2025
bf12b40
feat: md to .rst, fix ci unstability
x0rw Jul 27, 2025
fe1279b
add m2r to pyproject.toml
x0rw Jul 27, 2025
86ab9d4
fix double commit issue
x0rw Jul 27, 2025
9641978
fix ci: merge dup with
x0rw Jul 27, 2025
3cc0622
fix: we assume that tags are already seperated in the issue, update s…
x0rw Jul 27, 2025
e3582f4
Add snapshot tests readme.md
x0rw Jul 27, 2025
d0e216e
Add scripts/auto-pr-helper.py readme.md
x0rw Jul 27, 2025
a52f883
feat: tag the original author in the PR itself
x0rw Jul 28, 2025
ceae2f7
update snapshots
x0rw Jul 28, 2025
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
36 changes: 36 additions & 0 deletions .github/auto-pr-tests/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
## How to Add and Document Tests in `auto-pr-tests`

The test script `scripts/auto-pr-helper.py` transforms an issue from JSON format into our `.rst` format.

This directory contains test issue files in JSON format along with their expected output snapshots. These tests are executed by the script `test_runner.py`.

### Adding a New Test

1. **Create Input JSON File**

First, obtain the JSON data for the GitHub issue you want to use as a test case. Name the file test_issue_XX.json, where XX is a number, Instructions on how to get this JSON data are provided in the next section.

2. **Generate Expected Output Snapshot**
Run the following command to generate the corresponding `.snapshot` file automatically:

```bash
cat .github/auto-pr-tests/test_issue_XX.json | uv run scripts/auto-pr-helper.py > .github/auto-pr-tests/test_issue_XX.snapshot
```
It is better to run this command and manually verify the output, rather than creating the snapshot manually.
3. **Add Test to the Test List**
Add your new JSON and snapshot file paths to the tests dictionary inside test_runner.py(line 47). This registers the new test so it will be run.
4. Run Tests
Execute test_runner.py to verify that the output matches the expected snapshots.


### How to Get Issue JSON from GitHub API

To create the input JSON file (`test_issue_XX.json`), you can fetch the issue data directly from the GitHub API:

1. Find the issue number and repository where the issue is located.

2. Use a tool like `curl` or any HTTP client to request the issue JSON data:

```bash
curl https://api.github.com/repos/OWNER/REPO/issues/ISSUE_NUMBER > test_issue_XX.json
```
124 changes: 124 additions & 0 deletions .github/auto-pr-tests/test_issue_01.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
{
"url": "https://api.github.com/repos/rustfoundation/safety-critical-rust-coding-guidelines/issues/4",
"repository_url": "https://api.github.com/repos/rustfoundation/safety-critical-rust-coding-guidelines",
"labels_url": "https://api.github.com/repos/rustfoundation/safety-critical-rust-coding-guidelines/issues/4/labels{/name}",
"comments_url": "https://api.github.com/repos/rustfoundation/safety-critical-rust-coding-guidelines/issues/4/comments",
"events_url": "https://api.github.com/repos/rustfoundation/safety-critical-rust-coding-guidelines/issues/4/events",
"html_url": "https://github.com/rustfoundation/safety-critical-rust-coding-guidelines/issues/4",
"id": 3104390263,
"node_id": "I_kwDOOMMjbs65CTx3",
"number": 4,
"title": "[Coding Guideline]: testtt",
"user": {
"login": "rustfoundation",
"id": 14003018,
"node_id": "MDQ6VXNlcjE0MDAzMDE4",
"avatar_url": "https://avatars.githubusercontent.com/u/14003018?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/rustfoundation",
"html_url": "https://github.com/rustfoundation",
"followers_url": "https://api.github.com/users/rustfoundation/followers",
"following_url": "https://api.github.com/users/rustfoundation/following{/other_user}",
"gists_url": "https://api.github.com/users/rustfoundation/gists{/gist_id}",
"starred_url": "https://api.github.com/users/rustfoundation/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/rustfoundation/subscriptions",
"organizations_url": "https://api.github.com/users/rustfoundation/orgs",
"repos_url": "https://api.github.com/users/rustfoundation/repos",
"events_url": "https://api.github.com/users/rustfoundation/events{/privacy}",
"received_events_url": "https://api.github.com/users/rustfoundation/received_events",
"type": "User",
"user_view_type": "public",
"site_admin": false
},
"labels": [
{
"id": 8703664686,
"node_id": "LA_kwDOOMMjbs8AAAACBsdiLg",
"url": "https://api.github.com/repos/rustfoundation/safety-critical-rust-coding-guidelines/labels/category:%20advisory",
"name": "category: advisory",
"color": "ededed",
"default": false,
"description": null
},
{
"id": 8703664688,
"node_id": "LA_kwDOOMMjbs8AAAACBsdiMA",
"url": "https://api.github.com/repos/rustfoundation/safety-critical-rust-coding-guidelines/labels/status:%20draft",
"name": "status: draft",
"color": "ededed",
"default": false,
"description": null
},
{
"id": 8703664689,
"node_id": "LA_kwDOOMMjbs8AAAACBsdiMQ",
"url": "https://api.github.com/repos/rustfoundation/safety-critical-rust-coding-guidelines/labels/decidability:%20decidable",
"name": "decidability: decidable",
"color": "ededed",
"default": false,
"description": null
},
{
"id": 8703686409,
"node_id": "LA_kwDOOMMjbs8AAAACBse3CQ",
"url": "https://api.github.com/repos/rustfoundation/safety-critical-rust-coding-guidelines/labels/chapter:%20concurrency",
"name": "chapter: concurrency",
"color": "ededed",
"default": false,
"description": null
},
{
"id": 8703686412,
"node_id": "LA_kwDOOMMjbs8AAAACBse3DA",
"url": "https://api.github.com/repos/rustfoundation/safety-critical-rust-coding-guidelines/labels/scope:%20crate",
"name": "scope: crate",
"color": "ededed",
"default": false,
"description": null
},
{
"id": 8703732885,
"node_id": "LA_kwDOOMMjbs8AAAACBshslQ",
"url": "https://api.github.com/repos/rustfoundation/safety-critical-rust-coding-guidelines/labels/accepted",
"name": "accepted",
"color": "6AABE8",
"default": false,
"description": ""
}
],
"state": "open",
"locked": false,
"assignee": null,
"assignees": [

],
"milestone": null,
"comments": 0,
"created_at": "2025-05-30T22:24:07Z",
"updated_at": "2025-05-30T22:48:17Z",
"closed_at": null,
"author_association": "OWNER",
"active_lock_reason": null,
"sub_issues_summary": {
"total": 0,
"completed": 0,
"percent_completed": 0
},
"body": "### Chapter\n\nConcurrency\n\n### Guideline Title\n\ntest ga\n\n### Category\n\nAdvisory\n\n### Status\n\nDraft\n\n### Release Begin\n\n1.1.1\n\n### Release End\n\n1.1.1\n\n### FLS Paragraph ID\n\nfls_fsdjkfslkdfj\n\n### Decidability\n\nDecidable\n\n### Scope\n\nCrate\n\n### Tags\n\ntest gatest ga\n\n### Amplification\n\nhehehehe\n\n### Exception(s)\n\n_No response_\n\n### Rationale\n\ntest ga\n\n### Non-Compliant Example - Prose\n\ntest ga\n\n### Non-Compliant Example - Code\n\ndfhsdfkjshdfskdjhftest ga\n\n### Compliant Example - Prose\n\ntest ga\n\n### Compliant Example - Code\n\ntest ga",
"closed_by": null,
"reactions": {
"url": "https://api.github.com/repos/rustfoundation/safety-critical-rust-coding-guidelines/issues/4/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
},
"timeline_url": "https://api.github.com/repos/rustfoundation/safety-critical-rust-coding-guidelines/issues/4/timeline",
"performed_via_github_app": null,
"state_reason": null
}
41 changes: 41 additions & 0 deletions .github/auto-pr-tests/test_issue_01.snapshot
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
=====CONTENT=====

.. guideline:: test ga
:id: gui_3Wl9gOTto7p2
:category: advisory
:status: draft
:release: 1.1.1-1.1.1
:fls: fls_fsdjkfslkdfj
:decidability: decidable
:scope: crate
:tags: test gatest ga

hehehehe

.. rationale::
:id: rat_PVjXjtM9G383
:status: draft

test ga

.. non_compliant_example::
:id: non_compl_ex_ABSVsT97MwLG
:status: draft

test ga

.. code-block:: rust

dfhsdfkjshdfskdjhftest ga

.. compliant_example::
:id: compl_ex_Z9TjeDsRTnwL
:status: draft

test ga

.. code-block:: rust

test ga

=====CONTENT=END=====
124 changes: 124 additions & 0 deletions .github/auto-pr-tests/test_issue_02.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
{
"url": "https://api.github.com/repos/rustfoundation/safety-critical-rust-coding-guidelines/issues/4",
"repository_url": "https://api.github.com/repos/rustfoundation/safety-critical-rust-coding-guidelines",
"labels_url": "https://api.github.com/repos/rustfoundation/safety-critical-rust-coding-guidelines/issues/4/labels{/name}",
"comments_url": "https://api.github.com/repos/rustfoundation/safety-critical-rust-coding-guidelines/issues/4/comments",
"events_url": "https://api.github.com/repos/rustfoundation/safety-critical-rust-coding-guidelines/issues/4/events",
"html_url": "https://github.com/rustfoundation/safety-critical-rust-coding-guidelines/issues/4",
"id": 3104390263,
"node_id": "I_kwDOOMMjbs65CTx3",
"number": 4,
"title": "[Coding Guideline]: testtt",
"user": {
"login": "rustfoundation",
"id": 14003018,
"node_id": "MDQ6VXNlcjE0MDAzMDE4",
"avatar_url": "https://avatars.githubusercontent.com/u/14003018?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/rustfoundation",
"html_url": "https://github.com/rustfoundation",
"followers_url": "https://api.github.com/users/rustfoundation/followers",
"following_url": "https://api.github.com/users/rustfoundation/following{/other_user}",
"gists_url": "https://api.github.com/users/rustfoundation/gists{/gist_id}",
"starred_url": "https://api.github.com/users/rustfoundation/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/rustfoundation/subscriptions",
"organizations_url": "https://api.github.com/users/rustfoundation/orgs",
"repos_url": "https://api.github.com/users/rustfoundation/repos",
"events_url": "https://api.github.com/users/rustfoundation/events{/privacy}",
"received_events_url": "https://api.github.com/users/rustfoundation/received_events",
"type": "User",
"user_view_type": "public",
"site_admin": false
},
"labels": [
{
"id": 8703664686,
"node_id": "LA_kwDOOMMjbs8AAAACBsdiLg",
"url": "https://api.github.com/repos/rustfoundation/safety-critical-rust-coding-guidelines/labels/category:%20advisory",
"name": "category: advisory",
"color": "ededed",
"default": false,
"description": null
},
{
"id": 8703664688,
"node_id": "LA_kwDOOMMjbs8AAAACBsdiMA",
"url": "https://api.github.com/repos/rustfoundation/safety-critical-rust-coding-guidelines/labels/status:%20draft",
"name": "status: draft",
"color": "ededed",
"default": false,
"description": null
},
{
"id": 8703664689,
"node_id": "LA_kwDOOMMjbs8AAAACBsdiMQ",
"url": "https://api.github.com/repos/rustfoundation/safety-critical-rust-coding-guidelines/labels/decidability:%20decidable",
"name": "decidability: decidable",
"color": "ededed",
"default": false,
"description": null
},
{
"id": 8703686409,
"node_id": "LA_kwDOOMMjbs8AAAACBse3CQ",
"url": "https://api.github.com/repos/rustfoundation/safety-critical-rust-coding-guidelines/labels/chapter:%20concurrency",
"name": "chapter: concurrency",
"color": "ededed",
"default": false,
"description": null
},
{
"id": 8703686412,
"node_id": "LA_kwDOOMMjbs8AAAACBse3DA",
"url": "https://api.github.com/repos/rustfoundation/safety-critical-rust-coding-guidelines/labels/scope:%20crate",
"name": "scope: crate",
"color": "ededed",
"default": false,
"description": null
},
{
"id": 8703732885,
"node_id": "LA_kwDOOMMjbs8AAAACBshslQ",
"url": "https://api.github.com/repos/rustfoundation/safety-critical-rust-coding-guidelines/labels/accepted",
"name": "accepted",
"color": "6AABE8",
"default": false,
"description": ""
}
],
"state": "open",
"locked": false,
"assignee": null,
"assignees": [

],
"milestone": null,
"comments": 0,
"created_at": "2025-05-30T22:24:07Z",
"updated_at": "2025-05-30T22:48:17Z",
"closed_at": null,
"author_association": "OWNER",
"active_lock_reason": null,
"sub_issues_summary": {
"total": 0,
"completed": 0,
"percent_completed": 0
},
"body": "### Chapter\n\nAssociated Items\n\n### Guideline Title\n\nRecursive function are not allowed\n\n### Category\n\nRequired\n\n### Status\n\nDraft\n\n### Release Begin\n\n1.3.0\n\n### Release End\n\nlatest\n\n### FLS Paragraph ID\n\nfls_vjgkg8kfi93\n\n### Decidability\n\nUndecidable\n\n### Scope\n\nSystem\n\n### Tags\n\nreduce-human-error\n\n### Amplification\n\nAny function shall not call itself directly or indirectly\n\n### Exception(s)\n\nRecursion may be permitted under the following conditions:\n- The recursion termination condition is simple, explicit, and well-defined.\n- The function calls itself directly, or with strictly limited and clearly documented indirection.\n- The maximum recursion depth is statically bounded and justified, ensuring no risk of stack overflow.\n- The rationale for using recursion, rather than iteration, is clearly documented and reviewed.\n- The code is accompanied by tests that exercise the recursion boundary conditions.\n\n### Rationale\n\nRecursive functions can easily cause stack overflows, which may result in exceptions or, in some cases, undefined behavior (typically some embedded systems). Although the Rust compiler supports [tail call optimization](https://en.wikipedia.org/wiki/Tail_call), this optimization is not guaranteed and depends on the specific implementation and function structure. There is an [open RFC to guarantee tail call optimization in the Rust compiler](https://github.com/phi-go/rfcs/blob/guaranteed-tco/text/0000-explicit-tail-calls.md), but this feature has not yet been stabilized. Until tail call optimization is guaranteed and stabilized, developers should avoid using recursive functions to prevent potential stack overflows and ensure program reliability.\n\n### Non-Compliant Example - Prose\n\nThe below function `concat_strings` is not complaint because it call itself and depending on depth of data provided as input it could generate an stack overflow exception or undefine behavior.\n\n### Non-Compliant Example - Code\n\n```rust\n// Recursive enum to represent a string or a list of `MyEnum`\nenum MyEnum {\n Str(String),\n List(Vec<MyEnum>),\n}\n\n// Concatenates strings from a nested structure of `MyEnum` using recursion.\nfn concat_strings(input: &[MyEnum]) -> String {\n let mut result = String::new();\n for item in input {\n match item {\n MyEnum::Str(s) => result.push_str(s),\n MyEnum::List(list) => result.push_str(&concat_strings(list)),\n }\n }\n result\n}\n```\n\n### Compliant Example - Prose\n\nThe following code implements the same functionality using iteration instead of recursion. The `stack` variable is used to maintain the processing context at each step of the loop. This approach provides explicit control over memory usage. If the stack grows beyond a predefined limit due to the structure or size of the input, the function returns an error rather than risking a stack overflow or out-of-memory exception. This ensures more predictable and robust behavior in resource-constrained environments.\n\n### Compliant Example - Code\n\n```rust\n// Recursive enum to represent a string or a list of `MyEnum`\nenum MyEnum {\n Str(String),\n List(Vec<MyEnum>),\n}\n\n/// Concatenates strings from a nested structure of `MyEnum` without using recursion.\n/// Returns an error if the stack size exceeds `MAX_STACK_SIZE`.\nfn concat_strings_non_recursive(input: &[MyEnum]) -> Result<String, &'static str> {\n const MAX_STACK_SIZE: usize = 1000;\n let mut result = String::new();\n let mut stack = Vec::new();\n\n // Add all items to the stack\n stack.extend(input.iter());\n\n while let Some(item) = stack.pop() {\n match item {\n MyEnum::Str(s) => result.insert_str(0, s),\n MyEnum::List(list) => {\n // Add list items to the stack\n for sub_item in list.iter() {\n stack.push(sub_item);\n if stack.len() > MAX_STACK_SIZE {\n return Err(\"Too big structure\");\n }\n }\n }\n }\n }\n Ok(result)\n}\n```",
"closed_by": null,
"reactions": {
"url": "https://api.github.com/repos/rustfoundation/safety-critical-rust-coding-guidelines/issues/4/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
},
"timeline_url": "https://api.github.com/repos/rustfoundation/safety-critical-rust-coding-guidelines/issues/4/timeline",
"performed_via_github_app": null,
"state_reason": null
}
Loading