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 ebdd0ef0e fixup! fixup! [#8463] added basic resp endpoint to store 
commit statuses
ebdd0ef0e is described below

commit ebdd0ef0eb20c0c122823d1928588d80b3b4447e
Author: Guillermo Cruz <[email protected]>
AuthorDate: Wed Sep 21 16:41:11 2022 -0600

    fixup! fixup! [#8463] added basic resp endpoint to store commit statuses
---
 Allura/allura/controllers/repository.py |  2 ++
 Allura/allura/lib/app_globals.py        |  4 ++++
 Allura/allura/model/repository.py       | 16 +++++++++-------
 Allura/development.ini                  |  4 ++++
 4 files changed, 19 insertions(+), 7 deletions(-)

diff --git a/Allura/allura/controllers/repository.py 
b/Allura/allura/controllers/repository.py
index 1f302a55a..0dae4b49f 100644
--- a/Allura/allura/controllers/repository.py
+++ b/Allura/allura/controllers/repository.py
@@ -363,6 +363,8 @@ class RepoRestController(RepoRootController, 
AppRestControllerMixin):
             ]}
     @expose('json:')
     def commit_status(self, rev=None, **kwargs):
+        if not g.commit_statuses_enabled:
+            return {'status': 'disabled', 'message': 'check your config file'}
         params = {x : kwargs.get(x, '').strip() for x in
                                                    ['state', 'target_url', 
'description', 'context']}
         params['commit_id'] = rev
diff --git a/Allura/allura/lib/app_globals.py b/Allura/allura/lib/app_globals.py
index 4ec209205..65279bbca 100644
--- a/Allura/allura/lib/app_globals.py
+++ b/Allura/allura/lib/app_globals.py
@@ -658,6 +658,10 @@ class Globals:
             "image_height": logo['image_height']
         }
 
+    @property
+    def commit_statuses_enabled(self):
+        return asbool(config['scm.commit_statuses'])
+
 class Icon:
 
     def __init__(self, css, title=None):
diff --git a/Allura/allura/model/repository.py 
b/Allura/allura/model/repository.py
index 8619c65a1..91efca2f1 100644
--- a/Allura/allura/model/repository.py
+++ b/Allura/allura/model/repository.py
@@ -1047,7 +1047,7 @@ class CommitStatus(MappedClass):
     class __mongometa__:
         session = repository_orm_session
         name = 'commit_status'
-        indexes = ['commit_id']
+        indexes = [('commit_id', 'context'),]
 
     query: 'Query[CommitStatus]'
 
@@ -1065,13 +1065,15 @@ class CommitStatus(MappedClass):
 
     @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.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).insert_now(obj, state(obj))
-        else:
-            obj.state = kw.get('state')
-            obj.description = kw.get('description')
+            session(obj).flush(obj)
+        except pymongo.errors.DuplicateKeyError:
+            session(obj).expunge(obj)
+            obj = cls.query.get(**kw)
         return obj
 
 
diff --git a/Allura/development.ini b/Allura/development.ini
index 4ddbc0c1b..2a13baef9 100644
--- a/Allura/development.ini
+++ b/Allura/development.ini
@@ -449,6 +449,10 @@ scm.view.max_diff_bytes = 2000000
 ; Max size for download a raw file from a repo
 scm.download.max_file_bytes = 30000000
 
+; Commit Status Support
+scm.commit_statuses = false
+
+
 ; bulk_export_enabled = true
 ; If you keep bulk_export_enabled, you should set up your server to securely 
share bulk_export_path with users somehow
 bulk_export_path = /tmp/bulk_export/{nbhd}/{project}

Reply via email to