-
Notifications
You must be signed in to change notification settings - Fork 15
fix: resolve repository analysis and PR creation issues #35
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,7 +9,6 @@ | |
| from __future__ import annotations | ||
|
|
||
| import logging | ||
| import textwrap | ||
| from typing import Any | ||
|
|
||
| import yaml | ||
|
|
@@ -258,7 +257,7 @@ def _default_recommendations( | |
| severity: medium | ||
| event_types: | ||
| - pull_request | ||
| parameters: | ||
| parameters: | ||
| source_patterns: | ||
| {source_patterns_yaml} | ||
| test_patterns: | ||
|
|
@@ -294,17 +293,14 @@ def _default_recommendations( | |
|
|
||
| recommendations.append( | ||
| RuleRecommendation( | ||
| yaml_rule=textwrap.dedent( | ||
| """ | ||
| description: "Ensure PRs include context" | ||
| yaml_rule="""description: "Ensure PRs include context" | ||
| enabled: true | ||
| severity: low | ||
| severity: low | ||
| event_types: | ||
| - pull_request | ||
| parameters: | ||
| min_description_length: 50 | ||
| """ | ||
| ).strip(), | ||
| parameters: | ||
| min_description_length: 50 | ||
| """.strip(), | ||
|
Comment on lines
+296
to
+303
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. While the YAML string is now correctly formatted, generating YAML by hardcoding multiline strings can be fragile and hard to maintain. A more robust approach is to define rules as Python dictionaries and then serialize them to YAML. This eliminates the risk of manual indentation or syntax errors. This would also simplify the overall flow, as you are currently creating a YAML string, which is then parsed back into a dictionary in Consider this alternative approach: import yaml
rule_dict = {
"description": "Ensure PRs include context",
"enabled": True,
"severity": "low",
"event_types": ["pull_request"],
"parameters": {
"min_description_length": 50,
},
}
recommendations.append(
RuleRecommendation(
yaml_rule=yaml.dump(rule_dict, sort_keys=False),
confidence=desc_confidence,
reasoning=desc_reasoning,
strategy_used="static",
)
)This would likely require adjusting |
||
| confidence=desc_confidence, | ||
| reasoning=desc_reasoning, | ||
| strategy_used="static", | ||
|
|
@@ -313,18 +309,15 @@ def _default_recommendations( | |
|
|
||
| # Add a repository-specific rule if we detect specific patterns | ||
| if state.repository_features.has_workflows: | ||
| workflow_rule = textwrap.dedent( | ||
| """ | ||
| description: "Protect CI/CD workflows" | ||
| workflow_rule = """description: "Protect CI/CD workflows" | ||
| enabled: true | ||
| severity: high | ||
| severity: high | ||
| event_types: | ||
| - pull_request | ||
| parameters: | ||
| file_patterns: | ||
| - ".github/workflows/**" | ||
| """ | ||
| ).strip() | ||
| parameters: | ||
| file_patterns: | ||
| - ".github/workflows/**" | ||
| """.strip() | ||
|
|
||
| recommendations.append( | ||
| RuleRecommendation( | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For security, sensitive values like tokens should be stored in Pydantic's
SecretStrtype to prevent them from being exposed in logs or other string representations of the model. You will need to addSecretStrto your pydantic imports.Additionally, this new
user_tokenfield is not currently being used in the agent's workflow. For it to be effective, it needs to be passed down throughRepositoryAnalysisStateto the variousgithub_clientAPI calls. This involves:user_tokentoRepositoryAnalysisState.RepositoryAnalysisAgent.execute.github_clientmethods in the analysis nodes.When accessing the token value from the
SecretStrfield, you'll need to use.get_secret_value().