Skip to content

Integrate cfbot pgarchives #1

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
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,11 @@ lint-fix-unsafe:
npx @biomejs/biome check --fix --unsafe

fix: format lint-fix-unsafe

init-dev:
dropdb --if-exists pgcommitfest
createdb pgcommitfest
./manage.py migrate
./manage.py loaddata auth_data.json
./manage.py loaddata minimal_data.json
./run_dev.py
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,17 @@ following command to create a super user:
./manage.py createsuperuser
```

#### Setup Patchburner
To experiment with local compiling and testing of patches setup the following:

```
mkdir {settings.LOCAL_PATCH_BURNER_DIR}
cd {settings.LOCAL_PATCH_BURNER_DIR}
mkdir template
cd template
git clone {some postgres repository - creates directory named "postgres"}
```

#### Start application
Finally, you're ready to start the application:

Expand Down
59 changes: 47 additions & 12 deletions pgcommitfest/commitfest/ajax.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import json
import re
import textwrap
from datetime import datetime

import requests

Expand Down Expand Up @@ -183,24 +184,58 @@ def deleteAnnotation(request):
return "OK"


def parse_and_add_attachments(threadinfo, mailthread):
def parse_and_add_attachments(threadinfo, mailthread, patch, user):
# Save the messageid containing the most recent patchset to both
# the thread it exists on and, among the threads, to the patch itself.
thread_patchset = None
# Sorted threads, oldest to newest, so capture the last one with a patch
for t in threadinfo:
if len(t["atts"]):
# One or more attachments. For now, we're only actually going
# to store and process the first one, even though the API gets
# us all of them.
MailThreadAttachment.objects.get_or_create(
for a in t["atts"]:
if a["is_patch"]:
thread_patchset = t

mta, created = MailThreadAttachment.objects.get_or_create(
mailthread=mailthread,
messageid=t["msgid"],
attachmentid=a["id"],
defaults={
"date": t["date"],
"author": t["from"],
"attachmentid": t["atts"][0]["id"],
"filename": t["atts"][0]["name"],
"filename": a["name"],
"ispatch": a["is_patch"],
"contenttype": a["content_type"],
},
)
# In theory we should remove objects if they don't have an
# attachment, but how could that ever happen? Ignore for now.
PatchHistory(
patch=patch,
by=user,
what="Linked attachment %s %s"
% (a["id"], "created" if created else "gotten"),
).save_and_notify()
PatchHistory(
patch=patch, by=user, what="Linked Message %s" % t["msgid"]
).save_and_notify()

if thread_patchset:
mailthread.patchsetmsgid = thread_patchset["msgid"]
mailthread.save()
PatchHistory(
patch=patch,
by=user,
what="New Thread Patch Set Message %s" % thread_patchset["msgid"],
).save_and_notify()

if patch.patchset_messageid != thread_patchset[
"msgid"
] or patch.patchset_messagedate > datetime.strptime(thread_patchset["date"]):
patch.patchset_messagedate = thread_patchset["date"]
patch.patchset_messageid = thread_patchset["msgid"]
patch.save()
PatchHistory(
patch=patch,
by=user,
what="Updated Patch Set Message Id to %s" % thread_patchset["msgid"],
).save_and_notify()


@transaction.atomic
Expand Down Expand Up @@ -249,15 +284,15 @@ def doAttachThread(cf, patch, msgid, user):
m.save()
m.patches.add(patch)
m.save()
parse_and_add_attachments(r, m)
thread = m

PatchHistory(
patch=patch, by=user, what="Attached mail thread %s" % r[0]["msgid"]
).save_and_notify()
patch.update_lastmail()
patch.set_modified()
patch.save()

parse_and_add_attachments(r, thread, patch, user)
return "OK"


Expand Down
Loading