This is an automated email from the ASF dual-hosted git repository.
gcruz 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 a245e6d15 fixup! [#8463] added basic resp endpoint to store commit
statuses
a245e6d15 is described below
commit a245e6d151c3448769f0616629867f5156492adf
Author: Guillermo Cruz <[email protected]>
AuthorDate: Mon Sep 19 16:30:47 2022 -0600
fixup! [#8463] added basic resp endpoint to store commit statuses
---
Allura/allura/controllers/repository.py | 8 ++++++--
Allura/allura/model/repository.py | 17 +++++++++++++++++
2 files changed, 23 insertions(+), 2 deletions(-)
diff --git a/Allura/allura/controllers/repository.py
b/Allura/allura/controllers/repository.py
index 96d0232fe..1f302a55a 100644
--- a/Allura/allura/controllers/repository.py
+++ b/Allura/allura/controllers/repository.py
@@ -365,8 +365,12 @@ class RepoRestController(RepoRootController,
AppRestControllerMixin):
def commit_status(self, rev=None, **kwargs):
params = {x : kwargs.get(x, '').strip() for x in
['state', 'target_url',
'description', 'context']}
- M.CommitStatus(params)
- return {"status": "success"}
+ params['commit_id'] = rev
+ status = M.CommitStatus.upsert(**params)
+ response = {'status': 'error'}
+ if status:
+ response['status'] = 'success'
+ return response
diff --git a/Allura/allura/model/repository.py
b/Allura/allura/model/repository.py
index 99a5be417..8619c65a1 100644
--- a/Allura/allura/model/repository.py
+++ b/Allura/allura/model/repository.py
@@ -45,6 +45,7 @@ import bson
import six
from ming import schema as S
+from ming.orm import session, state
from ming import Field, collection, Index
from ming.utils import LazyProperty
from ming.odm import FieldProperty, session, Mapper, mapper, MappedClass,
RelationProperty
@@ -1050,6 +1051,7 @@ class CommitStatus(MappedClass):
query: 'Query[CommitStatus]'
+ _id = FieldProperty(S.ObjectId)
state = FieldProperty(str)
target_url = FieldProperty(str)
description = FieldProperty(str)
@@ -1057,6 +1059,21 @@ class CommitStatus(MappedClass):
commit_id = FieldProperty(str)
commit = RelationProperty('Commit')
+ def __init__(self, **kw):
+ assert 'commit_id' in kw, 'Commit id missing'
+ super().__init__(**kw)
+
+ @classmethod
+ def upsert(cls, **kw):
+ obj = cls.query.find({'commit_id':kw.get('commit_id'), 'context':
kw.get('context')}).one()
+ if obj is None:
+ obj = cls(**kw)
+ session(obj).insert_now(obj, state(obj))
+ else:
+ obj.state = kw.get('state')
+ obj.description = kw.get('description')
+ return obj
+
class Commit(MappedClass, RepoObject, ActivityObject):
# Basic commit information