Skip to content

Commit eccbb45

Browse files
committed
Create a new model CodeCommit
Signed-off-by: ziad hany <ziadhany2016@gmail.com>
1 parent 8c001a1 commit eccbb45

File tree

2 files changed

+123
-0
lines changed

2 files changed

+123
-0
lines changed
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
# Generated by Django 4.2.22 on 2025-10-30 23:37
2+
3+
from django.db import migrations, models
4+
5+
6+
class Migration(migrations.Migration):
7+
8+
dependencies = [
9+
("vulnerabilities", "0102_alter_impactedpackage_affecting_vers_and_more"),
10+
]
11+
12+
operations = [
13+
migrations.CreateModel(
14+
name="CodeCommit",
15+
fields=[
16+
(
17+
"id",
18+
models.AutoField(
19+
auto_created=True, primary_key=True, serialize=False, verbose_name="ID"
20+
),
21+
),
22+
(
23+
"commit_hash",
24+
models.CharField(
25+
help_text="Unique commit identifier (e.g., SHA).", max_length=64
26+
),
27+
),
28+
(
29+
"vcs_url",
30+
models.URLField(help_text="URL of the repository containing the commit."),
31+
),
32+
(
33+
"commit_rank",
34+
models.IntegerField(
35+
default=0,
36+
help_text="Rank of the commit to support ordering by commit. Rank zero means the rank has not been defined yet",
37+
),
38+
),
39+
(
40+
"commit_author",
41+
models.CharField(
42+
blank=True, help_text="Author of the commit.", max_length=100, null=True
43+
),
44+
),
45+
(
46+
"commit_date",
47+
models.DateTimeField(
48+
blank=True,
49+
help_text="Timestamp indicating when this commit was created.",
50+
null=True,
51+
),
52+
),
53+
(
54+
"commit_message",
55+
models.TextField(
56+
blank=True, help_text="Commit message or description.", null=True
57+
),
58+
),
59+
],
60+
options={
61+
"unique_together": {("commit_hash", "vcs_url")},
62+
},
63+
),
64+
migrations.AddField(
65+
model_name="impactedpackage",
66+
name="affecting_commits",
67+
field=models.ManyToManyField(
68+
help_text="Commits introducing this impact.",
69+
related_name="affecting_commits_in_impacts",
70+
to="vulnerabilities.codecommit",
71+
),
72+
),
73+
migrations.AddField(
74+
model_name="impactedpackage",
75+
name="fixed_by_commits",
76+
field=models.ManyToManyField(
77+
help_text="Commits fixing this impact.",
78+
related_name="fixing_commits_in_impacts",
79+
to="vulnerabilities.codecommit",
80+
),
81+
),
82+
]

vulnerabilities/models.py

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2957,6 +2957,18 @@ class ImpactedPackage(models.Model):
29572957
help_text="Packages vulnerable to this impact.",
29582958
)
29592959

2960+
affecting_commits = models.ManyToManyField(
2961+
"CodeCommit",
2962+
related_name="affecting_commits_in_impacts",
2963+
help_text="Commits introducing this impact.",
2964+
)
2965+
2966+
fixed_by_commits = models.ManyToManyField(
2967+
"CodeCommit",
2968+
related_name="fixing_commits_in_impacts",
2969+
help_text="Commits fixing this impact.",
2970+
)
2971+
29602972
created_at = models.DateTimeField(
29612973
auto_now_add=True,
29622974
db_index=True,
@@ -3373,3 +3385,32 @@ class AdvisoryExploit(models.Model):
33733385
@property
33743386
def get_known_ransomware_campaign_use_type(self):
33753387
return "Known" if self.known_ransomware_campaign_use else "Unknown"
3388+
3389+
3390+
class CodeCommit(models.Model):
3391+
"""
3392+
A CodeCommit Represents a single VCS commit (e.g., Git) related to a ImpactedPackage.
3393+
"""
3394+
3395+
commit_hash = models.CharField(max_length=64, help_text="Unique commit identifier (e.g., SHA).")
3396+
vcs_url = models.URLField(
3397+
max_length=200, help_text="URL of the repository containing the commit."
3398+
)
3399+
3400+
commit_rank = models.IntegerField(
3401+
default=0,
3402+
help_text="Rank of the commit to support ordering by commit. Rank "
3403+
"zero means the rank has not been defined yet",
3404+
)
3405+
commit_author = models.CharField(
3406+
max_length=100, null=True, blank=True, help_text="Author of the commit."
3407+
)
3408+
commit_date = models.DateTimeField(
3409+
null=True, blank=True, help_text="Timestamp indicating when this commit was created."
3410+
)
3411+
commit_message = models.TextField(
3412+
null=True, blank=True, help_text="Commit message or description."
3413+
)
3414+
3415+
class Meta:
3416+
unique_together = ("commit_hash", "vcs_url")

0 commit comments

Comments
 (0)