Skip to content
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

Enhancement: Apply Repository Settings on Every 'Synchronize' Event #511

Merged
merged 1 commit into from
Dec 11, 2023

Conversation

mrT23
Copy link
Collaborator

@mrT23 mrT23 commented Dec 7, 2023

Type

Enhancement


Description

This PR modifies the handling of the 'pull_request' event with 'synchronize' action in the 'github_app.py' file. The main changes include:

  • The application of repository settings is now triggered on every 'synchronize' event, not only when the 'handle_push_trigger' setting is enabled.
  • The 'handle_push_trigger' setting is now checked after applying the repository settings, and if it's not enabled, the function returns without further processing.

PR changes walkthrough

Relevant files                                                                                                                                 
Enhancement
1 files
github_app.py                                                                                             
    pr_agent/servers/github_app.py

    The 'handle_request' function has been updated to apply
    repository settings on every 'synchronize' event. The check
    for the 'handle_push_trigger' setting is now performed after
    applying the repository settings.
+5/-1

Copy link
Contributor

github-actions bot commented Dec 7, 2023

PR Analysis

(review updated until commit a043eb9)

  • 🎯 Main theme: Modifying the handling of the 'pull_request' event with 'synchronize' action in the 'github_app.py' file.
  • 📝 PR summary: This PR changes the handling of the 'pull_request' event with 'synchronize' action. Now, the repository settings are applied on every 'synchronize' event, not only when the 'handle_push_trigger' setting is enabled. The 'handle_push_trigger' setting is checked after applying the repository settings, and if it's not enabled, the function returns without further processing.
  • 📌 Type of PR: Enhancement
  • 🧪 Relevant tests added: No
  • ⏱️ Estimated effort to review [1-5]: 2, because the PR is small and the changes are straightforward, but it requires understanding of the existing codebase and the 'pull_request' event handling.
  • 🔒 Security concerns: No security concerns found

PR Feedback

  • 💡 General suggestions: It would be beneficial to add tests that verify the new behavior. This would ensure that the repository settings are indeed applied on every 'synchronize' event and that the function returns correctly when 'handle_push_trigger' is not enabled.

  • 🤖 Code feedback:
    relevant filepr_agent/servers/github_app.py
    suggestion      Consider handling the case where the 'apply_repo_settings' function fails. This could be done by wrapping the function call in a try-except block and logging any exceptions that occur. [important]
    relevant lineapply_repo_settings(api_url)

Copy link
Contributor

github-actions bot commented Dec 7, 2023

PR Code Suggestions

💡 Suggestion:

Consider checking the return value of apply_repo_settings(api_url) before proceeding.

File: pr_agent/servers/github_app.py (133-135)

Example code:

Existing code:

apply_repo_settings(api_url)
if not get_settings().github_app.handle_push_trigger:
    return {}

Improved code:

if not apply_repo_settings(api_url) or not get_settings().github_app.handle_push_trigger:
    return {}

💡 Suggestion:

Consider handling the case where before_sha or after_sha is None.

File: pr_agent/servers/github_app.py (138-139)

Example code:

Existing code:

before_sha = body.get("before")
after_sha = body.get("after")

Improved code:

before_sha = body.get("before")
after_sha = body.get("after")
if before_sha is None or after_sha is None:
    log_context.error("Missing 'before' or 'after' in the request body.")
    return {}

@mrT23
Copy link
Collaborator Author

mrT23 commented Dec 7, 2023

@zmeir @okotek
please take a look.

The issue raised in:
#504
is valid - on 'synchronize', we do not load the local configuration.
Hence, we will not trigger PR-Agent (unless the GithubApp itself was built with handle_push_trigger=true)

It's not ideal to read the configuration on every push. But currently the feature, and our instructions on the README, are not valid.
Can you think of a better way to enable this feature from local configuration file ?

@mrT23
Copy link
Collaborator Author

mrT23 commented Dec 7, 2023

/describe

@github-actions github-actions bot changed the title feat: Apply repo settings on push trigger in github_app.py Enhancement: Apply Repository Settings on Push Trigger Event Dec 7, 2023
@github-actions github-actions bot added the enhancement New feature or request label Dec 7, 2023
Copy link
Contributor

github-actions bot commented Dec 7, 2023

PR Description updated to latest commit (a043eb9)

@mrT23 mrT23 added the Bug fix label Dec 7, 2023
@mrT23 mrT23 changed the title Enhancement: Apply Repository Settings on Push Trigger Event Enhancement: Apply Repository Settings on Every 'Synchronize' Event Dec 7, 2023
@mrT23 mrT23 removed the Bug fix label Dec 7, 2023
@mrT23
Copy link
Collaborator Author

mrT23 commented Dec 7, 2023

PR Description updated to latest commit (a043eb9)

@zmeir
Copy link
Contributor

zmeir commented Dec 7, 2023

LGTM. I can't think of a cleaner way to handle this. The only other option I can think of is to just explicitly state in the README that this feature can only be enabled/disables via the global settings. But then what's the point of having it anyway?

@mrT23
Copy link
Collaborator Author

mrT23 commented Dec 10, 2023

Persistent review updated to latest commit a043eb9

1 similar comment
@mrT23
Copy link
Collaborator Author

mrT23 commented Dec 11, 2023

Persistent review updated to latest commit a043eb9

@mrT23 mrT23 merged commit cb64f92 into main Dec 11, 2023
5 checks passed
@mrT23 mrT23 deleted the tr/local_settings_on_push branch December 11, 2023 14:27
yochail pushed a commit to yochail/pr-agent that referenced this pull request Feb 11, 2024
…push

Enhancement: Apply Repository Settings on Every 'Synchronize' Event
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants