Skip to content

[code-simplifier] refactor: simplify generateCustomJobToolDefinition and extractDispatchWorkflowNames#20107

Merged
pelikhan merged 1 commit intomainfrom
code-simplifier/2026-03-08-74bbb339c80b1a6d
Mar 8, 2026
Merged

[code-simplifier] refactor: simplify generateCustomJobToolDefinition and extractDispatchWorkflowNames#20107
pelikhan merged 1 commit intomainfrom
code-simplifier/2026-03-08-74bbb339c80b1a6d

Conversation

@github-actions
Copy link
Contributor

@github-actions github-actions bot commented Mar 8, 2026

This PR simplifies two functions added or moved in recent PRs (#20080, #19965), applying Go best practices and project conventions for clarity.

Files Simplified

Improvements Made

generateCustomJobToolDefinition

  1. Removed unnecessary guardif len(jobConfig.Inputs) > 0 { ... } is not needed; ranging over a nil/empty map is a safe no-op in Go. Removing it reduces nesting by one level.

  2. Merged duplicate switch casescase "string", "": and default: both set property["type"] = "string". Merged into a single default: with a clearer comment.

  3. Inlined additionalProperties: false into the map literal where the schema is initialised, keeping all schema defaults together.

  4. Return the tool map at the point of return instead of building it at the top and mutating it through the function — clearer data flow.

  5. Removed obvious inline comments that restate what the code already expresses (e.g. // Build the tool definition, // Track required fields, // Add description if present), per project style: "Only comment code that needs a bit of clarification."

extractDispatchWorkflowNames

  1. Combined two-step existence + type assertion for safe-outputs into a single comma-ok type assertion (nil map key returns nil, false in comma-ok form).

  2. Inlined the filter into the collection loops — the separate post-collection filter loop is eliminated by adding !strings.Contains(name, "$\{\{") to the guard inside each case branch.

  3. Simplified nested existence + type assertion for v["workflows"] into a direct comma-ok type assertion, removing a level of nesting.

Testing

  • ✅ All targeted tests pass (TestGenerateCustomJobToolDefinition*, TestExtractDispatchWorkflowNames_*)
  • ✅ Full unit test suite passes (make test-unit)
  • ✅ Build succeeds (make build)
  • ✅ No functional changes — behaviour is identical

Changes Based On


Automated by Code Simplifier Agent — analysing code from the last 24 hours

Generated by Code Simplifier ·

  • expires on Mar 9, 2026, 7:00 PM UTC

…hWorkflowNames

- Remove redundant `if len(jobConfig.Inputs) > 0` guard (ranging over nil map is safe)
- Merge duplicate `case "string", ""` and `default:` switch branches into single `default:`
- Move `additionalProperties: false` into the inputSchema map literal
- Build tool return map at the point of return instead of mutating across the function
- Remove obvious inline comments that repeat what the code already says
- Inline the filter loop in extractDispatchWorkflowNames into the collection loop
- Combine two-step map existence check + type assertion into a single comma-ok assertion

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@pelikhan
Copy link
Contributor

pelikhan commented Mar 8, 2026

@copilot recompile

Copy link
Contributor

Copilot AI commented Mar 8, 2026

@copilot recompile

Ran make recompile — all 166 workflow files compiled successfully with no changes to the lock files (they were already up to date).

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • https://api.github.com/graphql
    • Triggering command: /usr/bin/gh /usr/bin/gh api graphql -f query=query($owner: String!, $name: String!) { repository(owner: $owner, name: $name) { hasDiscussionsEnabled } } -f owner=github -f name=gh-aw (http block)
  • https://api.github.com/repos/astral-sh/setup-uv/git/ref/tags/eac588ad8def6316056a12d4907a9d4d84ff7a3b
    • Triggering command: /usr/bin/gh gh api /repos/astral-sh/setup-uv/git/ref/tags/eac588ad8def6316056a12d4907a9d4d84ff7a3b --jq .object.sha (http block)
  • https://api.github.com/repos/github/gh-aw/git/ref/tags/a70c5eada06553e3510ac27f2c3bda9d3705bccb
    • Triggering command: /usr/bin/gh gh api /repos/github/gh-aw/git/ref/tags/a70c5eada06553e3510ac27f2c3bda9d3705bccb --jq .object.sha (http block)
  • https://api.github.com/repos/githubnext/agentics/git/ref/tags/
    • Triggering command: /usr/bin/gh gh api /repos/githubnext/agentics/git/ref/tags/# --jq .object.sha (http block)

If you need me to access, download, or install something from one of these locations, you can either:

@pelikhan pelikhan merged commit f1073c5 into main Mar 8, 2026
1 check passed
@pelikhan pelikhan deleted the code-simplifier/2026-03-08-74bbb339c80b1a6d branch March 8, 2026 20:21
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.

2 participants