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

Events outside the main branch should not trigger Event Rules #132

Open
PaulR282 opened this issue Sep 17, 2024 · 2 comments
Open

Events outside the main branch should not trigger Event Rules #132

PaulR282 opened this issue Sep 17, 2024 · 2 comments
Labels
app: branching type: feature A new feature or functionality

Comments

@PaulR282
Copy link

Plugin Version

v0.5.0

Proposed functionality

Events outside the main branch should not trigger Event Rules

Use case

A lot of network automation relies on event rules. If you plan e.g. a rebuild of a rack, where you update interfaces of a switch, you don't want those changes to be rolled out immediately. Only the changes on the main branch, like when merging a branch, should trigger the event rules.

External dependencies

No response

@PaulR282 PaulR282 added the type: feature A new feature or functionality label Sep 17, 2024
@mrmrcoleman
Copy link

mrmrcoleman commented Sep 18, 2024

Hey @PaulR282 we can't switch off Event Rules for branches because other users rely on webhooks from branches for their workflows.

One approach is to call the /api/plugins/branching/changes/ endpoint and check if the object is there. If it is, you know the change is on a branch, so you can ignore it for your use case.

def find_object_branch(object_id, model):
    changes_endpoint = f"{NETBOX_URL}/api/plugins/branching/changes/"
    params = {"object_id": object_id, "model": model}
    
    response = requests.get(changes_endpoint, headers=headers, params=params)
    
    if response.status_code == 200:
        changes = response.json().get("results", [])
        if not changes:
            return "main"  # Object was created or modified on the main branch
        else:
            for change in changes:
                branch = change.get("branch", {}).get("name", "main")
                return branch
    else:
        print(f"Error: {response.status_code} - {response.text}")
        return None

@PaulR282
Copy link
Author

Hi @mrmrcoleman. That would be one solution, thanks, I will try that. Alternatively, it would also be nice if you could configure whether branches trigger event rules or not.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
app: branching type: feature A new feature or functionality
Projects
None yet
Development

No branches or pull requests

4 participants