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

feat: Add Pull Request model and integrate with sync_repository #845

Open
wants to merge 22 commits into
base: main
Choose a base branch
from

Conversation

space-techy
Copy link
Collaborator

Resolves #825

Changes

  • Added PullRequest Model: Introduced a new model to store GitHub pull request data, including fields like title, body, state, author, repository, created_at, and merged_at.
  • Extended sync_repository: Integrated PR syncing logic to fetch and update pull requests using GitHub’s API.
  • Updated Django Admin: Registered the PullRequest model to enable management via the Django admin panel.
  • Improved Data Relationships: Established relationships between PRs and User, Repository, Labels, and Assignees.

This update enables automatic tracking and management of GitHub pull requests within OWASP Nest.

@space-techy space-techy force-pushed the feature/github-pull-request-tracking branch from e92aef2 to c56972a Compare February 15, 2025 22:33
@space-techy space-techy force-pushed the feature/github-pull-request-tracking branch from c56972a to 0aff313 Compare February 15, 2025 22:51
Copy link
Collaborator

@arkid15r arkid15r left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great PR, please look into these when you get a chance:

@space-techy space-techy force-pushed the feature/github-pull-request-tracking branch from 35bfb89 to 022555a Compare February 17, 2025 22:07
@space-techy space-techy force-pushed the feature/github-pull-request-tracking branch 2 times, most recently from ded2dc4 to 6f7b568 Compare February 19, 2025 08:36
@space-techy space-techy force-pushed the feature/github-pull-request-tracking branch from 6f7b568 to 181ec78 Compare February 19, 2025 08:47
@github-actions github-actions bot removed the makefile label Feb 19, 2025
@space-techy space-techy force-pushed the feature/github-pull-request-tracking branch from 181ec78 to ad3fe10 Compare February 20, 2025 03:21
@space-techy
Copy link
Collaborator Author

@arkid15r Please Don't Forget this PR!

Copy link
Collaborator

@arkid15r arkid15r left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have 2 suggestions to address before the merge:

  • DRY code for issues/prs
  • streamline PR sync process logic

@@ -83,6 +84,56 @@ def sync_repository(gh_repository, organization=None, user=None):
else:
logger.info("Skipping issues sync for %s", repository.name)

if not repository.is_archived and repository.project:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest applying the same logic we use for issues sync (see above). It fetches all states and has a cut off date if it's not the very first sync.

Copy link
Collaborator Author

@space-techy space-techy Feb 25, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are talking about that since argument passed to **kwargs in issue?
If you are then since is not available in PR!

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's try fetching PRs sorted by updated and break the loop when we see a date earlier than our latest_updated_at (if any)?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can sort by the created-at field to retrieve the earliest date after the first fetch is complete. For subsequent runs, we can use this date. If the closed pull request’s date is older than the stored date, we can simply skip it.

from apps.github.models.mixins import IssueIndexMixin


class PullRequest(BulkSaveModel, IssueIndexMixin, NodeModel, TimestampedModel):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Every PR is an issue according to GH docs. They have a lot of attributes in common. I think it'd be a good idea to use a base GenericIssueModel for both entities and extend them as needed.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ya it's a great Idea!
Let me check on it and inform you!

Copy link
Collaborator Author

@space-techy space-techy Feb 25, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also to confirm you want me to make a common model for both Pull request Model and Issues Model? And extend it?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, extract the common fields to GenericIssueModel abstract model.

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.

Add support for GitHub Pull Request entities
2 participants