-
-
Notifications
You must be signed in to change notification settings - Fork 325
feat: add github comment leaderboard #5363
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
Open
mdkaifansari04
wants to merge
12
commits into
OWASP-BLT:main
Choose a base branch
from
mdkaifansari04:feat/github-comment-leaderboard
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
600853b
feat: add github comment model
mdkaifansari04 dc2f4ff
(feat+refactor): migrated schema, added github comment leaderboard lo…
mdkaifansari04 7164614
chore: updated migration
mdkaifansari04 438543f
refactor: fix the global leaderboard
mdkaifansari04 4117aab
refactor: update models
mdkaifansari04 40a47e1
chore: style changes
mdkaifansari04 3a8fcf5
fix: updated model and fix runtime issues
mdkaifansari04 3130c00
refactor: updated the user profile info
mdkaifansari04 40a86d5
chore: fix styles
mdkaifansari04 096a119
chore: style changes
mdkaifansari04 d960b1e
Merge branch 'main' into feat/github-comment-leaderboard
mdkaifansari04 d6654e2
chore: pre-commit fix and minor bug
mdkaifansari04 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| # Generated by Django 5.2.9 on 2025-12-24 13:49 | ||
|
|
||
| import django.db.models.deletion | ||
| from django.db import migrations, models | ||
|
|
||
|
|
||
| class Migration(migrations.Migration): | ||
| dependencies = [ | ||
| ("website", "0260_add_username_to_slackbotactivity"), | ||
| ] | ||
|
|
||
| operations = [ | ||
| migrations.CreateModel( | ||
| name="GitHubComment", | ||
| fields=[ | ||
| ("id", models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name="ID")), | ||
| ("comment_id", models.BigIntegerField(unique=True)), | ||
| ("body", models.TextField()), | ||
| ("comment_type", models.CharField(max_length=50)), | ||
| ("created_at", models.DateTimeField()), | ||
| ("updated_at", models.DateTimeField()), | ||
| ("url", models.URLField()), | ||
| ( | ||
| "contributor", | ||
| models.ForeignKey( | ||
| blank=True, | ||
| null=True, | ||
| on_delete=django.db.models.deletion.SET_NULL, | ||
| related_name="github_comments", | ||
| to="website.contributor", | ||
| ), | ||
| ), | ||
| ( | ||
| "github_issue", | ||
| models.ForeignKey( | ||
| on_delete=django.db.models.deletion.CASCADE, related_name="comments", to="website.githubissue" | ||
| ), | ||
| ), | ||
| ( | ||
| "repo", | ||
| models.ForeignKey( | ||
| blank=True, | ||
| null=True, | ||
| on_delete=django.db.models.deletion.SET_NULL, | ||
| related_name="github_comments", | ||
| to="website.repo", | ||
| ), | ||
| ), | ||
| ( | ||
| "user_profile", | ||
| models.ForeignKey( | ||
| blank=True, | ||
| null=True, | ||
| on_delete=django.db.models.deletion.SET_NULL, | ||
| related_name="github_comments", | ||
| to="website.userprofile", | ||
| ), | ||
| ), | ||
| ], | ||
| options={ | ||
| "ordering": ["-created_at"], | ||
| }, | ||
| ), | ||
| ] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,110 @@ | ||
| import json | ||
|
|
||
| from django.test import Client, TestCase | ||
| from django.urls import reverse | ||
|
|
||
| from website.models import GitHubComment, GitHubIssue, Repo, User, UserProfile | ||
|
|
||
|
|
||
| class GitHubCommentWebhookTest(TestCase): | ||
| def setUp(self): | ||
| self.client = Client() | ||
| self.webhook_url = reverse("github-webhook") | ||
| self.repo = Repo.objects.create(repo_url="https://github.com/owner/repo") | ||
| self.user = User.objects.create(username="testuser") | ||
| self.user_profile, created = UserProfile.objects.get_or_create( | ||
| user=self.user, defaults={"github_url": "https://github.com/testuser"} | ||
| ) | ||
| if not created: | ||
| self.user_profile.github_url = "https://github.com/testuser" | ||
| self.user_profile.save() | ||
| self.issue = GitHubIssue.objects.create( | ||
| issue_id=1, | ||
| repo=self.repo, | ||
| title="Test PR", | ||
| type="pull_request", | ||
| state="open", | ||
| created_at="2023-01-01T00:00:00Z", | ||
| updated_at="2023-01-01T00:00:00Z", | ||
| ) | ||
|
|
||
| def test_issue_comment_on_pr(self): | ||
| payload = { | ||
| "action": "created", | ||
| "issue": { | ||
| "number": 1, | ||
| "pull_request": {}, # Indicates it is a PR | ||
| }, | ||
| "comment": { | ||
| "id": 1001, | ||
| "body": "This is a comment", | ||
| "created_at": "2023-01-01T12:00:00Z", | ||
| "updated_at": "2023-01-01T12:00:00Z", | ||
| "html_url": "https://github.com/owner/repo/issues/1#issuecomment-1001", | ||
| }, | ||
| "repository": {"html_url": "https://github.com/owner/repo", "full_name": "owner/repo"}, | ||
| "sender": {"login": "testuser", "html_url": "https://github.com/testuser", "type": "User"}, | ||
| } | ||
| response = self.client.post( | ||
| self.webhook_url, | ||
| data=json.dumps(payload), | ||
| content_type="application/json", | ||
| HTTP_X_GITHUB_EVENT="issue_comment", | ||
| ) | ||
| self.assertEqual(response.status_code, 200) | ||
| self.assertTrue(GitHubComment.objects.filter(comment_id=1001).exists()) | ||
| comment = GitHubComment.objects.get(comment_id=1001) | ||
| self.assertEqual(comment.github_issue, self.issue) | ||
| self.assertEqual(comment.user_profile, self.user_profile) | ||
mdkaifansari04 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| def test_issue_comment_not_on_pr(self): | ||
| payload = { | ||
| "action": "created", | ||
| "issue": { | ||
| "number": 1, | ||
| # No pull_request key | ||
| }, | ||
| "comment": { | ||
| "id": 1002, | ||
| "body": "This is a comment on an issue", | ||
| "created_at": "2023-01-01T12:00:00Z", | ||
| "updated_at": "2023-01-01T12:00:00Z", | ||
| "html_url": "https://github.com/owner/repo/issues/1#issuecomment-1002", | ||
| }, | ||
| "repository": {"html_url": "https://github.com/owner/repo", "full_name": "owner/repo"}, | ||
| "sender": {"login": "testuser", "type": "User"}, | ||
| } | ||
| response = self.client.post( | ||
| self.webhook_url, | ||
| data=json.dumps(payload), | ||
| content_type="application/json", | ||
| HTTP_X_GITHUB_EVENT="issue_comment", | ||
| ) | ||
| self.assertEqual(response.status_code, 200) | ||
| self.assertFalse(GitHubComment.objects.filter(comment_id=1002).exists()) | ||
|
|
||
| def test_bot_comment_ignored(self): | ||
| payload = { | ||
| "action": "created", | ||
| "issue": { | ||
| "number": 1, | ||
| "pull_request": {}, | ||
| }, | ||
| "comment": { | ||
| "id": 1003, | ||
| "body": "I am a bot", | ||
| "created_at": "2023-01-01T12:00:00Z", | ||
| "updated_at": "2023-01-01T12:00:00Z", | ||
| "html_url": "https://github.com/owner/repo/issues/1#issuecomment-1003", | ||
| }, | ||
| "repository": {"html_url": "https://github.com/owner/repo", "full_name": "owner/repo"}, | ||
| "sender": {"login": "copilot", "type": "Bot", "id": 12345}, | ||
| } | ||
| response = self.client.post( | ||
| self.webhook_url, | ||
| data=json.dumps(payload), | ||
| content_type="application/json", | ||
| HTTP_X_GITHUB_EVENT="issue_comment", | ||
| ) | ||
| self.assertEqual(response.status_code, 200) | ||
| self.assertFalse(GitHubComment.objects.filter(comment_id=1003).exists()) | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.