Skip to content

Conversation

@sensei-hacker
Copy link
Member

@sensei-hacker sensei-hacker commented Nov 30, 2025

User description

Adds a GitHub Action that automatically comments on new Pull Requests targeting the master branch, suggesting that contributors consider targeting maintenance-9.x or maintenance-10.x branches instead when appropriate.

  • Triggers when a PR is opened targeting master
  • Adds an informational comment explaining when to use maintenance branches
  • Non-blocking - contributors can still merge to master if appropriate

PR Type

Enhancement


Description

  • Adds GitHub Action workflow for PR branch suggestions

  • Automatically comments on PRs targeting master branch

  • Suggests maintenance-9.x or maintenance-10.x branches

  • Provides guidance on backward compatibility considerations


Diagram Walkthrough

flowchart LR
  PR["PR opened on master"] -- "triggers workflow" --> Action["GitHub Action executes"]
  Action -- "creates comment" --> Comment["Branch suggestion comment"]
  Comment -- "guides contributor" --> Decision["Choose appropriate branch"]
Loading

File Walkthrough

Relevant files
Enhancement
pr-branch-suggestion.yml
GitHub Action workflow for PR branch suggestions                 

.github/workflows/pr-branch-suggestion.yml

  • Creates new GitHub Actions workflow triggered on PR open events
    targeting master
  • Uses github-script action to post automated comment with branch
    suggestions
  • Provides guidance on when to use maintenance-9.x vs maintenance-10.x
    branches
  • Includes backward compatibility considerations in the suggestion
    message
+37/-0   

@qodo-code-review
Copy link
Contributor

qodo-code-review bot commented Nov 30, 2025

You are nearing your monthly Qodo Merge usage quota. For more information, please visit here.

PR Compliance Guide 🔍

Below is a summary of compliance checks for this PR:

Security Compliance
Excessive permissions

Description: The workflow grants write permission to pull requests for a workflow triggered by
pull_request events, which can enable PR comment or content manipulation if other parts of
the repository later consume PR comments or metadata without sanitization; consider
minimizing permissions (e.g., 'pull-requests: write' only when necessary and ideally use a
token with least privileges or 'permissions: write-all: false' with explicit scopes).
pr-branch-suggestion.yml [12-13]

Referred Code
permissions:
  pull-requests: write
Ticket Compliance
🎫 No ticket provided
  • Create ticket/issue
Codebase Duplication Compliance
Codebase context is not defined

Follow the guide to enable codebase context checks.

Custom Compliance
🟢
Generic: Comprehensive Audit Trails

Objective: To create a detailed and reliable record of critical system actions for security analysis
and compliance.

Status: Passed

Learn more about managing compliance generic rules or creating your own custom rules

Generic: Meaningful Naming and Self-Documenting Code

Objective: Ensure all identifiers clearly express their purpose and intent, making code
self-documenting

Status: Passed

Learn more about managing compliance generic rules or creating your own custom rules

Generic: Secure Error Handling

Objective: To prevent the leakage of sensitive system information through error messages while
providing sufficient detail for internal debugging.

Status: Passed

Learn more about managing compliance generic rules or creating your own custom rules

Generic: Secure Logging Practices

Objective: To ensure logs are useful for debugging and auditing without exposing sensitive
information like PII, PHI, or cardholder data.

Status: Passed

Learn more about managing compliance generic rules or creating your own custom rules

Generic: Security-First Input Validation and Data Handling

Objective: Ensure all data inputs are validated, sanitized, and handled securely to prevent
vulnerabilities

Status: Passed

Learn more about managing compliance generic rules or creating your own custom rules

Generic: Robust Error Handling and Edge Case Management

Objective: Ensure comprehensive error handling that provides meaningful context and graceful
degradation

Status:
Missing failure handling: The workflow posts a comment without guarding against API failures or providing
fallback/error handling, making errors silently fail in automation context.

Referred Code
- name: Suggest maintenance branch
  uses: actions/github-script@v7
  with:
    script: |
      const comment = `### Branch Targeting Suggestion

      You've targeted the \`master\` branch with this PR. Please consider if a version branch might be more appropriate:

      - **\`maintenance-9.x\`** - If your change is backward-compatible and won't create compatibility issues between INAV firmware and Configurator 9.x versions. This will allow your PR to be included in the next 9.x release.

      - **\`maintenance-10.x\`** - If your change introduces compatibility requirements between firmware and configurator that would break 9.x compatibility. This is for PRs which will be included in INAV 10.x

      If \`master\` is the correct target for this change, no action is needed.

      ---
      *This is an automated suggestion to help route contributions to the appropriate branch.*`;

      github.rest.issues.createComment({
        issue_number: context.issue.number,
        owner: context.repo.owner,
        repo: context.repo.repo,


 ... (clipped 1 lines)

Learn more about managing compliance generic rules or creating your own custom rules

  • Update
Compliance status legend 🟢 - Fully Compliant
🟡 - Partial Compliant
🔴 - Not Compliant
⚪ - Requires Further Human Verification
🏷️ - Compliance label

@qodo-code-review
Copy link
Contributor

qodo-code-review bot commented Nov 30, 2025

You are nearing your monthly Qodo Merge usage quota. For more information, please visit here.

PR Code Suggestions ✨

Explore these optional code suggestions:

CategorySuggestion                                                                                                                                    Impact
High-level
Dynamically generate branch suggestions

Instead of hardcoding maintenance branch names in the comment, the script should
be updated to dynamically query the repository for branches matching a
maintenance-* pattern and generate the suggestions from the results. This will
reduce future maintenance overhead.

Examples:

.github/workflows/pr-branch-suggestion.yml [19-30]
            const comment = `### Branch Targeting Suggestion

            You've targeted the \`master\` branch with this PR. Please consider if a version branch might be more appropriate:

            - **\`maintenance-9.x\`** - If your change is backward-compatible and won't create compatibility issues between INAV firmware and Configurator 9.x versions. This will allow your PR to be included in the next 9.x release.

            - **\`maintenance-10.x\`** - If your change introduces compatibility requirements between firmware and configurator that would break 9.x compatibility. This is for PRs which will be included in INAV 10.x

            If \`master\` is the correct target for this change, no action is needed.


 ... (clipped 2 lines)

Solution Walkthrough:

Before:

# .github/workflows/pr-branch-suggestion.yml
- name: Suggest maintenance branch
  uses: actions/github-script@v7
  with:
    script: |
      const comment = `### Branch Targeting Suggestion
      ...
      - **\`maintenance-9.x\`** - ...
      - **\`maintenance-10.x\`** - ...
      ...
      `;
      github.rest.issues.createComment({
        ...
        body: comment
      });

After:

# .github/workflows/pr-branch-suggestion.yml
- name: Suggest maintenance branch
  uses: actions/github-script@v7
  with:
    script: |
      const { data: branches } = await github.rest.repos.listBranches(...);
      const maintBranches = branches
        .filter(b => b.name.startsWith('maintenance-'))
        .map(b => `- **\`${b.name}\`** - ...`)
        .join('\n');

      const comment = `### Branch Targeting Suggestion
      ...
      ${maintBranches}
      ...
      `;
      github.rest.issues.createComment({ ... , body: comment });
Suggestion importance[1-10]: 7

__

Why: This suggestion correctly identifies that hardcoding branch names creates a future maintenance burden and proposes a dynamic solution, significantly improving the workflow's long-term robustness and maintainability.

Medium
Possible issue
Prevent posting duplicate comments

To prevent duplicate comments, modify the script to first check if a similar
comment from the bot already exists on the pull request before posting a new
one.

.github/workflows/pr-branch-suggestion.yml [19-37]

-const comment = `### Branch Targeting Suggestion
+const body = `### Branch Targeting Suggestion
 
 You've targeted the \`master\` branch with this PR. Please consider if a version branch might be more appropriate:
 
 - **\`maintenance-9.x\`** - If your change is backward-compatible and won't create compatibility issues between INAV firmware and Configurator 9.x versions. This will allow your PR to be included in the next 9.x release.
 
 - **\`maintenance-10.x\`** - If your change introduces compatibility requirements between firmware and configurator that would break 9.x compatibility. This is for PRs which will be included in INAV 10.x
 
 If \`master\` is the correct target for this change, no action is needed.
 
 ---
 *This is an automated suggestion to help route contributions to the appropriate branch.*`;
 
-github.rest.issues.createComment({
+const { data: comments } = await github.rest.issues.listComments({
+  owner: context.repo.owner,
+  repo: context.repo.repo,
+  issue_number: context.issue.number,
+});
+
+const botComment = comments.find(comment => {
+  return comment.user.type === 'Bot' && comment.body.includes('Branch Targeting Suggestion')
+});
+
+if (botComment) {
+  console.log('Suggestion comment already exists.');
+  return;
+}
+
+await github.rest.issues.createComment({
   issue_number: context.issue.number,
   owner: context.repo.owner,
   repo: context.repo.repo,
-  body: comment
+  body: body
 });

[Suggestion processed]

Suggestion importance[1-10]: 7

__

Why: The suggestion correctly identifies that the action is not idempotent and will post duplicate comments on re-triggers, proposing a valid fix to check for existing comments first, which improves the workflow's robustness.

Medium
General
Use environment variables for versions

To improve maintainability, define the branch version numbers as environment
variables at the job level and reference them within the script instead of
hardcoding them.

.github/workflows/pr-branch-suggestion.yml [9-37]

 jobs:
   suggest-branch:
     runs-on: ubuntu-latest
     permissions:
       pull-requests: write
+    env:
+      PREVIOUS_MAINTENANCE_VERSION: 9
+      CURRENT_MAINTENANCE_VERSION: 10
     steps:
       - name: Suggest maintenance branch
         uses: actions/github-script@v7
         with:
           script: |
+            const prev_version = process.env.PREVIOUS_MAINTENANCE_VERSION;
+            const current_version = process.env.CURRENT_MAINTENANCE_VERSION;
+
             const comment = `### Branch Targeting Suggestion
 
             You've targeted the \`master\` branch with this PR. Please consider if a version branch might be more appropriate:
 
-            - **\`maintenance-9.x\`** - If your change is backward-compatible and won't create compatibility issues between INAV firmware and Configurator 9.x versions. This will allow your PR to be included in the next 9.x release.
+            - **\`maintenance-${prev_version}.x\`** - If your change is backward-compatible and won't create compatibility issues between INAV firmware and Configurator ${prev_version}.x versions. This will allow your PR to be included in the next ${prev_version}.x release.
 
-            - **\`maintenance-10.x\`** - If your change introduces compatibility requirements between firmware and configurator that would break 9.x compatibility. This is for PRs which will be included in INAV 10.x
+            - **\`maintenance-${current_version}.x\`** - If your change introduces compatibility requirements between firmware and configurator that would break ${prev_version}.x compatibility. This is for PRs which will be included in INAV ${current_version}.x
 
             If \`master\` is the correct target for this change, no action is needed.
 ...

[To ensure code accuracy, apply this suggestion manually]

Suggestion importance[1-10]: 6

__

Why: The suggestion improves maintainability by correctly proposing to extract hardcoded version numbers into environment variables, making future updates to the workflow easier and less error-prone.

Low
Learned
best practice
Await comment API call

Await the API call to ensure the comment is posted and surface any errors in the
workflow logs. Add basic error handling to guard failures.

.github/workflows/pr-branch-suggestion.yml [32-37]

-github.rest.issues.createComment({
+await github.rest.issues.createComment({
   issue_number: context.issue.number,
   owner: context.repo.owner,
   repo: context.repo.repo,
   body: comment
 });
  • Apply / Chat
Suggestion importance[1-10]: 6

__

Why:
Relevant best practice - Gate asynchronous flows with explicit guards and await prerequisites before proceeding.

Low
  • Update

@sensei-hacker sensei-hacker force-pushed the github-action-pr-branch-suggestion branch from 761f168 to dc14163 Compare November 30, 2025 08:27
@sensei-hacker sensei-hacker merged commit 4618245 into iNavFlight:master Nov 30, 2025
6 checks passed
Comment on lines +19 to +37
const comment = `### Branch Targeting Suggestion

You've targeted the \`master\` branch with this PR. Please consider if a version branch might be more appropriate:

- **\`maintenance-9.x\`** - If your change is backward-compatible and won't create compatibility issues between INAV firmware and Configurator 9.x versions. This will allow your PR to be included in the next 9.x release.

- **\`maintenance-10.x\`** - If your change introduces compatibility requirements between firmware and configurator that would break 9.x compatibility. This is for PRs which will be included in INAV 10.x

If \`master\` is the correct target for this change, no action is needed.

---
*This is an automated suggestion to help route contributions to the appropriate branch.*`;

github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: comment
});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion: Prevent posting duplicate comments

Suggested change
const comment = `### Branch Targeting Suggestion
You've targeted the \`master\` branch with this PR. Please consider if a version branch might be more appropriate:
- **\`maintenance-9.x\`** - If your change is backward-compatible and won't create compatibility issues between INAV firmware and Configurator 9.x versions. This will allow your PR to be included in the next 9.x release.
- **\`maintenance-10.x\`** - If your change introduces compatibility requirements between firmware and configurator that would break 9.x compatibility. This is for PRs which will be included in INAV 10.x
If \`master\` is the correct target for this change, no action is needed.
---
*This is an automated suggestion to help route contributions to the appropriate branch.*`;
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: comment
});
const body = `### Branch Targeting Suggestion
You've targeted the \`master\` branch with this PR. Please consider if a version branch might be more appropriate:
- **\`maintenance-9.x\`** - If your change is backward-compatible and won't create compatibility issues between INAV firmware and Configurator 9.x versions. This will allow your PR to be included in the next 9.x release.
- **\`maintenance-10.x\`** - If your change introduces compatibility requirements between firmware and configurator that would break 9.x compatibility. This is for PRs which will be included in INAV 10.x
If \`master\` is the correct target for this change, no action is needed.
---
*This is an automated suggestion to help route contributions to the appropriate branch.*`;
const { data: comments } = await github.rest.issues.listComments({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
});
const botComment = comments.find(comment => {
return comment.user.type === 'Bot' && comment.body.includes('Branch Targeting Suggestion')
});
if (botComment) {
console.log('Suggestion comment already exists.');
return;
}
await github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: body
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant