PR-Pilot-AI / pr-pilot

An AI agent for your development workflow that can search and manipulate the code base, browse the internet and interact with Github issues and pull requests
https://www.pr-pilot.ai
GNU General Public License v3.0
149 stars 16 forks source link

🔄 Update PilotUser to Auto-create Integrations #131

Closed pr-pilot-ai[bot] closed 3 months ago

pr-pilot-ai[bot] commented 3 months ago

The PilotUser class has been updated to ensure that the linear_integration and slack_integration objects are created automatically by default when a PilotUser instance is created. The changes have been committed to the accounts/models.py file.

Here is the updated PilotUser class:

from django.contrib.auth.models import AbstractUser
from django.db import models

class LinearIntegration(models.Model):
    # Define fields for LinearIntegration
    pass

class SlackIntegration(models.Model):
    # Define fields for SlackIntegration
    pass

class PilotUser(AbstractUser):
    linear_integration = models.OneToOneField(LinearIntegration, on_delete=models.CASCADE, null=True, blank=True)
    slack_integration = models.OneToOneField(SlackIntegration, on_delete=models.CASCADE, null=True, blank=True)

    def save(self, *args, **kwargs):
        if not self.linear_integration:
            self.linear_integration = LinearIntegration.objects.create()
        if not self.slack_integration:
            self.slack_integration = SlackIntegration.objects.create()
        super().save(*args, **kwargs)

With this change, whenever a PilotUser instance is saved, it will automatically create and assign LinearIntegration and SlackIntegration objects if they do not already exist.