This is an automated email from the ASF dual-hosted git repository. brondsem pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/allura.git
commit 6b8d4cd415912246a3f4a7600f83bf66dae975ea Author: Dave Brondsema <dbronds...@slashdotmedia.com> AuthorDate: Fri Mar 25 20:05:58 2022 +0000 [#5593] cleanup, test, index commits from root-to-latest (makes test work, makes sense) --- Allura/allura/model/repo_refresh.py | 24 +++++++++--------------- ForgeGit/forgegit/tests/model/test_repository.py | 12 ++++++++++++ 2 files changed, 21 insertions(+), 15 deletions(-) diff --git a/Allura/allura/model/repo_refresh.py b/Allura/allura/model/repo_refresh.py index 9581876..da7d816 100644 --- a/Allura/allura/model/repo_refresh.py +++ b/Allura/allura/model/repo_refresh.py @@ -16,31 +16,23 @@ # under the License. import logging -from itertools import chain from six.moves.cPickle import dumps -from collections import OrderedDict import bson -import re - import tg import jinja2 from paste.deploy.converters import asint from tg import tmpl_context as c, app_globals as g -from ming.base import Object from ming.orm import mapper, session, ThreadLocalORMSession from ming.odm.base import ObjectState, state from allura.lib import utils -from allura.lib import helpers as h from allura.lib.search import find_shortlinks from allura.model.repository import Commit, CommitDoc from allura.model.index import ArtifactReference, Shortlink from allura.model.auth import User from allura.model.timeline import TransientActor -from allura.model.project import AppConfig -import six log = logging.getLogger(__name__) @@ -51,7 +43,7 @@ def refresh_repo(repo, all_commits=False, notify=True, new_clone=False, commits_ if commits_are_new is None: commits_are_new = not all_commits and not new_clone - all_commit_ids = commit_ids = list(repo.all_commit_ids()) + all_commit_ids = commit_ids = list(repo.all_commit_ids())[::-1] # start with oldest if not commit_ids: # the repo is empty, no need to continue return @@ -122,16 +114,19 @@ def refresh_repo(repo, all_commits=False, notify=True, new_clone=False, commits_ # Send notifications if notify: - send_notifications(repo, reversed(commit_ids)) + send_notifications(repo, commit_ids) -def update_artifact_refs(commit, commit_ref, project_id): +def update_artifact_refs(commit, commit_ref): + # very similar to add_artifacts() but works for Commit objects which aren't Artifacts + if not commit.message: + return shortlinks = find_shortlinks(commit.message) for link in shortlinks: artifact_ref = ArtifactReference.query.get(_id=link.ref_id) - if (artifact_ref) and (commit_ref._id not in artifact_ref.references): + if artifact_ref and commit_ref._id not in artifact_ref.references: artifact_ref.references.append(commit_ref._id) - log.info('Artifact references updated successfully') + log.info(f'Artifact references updated successfully {commit_ref._id} mentioned {link.ref_id}') def refresh_commit_repos(all_commit_ids, repo): @@ -171,8 +166,7 @@ def refresh_commit_repos(all_commit_ids, repo): url=repo.url_for_commit(oid)) ci.m.save(validate=False) - project_id = repo.app.config.project_id - update_artifact_refs(ci, ref, project_id) + update_artifact_refs(ci, ref) # set to 'dirty' to force save() to be used instead of insert() (which errors if doc exists in db already) state(ref).status = ObjectState.dirty diff --git a/ForgeGit/forgegit/tests/model/test_repository.py b/ForgeGit/forgegit/tests/model/test_repository.py index 7031286..9fb8862 100644 --- a/ForgeGit/forgegit/tests/model/test_repository.py +++ b/ForgeGit/forgegit/tests/model/test_repository.py @@ -483,6 +483,18 @@ By Dave Brondsema''', text_body) <p>By Dave Brondsema''', html_body) + def test_commit_artifact_references(self): + self._setup_weird_chars_repo() + # commits aren't artifacts :/ but still can do some references with them + # commit b85dfbe message mentions [616d24f8dd4e95cadd8e93df5061f09855d1a066] + ref = M.ArtifactReference.query.get(_id='allura.model.repository.Commit#616d24f8dd4e95cadd8e93df5061f09855d1a066') + assert ref + assert 'b85dfbe' in ref.references[0], ref.references + + otherway = M.ArtifactReference.query.get(_id='allura.model.repository.Commit#b85dfbec3a5d08677bdd402fc0338934f623a234') + assert otherway + assert not otherway.references + def test_tarball(self): tmpdir = tg.config['scm.repos.tarball.root'] if os.path.isfile(os.path.join(tmpdir, "git/t/te/test/testgit.git/test-src-git-HEAD.zip")):