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 21 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
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/x0rw/safety-critical-rust-coding-guidelines/issues/4",
"repository_url": "https://api.github.com/repos/x0rw/safety-critical-rust-coding-guidelines",
"labels_url": "https://api.github.com/repos/x0rw/safety-critical-rust-coding-guidelines/issues/4/labels{/name}",
"comments_url": "https://api.github.com/repos/x0rw/safety-critical-rust-coding-guidelines/issues/4/comments",
"events_url": "https://api.github.com/repos/x0rw/safety-critical-rust-coding-guidelines/issues/4/events",
"html_url": "https://github.com/x0rw/safety-critical-rust-coding-guidelines/issues/4",
"id": 3104390263,
"node_id": "I_kwDOOMMjbs65CTx3",
"number": 4,
"title": "[Coding Guideline]: testtt",
"user": {
"login": "x0rw",
"id": 14003018,
"node_id": "MDQ6VXNlcjE0MDAzMDE4",
"avatar_url": "https://avatars.githubusercontent.com/u/14003018?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/x0rw",
"html_url": "https://github.com/x0rw",
"followers_url": "https://api.github.com/users/x0rw/followers",
"following_url": "https://api.github.com/users/x0rw/following{/other_user}",
"gists_url": "https://api.github.com/users/x0rw/gists{/gist_id}",
"starred_url": "https://api.github.com/users/x0rw/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/x0rw/subscriptions",
"organizations_url": "https://api.github.com/users/x0rw/orgs",
"repos_url": "https://api.github.com/users/x0rw/repos",
"events_url": "https://api.github.com/users/x0rw/events{/privacy}",
"received_events_url": "https://api.github.com/users/x0rw/received_events",
"type": "User",
"user_view_type": "public",
"site_admin": false
},
"labels": [
{
"id": 8703664686,
"node_id": "LA_kwDOOMMjbs8AAAACBsdiLg",
"url": "https://api.github.com/repos/x0rw/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/x0rw/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/x0rw/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/x0rw/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/x0rw/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/x0rw/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/x0rw/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/x0rw/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_LzfV28IVG7qO
: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_nPL2Cv7VBdqG
:status: draft

test ga

.. non_compliant_example::
:id: non_compl_ex_Bv7HMs0AVNlH
:status: draft

test ga

.. code-block:: rust

dfhsdfkjshdfskdjhftest ga

.. compliant_example::
:id: compl_ex_H5Z7OsxZX3Ig
: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/x0rw/safety-critical-rust-coding-guidelines/issues/4",
"repository_url": "https://api.github.com/repos/x0rw/safety-critical-rust-coding-guidelines",
"labels_url": "https://api.github.com/repos/x0rw/safety-critical-rust-coding-guidelines/issues/4/labels{/name}",
"comments_url": "https://api.github.com/repos/x0rw/safety-critical-rust-coding-guidelines/issues/4/comments",
"events_url": "https://api.github.com/repos/x0rw/safety-critical-rust-coding-guidelines/issues/4/events",
"html_url": "https://github.com/x0rw/safety-critical-rust-coding-guidelines/issues/4",
"id": 3104390263,
"node_id": "I_kwDOOMMjbs65CTx3",
"number": 4,
"title": "[Coding Guideline]: testtt",
"user": {
"login": "x0rw",
"id": 14003018,
"node_id": "MDQ6VXNlcjE0MDAzMDE4",
"avatar_url": "https://avatars.githubusercontent.com/u/14003018?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/x0rw",
"html_url": "https://github.com/x0rw",
"followers_url": "https://api.github.com/users/x0rw/followers",
"following_url": "https://api.github.com/users/x0rw/following{/other_user}",
"gists_url": "https://api.github.com/users/x0rw/gists{/gist_id}",
"starred_url": "https://api.github.com/users/x0rw/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/x0rw/subscriptions",
"organizations_url": "https://api.github.com/users/x0rw/orgs",
"repos_url": "https://api.github.com/users/x0rw/repos",
"events_url": "https://api.github.com/users/x0rw/events{/privacy}",
"received_events_url": "https://api.github.com/users/x0rw/received_events",
"type": "User",
"user_view_type": "public",
"site_admin": false
},
"labels": [
{
"id": 8703664686,
"node_id": "LA_kwDOOMMjbs8AAAACBsdiLg",
"url": "https://api.github.com/repos/x0rw/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/x0rw/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/x0rw/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/x0rw/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/x0rw/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/x0rw/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/x0rw/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/x0rw/safety-critical-rust-coding-guidelines/issues/4/timeline",
"performed_via_github_app": null,
"state_reason": null
}
88 changes: 88 additions & 0 deletions .github/auto-pr-tests/test_issue_02.snapshot
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
=====CONTENT=====

.. guideline:: Recursive function are not allowed
:id: gui_1EDWRNKjs6It
:category: required
:status: draft
:release: 1.3.0-latest
:fls: fls_vjgkg8kfi93
:decidability: undecidable
:scope: system
:tags: reduce-human-error

Any function shall not call itself directly or indirectly

.. rationale::
:id: rat_Hbn0yLGzVdDK
:status: draft

Recursive 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.

.. non_compliant_example::
:id: non_compl_ex_eRmcumqqmMaZ
:status: draft

The 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.

.. code-block:: rust

// Recursive enum to represent a string or a list of `MyEnum`
enum MyEnum {
Str(String),
List(Vec<MyEnum>),
}

// Concatenates strings from a nested structure of `MyEnum` using recursion.
fn concat_strings(input: &[MyEnum]) -> String {
let mut result = String::new();
for item in input {
match item {
MyEnum::Str(s) => result.push_str(s),
MyEnum::List(list) => result.push_str(&concat_strings(list)),
}
}
result
}

.. compliant_example::
:id: compl_ex_t6Hy8E2YlneV
:status: draft

The 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.

.. code-block:: rust

// Recursive enum to represent a string or a list of `MyEnum`
enum MyEnum {
Str(String),
List(Vec<MyEnum>),
}

/// Concatenates strings from a nested structure of `MyEnum` without using recursion.
/// Returns an error if the stack size exceeds `MAX_STACK_SIZE`.
fn concat_strings_non_recursive(input: &[MyEnum]) -> Result<String, &'static str> {
const MAX_STACK_SIZE: usize = 1000;
let mut result = String::new();
let mut stack = Vec::new();

// Add all items to the stack
stack.extend(input.iter());

while let Some(item) = stack.pop() {
match item {
MyEnum::Str(s) => result.insert_str(0, s),
MyEnum::List(list) => {
// Add list items to the stack
for sub_item in list.iter() {
stack.push(sub_item);
if stack.len() > MAX_STACK_SIZE {
return Err("Too big structure");
}
}
}
}
}
Ok(result)
}

=====CONTENT=END=====
Loading
Loading