You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@allura.apache.org by di...@apache.org on 2022/09/22 20:42:07 UTC

[allura] branch gc/8463 updated: fixup! fixup! fixup! [#8463] added basic resp endpoint to store commit statuses

This is an automated email from the ASF dual-hosted git repository.

dill0wn pushed a commit to branch gc/8463
in repository https://gitbox.apache.org/repos/asf/allura.git


The following commit(s) were added to refs/heads/gc/8463 by this push:
     new 492f0ad42 fixup! fixup! fixup! [#8463] added basic resp endpoint to store commit statuses
492f0ad42 is described below

commit 492f0ad42c49c036df06f2d559d66760948c8e42
Author: Dillon Walls <di...@slashdotmedia.com>
AuthorDate: Thu Sep 22 20:41:53 2022 +0000

    fixup! fixup! fixup! [#8463] added basic resp endpoint to store commit statuses
---
 Allura/allura/model/repository.py | 19 ++++++++-----------
 1 file changed, 8 insertions(+), 11 deletions(-)

diff --git a/Allura/allura/model/repository.py b/Allura/allura/model/repository.py
index 91efca2f1..737389095 100644
--- a/Allura/allura/model/repository.py
+++ b/Allura/allura/model/repository.py
@@ -32,7 +32,6 @@ from six.moves.urllib.parse import urljoin
 from threading import Thread
 from six.moves.queue import Queue
 from itertools import chain, islice
-from difflib import SequenceMatcher
 import typing
 
 import tg
@@ -45,7 +44,7 @@ import bson
 import six
 
 from ming import schema as S
-from ming.orm import session, state
+from ming.orm import session
 from ming import Field, collection, Index
 from ming.utils import LazyProperty
 from ming.odm import FieldProperty, session, Mapper, mapper, MappedClass, RelationProperty
@@ -1043,6 +1042,7 @@ CommitDoc = collection(
     Field('child_ids', [str], index=True),
     Field('repo_ids', [S.ObjectId()], index=True))
 
+
 class CommitStatus(MappedClass):
     class __mongometa__:
         session = repository_orm_session
@@ -1065,15 +1065,12 @@ class CommitStatus(MappedClass):
 
     @classmethod
     def upsert(cls, **kw):
-        obj = cls.query.get(commit_id=kw.get('commit_id'), context=kw.get('context'))
-        if obj is not None:
-            return obj
-        try:
-            obj = cls(**kw)
-            session(obj).flush(obj)
-        except pymongo.errors.DuplicateKeyError:
-            session(obj).expunge(obj)
-            obj = cls.query.get(**kw)
+        obj = cls.query.find_and_modify(
+            query=dict(commit_id=kw.get('commit_id'), context=kw.get('context')),
+            update={'$set': kw},
+            new=True,
+            upsert=True,
+        )
         return obj