2020-07-12 17:34:25 +02:00
|
|
|
# ContentDB
|
2021-01-29 18:17:51 +01:00
|
|
|
# Copyright (C) 2018-21 rubenwardy
|
2018-05-17 16:18:20 +02:00
|
|
|
#
|
|
|
|
# This program is free software: you can redistribute it and/or modify
|
2021-01-30 17:59:42 +01:00
|
|
|
# it under the terms of the GNU Affero General Public License as published by
|
2018-05-17 16:18:20 +02:00
|
|
|
# the Free Software Foundation, either version 3 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
2021-01-30 17:59:42 +01:00
|
|
|
# GNU Affero General Public License for more details.
|
2018-05-17 16:18:20 +02:00
|
|
|
#
|
2021-01-30 17:59:42 +01:00
|
|
|
# You should have received a copy of the GNU Affero General Public License
|
2018-05-17 16:18:20 +02:00
|
|
|
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
|
2021-01-30 02:20:38 +01:00
|
|
|
import os, git, tempfile, shutil, gitdb, contextlib, datetime
|
2018-06-05 20:47:02 +02:00
|
|
|
from git import GitCommandError
|
2020-01-19 01:28:26 +01:00
|
|
|
from git_archive_all import GitArchiver
|
2018-05-15 20:35:59 +02:00
|
|
|
from urllib.error import HTTPError
|
2018-05-11 13:57:16 +02:00
|
|
|
import urllib.request
|
2020-12-04 03:23:04 +01:00
|
|
|
from urllib.parse import urlsplit
|
2020-01-19 02:37:15 +01:00
|
|
|
from zipfile import ZipFile
|
2020-12-15 20:05:29 +01:00
|
|
|
|
|
|
|
from kombu import uuid
|
|
|
|
|
2018-05-11 13:57:16 +02:00
|
|
|
from app.models import *
|
2018-05-14 02:20:02 +02:00
|
|
|
from app.tasks import celery, TaskError
|
2021-01-30 18:10:38 +01:00
|
|
|
from app.utils import randomString, getExtension, post_bot_message, addSystemNotification, addSystemAuditLog
|
2020-01-19 02:22:33 +01:00
|
|
|
from .minetestcheck import build_tree, MinetestCheckError, ContentType
|
2018-05-12 19:50:09 +02:00
|
|
|
|
2020-08-18 17:12:27 +02:00
|
|
|
|
2018-06-07 23:32:17 +02:00
|
|
|
def generateGitURL(urlstr):
|
|
|
|
scheme, netloc, path, query, frag = urlsplit(urlstr)
|
|
|
|
|
|
|
|
return "http://:@" + netloc + path + query
|
2018-06-05 01:10:47 +02:00
|
|
|
|
2020-01-19 02:37:15 +01:00
|
|
|
|
2020-12-03 22:07:42 +01:00
|
|
|
@contextlib.contextmanager
|
2020-12-14 22:05:56 +01:00
|
|
|
def get_temp_dir():
|
2020-12-03 22:07:42 +01:00
|
|
|
temp = os.path.join(tempfile.gettempdir(), randomString(10))
|
|
|
|
yield temp
|
|
|
|
shutil.rmtree(temp)
|
2020-01-19 02:37:15 +01:00
|
|
|
|
|
|
|
|
2018-06-06 00:13:39 +02:00
|
|
|
# Clones a repo from an unvalidated URL.
|
|
|
|
# Returns a tuple of path and repo on sucess.
|
|
|
|
# Throws `TaskError` on failure.
|
|
|
|
# Caller is responsible for deleting returned directory.
|
2020-12-03 22:07:42 +01:00
|
|
|
@contextlib.contextmanager
|
2020-12-14 22:05:56 +01:00
|
|
|
def clone_repo(urlstr, ref=None, recursive=False):
|
2020-12-03 22:07:42 +01:00
|
|
|
gitDir = os.path.join(tempfile.gettempdir(), randomString(10))
|
2018-06-05 20:47:02 +02:00
|
|
|
|
|
|
|
err = None
|
|
|
|
try:
|
2018-06-07 23:32:17 +02:00
|
|
|
gitUrl = generateGitURL(urlstr)
|
|
|
|
print("Cloning from " + gitUrl)
|
2019-09-15 19:30:42 +02:00
|
|
|
|
|
|
|
if ref is None:
|
2020-12-04 03:23:04 +01:00
|
|
|
repo = git.Repo.clone_from(gitUrl, gitDir,
|
2019-09-15 19:30:42 +02:00
|
|
|
progress=None, env=None, depth=1, recursive=recursive, kill_after_timeout=15)
|
|
|
|
else:
|
2020-12-14 22:05:56 +01:00
|
|
|
assert ref != ""
|
|
|
|
|
2020-01-25 02:07:39 +01:00
|
|
|
repo = git.Repo.init(gitDir)
|
|
|
|
origin = repo.create_remote("origin", url=gitUrl)
|
|
|
|
assert origin.exists()
|
|
|
|
origin.fetch()
|
2020-12-14 22:05:56 +01:00
|
|
|
repo.git.checkout(ref)
|
2018-06-07 23:32:17 +02:00
|
|
|
|
2020-03-27 16:23:18 +01:00
|
|
|
for submodule in repo.submodules:
|
|
|
|
submodule.update(init=True)
|
|
|
|
|
2020-12-03 22:07:42 +01:00
|
|
|
yield repo
|
|
|
|
shutil.rmtree(gitDir)
|
|
|
|
return
|
2019-08-31 23:09:19 +02:00
|
|
|
|
2018-06-05 20:47:02 +02:00
|
|
|
except GitCommandError as e:
|
2018-06-05 23:34:57 +02:00
|
|
|
# This is needed to stop the backtrace being weird
|
2018-06-05 20:47:02 +02:00
|
|
|
err = e.stderr
|
|
|
|
|
2019-08-31 23:09:19 +02:00
|
|
|
except gitdb.exc.BadName as e:
|
|
|
|
err = "Unable to find the reference " + (ref or "?") + "\n" + e.stderr
|
|
|
|
|
2018-06-06 00:13:39 +02:00
|
|
|
raise TaskError(err.replace("stderr: ", "") \
|
|
|
|
.replace("Cloning into '" + gitDir + "'...", "") \
|
|
|
|
.strip())
|
2018-06-05 01:10:47 +02:00
|
|
|
|
2020-07-12 03:22:35 +02:00
|
|
|
|
2021-01-29 18:17:51 +01:00
|
|
|
def get_commit_hash(git_url, ref_name=None):
|
2021-01-29 21:01:48 +01:00
|
|
|
git_url = generateGitURL(git_url)
|
|
|
|
|
2020-12-15 23:20:40 +01:00
|
|
|
if ref_name:
|
2021-01-29 18:17:51 +01:00
|
|
|
ref_name = "refs/heads/" + ref_name
|
2020-12-15 23:20:40 +01:00
|
|
|
else:
|
2021-01-29 18:17:51 +01:00
|
|
|
ref_name = "HEAD"
|
|
|
|
|
|
|
|
g = git.cmd.Git()
|
|
|
|
|
|
|
|
remote_refs = {}
|
|
|
|
for ref in g.ls_remote(git_url).split('\n'):
|
|
|
|
hash_ref_list = ref.split('\t')
|
|
|
|
remote_refs[hash_ref_list[1]] = hash_ref_list[0]
|
2020-12-15 20:05:29 +01:00
|
|
|
|
2021-01-29 18:17:51 +01:00
|
|
|
return remote_refs.get(ref_name)
|
2020-12-15 20:05:29 +01:00
|
|
|
|
|
|
|
|
2021-01-29 23:20:44 +01:00
|
|
|
def get_latest_tag(git_url):
|
|
|
|
with get_temp_dir() as git_dir:
|
|
|
|
repo = git.Repo.init(git_dir)
|
|
|
|
origin = repo.create_remote("origin", url=git_url)
|
|
|
|
origin.fetch()
|
|
|
|
|
|
|
|
refs = repo.git.ls_remote(tags=True, sort="creatordate").split('\n')
|
2021-01-31 00:41:31 +01:00
|
|
|
refs = [ref for ref in refs if ref.strip() != ""]
|
2021-01-29 23:20:44 +01:00
|
|
|
if len(refs) == 0:
|
2021-01-31 12:24:04 +01:00
|
|
|
return None, None
|
2021-01-29 23:20:44 +01:00
|
|
|
|
|
|
|
last_ref = refs[-1]
|
|
|
|
hash_ref_list = last_ref.split('\t')
|
|
|
|
|
|
|
|
tag = hash_ref_list[1].replace("refs/tags/", "")
|
|
|
|
commit_hash = repo.git.rev_parse(tag + "^{}")
|
|
|
|
return tag, commit_hash
|
|
|
|
|
|
|
|
|
2018-06-05 23:34:57 +02:00
|
|
|
@celery.task()
|
|
|
|
def getMeta(urlstr, author):
|
2020-12-14 22:05:56 +01:00
|
|
|
with clone_repo(urlstr, recursive=True) as repo:
|
2020-12-03 22:07:42 +01:00
|
|
|
try:
|
|
|
|
tree = build_tree(repo.working_tree_dir, author=author, repo=urlstr)
|
|
|
|
except MinetestCheckError as err:
|
|
|
|
raise TaskError(str(err))
|
2020-01-19 02:22:33 +01:00
|
|
|
|
2020-12-04 03:23:04 +01:00
|
|
|
result = {"name": tree.name, "provides": tree.getModNames(), "type": tree.type.name}
|
2018-06-05 20:47:02 +02:00
|
|
|
|
2020-12-03 22:07:42 +01:00
|
|
|
for key in ["depends", "optional_depends"]:
|
|
|
|
result[key] = tree.fold("meta", key)
|
2018-05-27 23:03:54 +02:00
|
|
|
|
2020-12-03 22:07:42 +01:00
|
|
|
for key in ["title", "repo", "issueTracker", "forumId", "description", "short_description"]:
|
|
|
|
result[key] = tree.get(key)
|
2018-05-27 23:03:54 +02:00
|
|
|
|
2020-12-03 22:07:42 +01:00
|
|
|
for mod in result["provides"]:
|
|
|
|
result["depends"].discard(mod)
|
|
|
|
result["optional_depends"].discard(mod)
|
2018-05-12 18:28:04 +02:00
|
|
|
|
2020-12-03 22:07:42 +01:00
|
|
|
for key, value in result.items():
|
|
|
|
if isinstance(value, set):
|
|
|
|
result[key] = list(value)
|
2018-05-27 23:03:54 +02:00
|
|
|
|
2020-12-03 22:07:42 +01:00
|
|
|
return result
|
2018-05-11 16:04:17 +02:00
|
|
|
|
2018-05-15 20:35:59 +02:00
|
|
|
|
2020-08-18 17:12:27 +02:00
|
|
|
def postReleaseCheckUpdate(self, release, path):
|
|
|
|
try:
|
2020-12-04 03:23:04 +01:00
|
|
|
tree = build_tree(path, expected_type=ContentType[release.package.type.name],
|
|
|
|
author=release.package.author.username, name=release.package.name)
|
2020-08-18 17:12:27 +02:00
|
|
|
|
|
|
|
cache = {}
|
|
|
|
def getMetaPackages(names):
|
|
|
|
return [ MetaPackage.GetOrCreate(x, cache) for x in names ]
|
|
|
|
|
|
|
|
provides = tree.getModNames()
|
|
|
|
|
|
|
|
package = release.package
|
|
|
|
package.provides.clear()
|
|
|
|
package.provides.extend(getMetaPackages(tree.getModNames()))
|
|
|
|
|
|
|
|
# Delete all meta package dependencies
|
|
|
|
package.dependencies.filter(Dependency.meta_package != None).delete()
|
|
|
|
|
|
|
|
# Get raw dependencies
|
|
|
|
depends = tree.fold("meta", "depends")
|
|
|
|
optional_depends = tree.fold("meta", "optional_depends")
|
|
|
|
|
|
|
|
# Filter out provides
|
|
|
|
for mod in provides:
|
|
|
|
depends.discard(mod)
|
|
|
|
optional_depends.discard(mod)
|
|
|
|
|
2020-08-18 18:08:17 +02:00
|
|
|
# Add dependencies
|
2020-08-18 17:12:27 +02:00
|
|
|
for meta in getMetaPackages(depends):
|
|
|
|
db.session.add(Dependency(package, meta=meta, optional=False))
|
|
|
|
|
|
|
|
for meta in getMetaPackages(optional_depends):
|
|
|
|
db.session.add(Dependency(package, meta=meta, optional=True))
|
|
|
|
|
|
|
|
# Update min/max
|
|
|
|
|
|
|
|
if tree.meta.get("min_minetest_version"):
|
|
|
|
release.min_rel = MinetestRelease.get(tree.meta["min_minetest_version"], None)
|
|
|
|
|
|
|
|
if tree.meta.get("max_minetest_version"):
|
|
|
|
release.max_rel = MinetestRelease.get(tree.meta["max_minetest_version"], None)
|
|
|
|
|
|
|
|
return tree
|
|
|
|
|
|
|
|
except MinetestCheckError as err:
|
2020-08-19 14:06:21 +02:00
|
|
|
db.session.rollback()
|
|
|
|
|
2020-08-18 17:12:27 +02:00
|
|
|
if "Fails validation" not in release.title:
|
|
|
|
release.title += " (Fails validation)"
|
|
|
|
|
|
|
|
release.task_id = self.request.id
|
|
|
|
release.approved = False
|
|
|
|
db.session.commit()
|
|
|
|
|
|
|
|
raise TaskError(str(err))
|
|
|
|
|
|
|
|
|
|
|
|
@celery.task(bind=True)
|
|
|
|
def checkZipRelease(self, id, path):
|
|
|
|
release = PackageRelease.query.get(id)
|
|
|
|
if release is None:
|
|
|
|
raise TaskError("No such release!")
|
|
|
|
elif release.package is None:
|
|
|
|
raise TaskError("No package attached to release")
|
|
|
|
|
2020-12-14 22:05:56 +01:00
|
|
|
with get_temp_dir() as temp:
|
2020-08-18 17:12:27 +02:00
|
|
|
with ZipFile(path, 'r') as zip_ref:
|
|
|
|
zip_ref.extractall(temp)
|
|
|
|
|
|
|
|
postReleaseCheckUpdate(self, release, temp)
|
2020-01-19 02:37:15 +01:00
|
|
|
|
|
|
|
release.task_id = None
|
|
|
|
release.approve(release.package.author)
|
|
|
|
db.session.commit()
|
|
|
|
|
2018-06-06 00:13:39 +02:00
|
|
|
|
2020-08-18 17:12:27 +02:00
|
|
|
@celery.task(bind=True)
|
|
|
|
def makeVCSRelease(self, id, branch):
|
2018-06-06 00:13:39 +02:00
|
|
|
release = PackageRelease.query.get(id)
|
|
|
|
if release is None:
|
|
|
|
raise TaskError("No such release!")
|
|
|
|
elif release.package is None:
|
|
|
|
raise TaskError("No package attached to release")
|
|
|
|
|
2020-12-14 22:05:56 +01:00
|
|
|
with clone_repo(release.package.repo, ref=branch, recursive=True) as repo:
|
2020-12-03 22:07:42 +01:00
|
|
|
postReleaseCheckUpdate(self, release, repo.working_tree_dir)
|
2020-01-19 02:22:33 +01:00
|
|
|
|
2020-01-19 01:28:26 +01:00
|
|
|
filename = randomString(10) + ".zip"
|
|
|
|
destPath = os.path.join(app.config["UPLOAD_DIR"], filename)
|
|
|
|
|
|
|
|
assert(not os.path.isfile(destPath))
|
2020-12-29 21:42:43 +01:00
|
|
|
archiver = GitArchiver(prefix=release.package.name, force_sub=True, main_repo_abspath=repo.working_tree_dir)
|
2020-01-19 01:28:26 +01:00
|
|
|
archiver.create(destPath)
|
|
|
|
assert(os.path.isfile(destPath))
|
|
|
|
|
|
|
|
release.url = "/uploads/" + filename
|
|
|
|
release.task_id = None
|
|
|
|
release.commit_hash = repo.head.object.hexsha
|
|
|
|
release.approve(release.package.author)
|
|
|
|
db.session.commit()
|
|
|
|
|
|
|
|
return release.url
|
2018-06-06 00:13:39 +02:00
|
|
|
|
2020-07-12 03:22:35 +02:00
|
|
|
|
2018-05-15 20:35:59 +02:00
|
|
|
@celery.task()
|
|
|
|
def importRepoScreenshot(id):
|
|
|
|
package = Package.query.get(id)
|
2020-09-16 18:51:03 +02:00
|
|
|
if package is None or package.state == PackageState.DELETED:
|
2018-05-15 20:35:59 +02:00
|
|
|
raise Exception("Unexpected none package")
|
|
|
|
|
2018-06-06 00:13:39 +02:00
|
|
|
try:
|
2020-12-14 22:05:56 +01:00
|
|
|
with clone_repo(package.repo) as repo:
|
2020-12-03 22:07:42 +01:00
|
|
|
for ext in ["png", "jpg", "jpeg"]:
|
|
|
|
sourcePath = repo.working_tree_dir + "/screenshot." + ext
|
|
|
|
if os.path.isfile(sourcePath):
|
|
|
|
filename = randomString(10) + "." + ext
|
|
|
|
destPath = os.path.join(app.config["UPLOAD_DIR"], filename)
|
|
|
|
shutil.copyfile(sourcePath, destPath)
|
|
|
|
|
|
|
|
ss = PackageScreenshot()
|
|
|
|
ss.approved = True
|
|
|
|
ss.package = package
|
|
|
|
ss.title = "screenshot.png"
|
|
|
|
ss.url = "/uploads/" + filename
|
|
|
|
db.session.add(ss)
|
|
|
|
db.session.commit()
|
|
|
|
|
|
|
|
return "/uploads/" + filename
|
|
|
|
|
2018-06-06 00:13:39 +02:00
|
|
|
except TaskError as e:
|
|
|
|
# ignore download errors
|
|
|
|
print(e)
|
2020-12-03 22:07:42 +01:00
|
|
|
pass
|
2018-06-05 23:34:57 +02:00
|
|
|
|
|
|
|
print("screenshot.png does not exist")
|
2018-05-15 20:35:59 +02:00
|
|
|
return None
|
2020-07-14 01:28:56 +02:00
|
|
|
|
|
|
|
|
|
|
|
@celery.task(bind=True)
|
|
|
|
def importForeignDownloads(self, id):
|
|
|
|
release = PackageRelease.query.get(id)
|
|
|
|
if release is None:
|
|
|
|
raise TaskError("No such release!")
|
|
|
|
elif release.package is None:
|
|
|
|
raise TaskError("No package attached to release")
|
|
|
|
elif not release.url.startswith("http"):
|
|
|
|
return
|
|
|
|
|
|
|
|
try:
|
|
|
|
ext = getExtension(release.url)
|
|
|
|
filename = randomString(10) + "." + ext
|
|
|
|
filepath = os.path.join(app.config["UPLOAD_DIR"], filename)
|
|
|
|
urllib.request.urlretrieve(release.url, filepath)
|
|
|
|
|
|
|
|
release.url = "/uploads/" + filename
|
|
|
|
db.session.commit()
|
2020-08-18 17:12:27 +02:00
|
|
|
|
2020-07-14 01:28:56 +02:00
|
|
|
except urllib.error.URLError:
|
2020-08-18 17:12:27 +02:00
|
|
|
db.session.rollback()
|
2020-07-14 01:28:56 +02:00
|
|
|
release.task_id = self.request.id
|
|
|
|
release.approved = False
|
|
|
|
db.session.commit()
|
2020-12-15 20:05:29 +01:00
|
|
|
|
|
|
|
|
2021-01-29 23:20:44 +01:00
|
|
|
def check_update_config_impl(package):
|
|
|
|
config = package.update_config
|
|
|
|
|
|
|
|
if config.trigger == PackageUpdateTrigger.COMMIT:
|
|
|
|
tag = None
|
|
|
|
commit = get_commit_hash(package.repo, package.update_config.ref)
|
|
|
|
elif config.trigger == PackageUpdateTrigger.TAG:
|
|
|
|
tag, commit = get_latest_tag(package.repo)
|
|
|
|
else:
|
|
|
|
raise TaskError("Unknown update trigger")
|
|
|
|
|
|
|
|
if config.last_commit == commit:
|
|
|
|
if tag and config.last_tag != tag:
|
|
|
|
config.last_tag = tag
|
|
|
|
db.session.commit()
|
|
|
|
return
|
|
|
|
|
|
|
|
if not config.last_commit:
|
|
|
|
config.last_commit = commit
|
|
|
|
config.last_tag = tag
|
|
|
|
db.session.commit()
|
|
|
|
return
|
|
|
|
|
2021-01-31 00:51:09 +01:00
|
|
|
if package.releases.filter_by(commit_hash=commit).count() > 0:
|
2021-01-30 20:56:27 +01:00
|
|
|
return
|
|
|
|
|
2021-01-29 23:20:44 +01:00
|
|
|
if config.make_release:
|
|
|
|
rel = PackageRelease()
|
|
|
|
rel.package = package
|
2021-01-30 02:20:38 +01:00
|
|
|
rel.title = tag if tag else datetime.datetime.utcnow().strftime("%Y-%m-%d")
|
2021-01-29 23:20:44 +01:00
|
|
|
rel.url = ""
|
|
|
|
rel.task_id = uuid()
|
|
|
|
db.session.add(rel)
|
2021-01-30 18:10:38 +01:00
|
|
|
|
2021-01-30 19:25:00 +01:00
|
|
|
msg = "Created release {} (Git Update Detection)".format(rel.title)
|
2021-01-30 18:10:38 +01:00
|
|
|
addSystemAuditLog(AuditSeverity.NORMAL, msg, package.getDetailsURL(), package)
|
|
|
|
|
2021-01-29 23:20:44 +01:00
|
|
|
db.session.commit()
|
|
|
|
|
|
|
|
makeVCSRelease.apply_async((rel.id, commit), task_id=rel.task_id)
|
|
|
|
|
|
|
|
elif config.outdated_at is None:
|
|
|
|
config.set_outdated()
|
|
|
|
|
|
|
|
if config.trigger == PackageUpdateTrigger.COMMIT:
|
|
|
|
msg_last = ""
|
|
|
|
if config.last_commit:
|
|
|
|
msg_last = " The last commit was {}".format(config.last_commit[0:5])
|
|
|
|
|
|
|
|
msg = "New commit {} found on the Git repo, is the package outdated?{}" \
|
|
|
|
.format(commit[0:5], msg_last)
|
|
|
|
else:
|
|
|
|
msg_last = ""
|
|
|
|
if config.last_tag:
|
|
|
|
msg_last = " The last tag was {}".format(config.last_tag)
|
|
|
|
|
|
|
|
msg = "New tag {} found on the Git repo.{}" \
|
|
|
|
.format(tag, msg_last)
|
|
|
|
|
|
|
|
for user in package.maintainers:
|
|
|
|
addSystemNotification(user, NotificationType.BOT,
|
|
|
|
msg, url_for("todo.view_user", username=user.username, _external=False), package)
|
|
|
|
|
|
|
|
config.last_commit = commit
|
|
|
|
config.last_tag = tag
|
|
|
|
db.session.commit()
|
|
|
|
|
|
|
|
|
2020-12-15 23:20:40 +01:00
|
|
|
@celery.task(bind=True)
|
|
|
|
def check_update_config(self, package_id):
|
2020-12-15 20:05:29 +01:00
|
|
|
package: Package = Package.query.get(package_id)
|
|
|
|
if package is None:
|
|
|
|
raise TaskError("No such package!")
|
|
|
|
elif package.update_config is None:
|
|
|
|
raise TaskError("No update config attached to package")
|
|
|
|
|
2020-12-15 23:20:40 +01:00
|
|
|
err = None
|
|
|
|
try:
|
2021-01-29 23:20:44 +01:00
|
|
|
check_update_config_impl(package)
|
2020-12-15 23:20:40 +01:00
|
|
|
except GitCommandError as e:
|
|
|
|
# This is needed to stop the backtrace being weird
|
|
|
|
err = e.stderr
|
|
|
|
except gitdb.exc.BadName as e:
|
|
|
|
err = "Unable to find the reference " + (package.update_config.ref or "?") + "\n" + e.stderr
|
2021-01-29 23:20:44 +01:00
|
|
|
except TaskError as e:
|
|
|
|
err = e.value
|
2020-12-15 23:20:40 +01:00
|
|
|
|
|
|
|
if err:
|
|
|
|
err = err.replace("stderr: ", "") \
|
|
|
|
.replace("Cloning into '/tmp/", "Cloning into '") \
|
|
|
|
.strip()
|
|
|
|
|
2020-12-15 23:40:49 +01:00
|
|
|
msg = "Error: {}.\n\nTask ID: {}\n\n[Change update configuration]({})" \
|
2021-01-29 23:20:44 +01:00
|
|
|
.format(err, self.request.id, package.getUpdateConfigURL())
|
2020-12-15 23:40:49 +01:00
|
|
|
|
2020-12-15 23:51:57 +01:00
|
|
|
post_bot_message(package, "Failed to check git repository", msg)
|
2020-12-15 23:20:40 +01:00
|
|
|
|
|
|
|
db.session.commit()
|
|
|
|
return
|
|
|
|
|
2020-12-15 20:05:29 +01:00
|
|
|
|
|
|
|
@celery.task
|
|
|
|
def check_for_updates():
|
|
|
|
for update_config in PackageUpdateConfig.query.all():
|
|
|
|
update_config: PackageUpdateConfig
|
|
|
|
|
2020-12-15 23:41:38 +01:00
|
|
|
if not update_config.package.approved:
|
|
|
|
continue
|
|
|
|
|
2020-12-15 20:05:29 +01:00
|
|
|
if update_config.package.repo is None:
|
|
|
|
db.session.delete(update_config)
|
|
|
|
continue
|
|
|
|
|
|
|
|
check_update_config.delay(update_config.package_id)
|
|
|
|
|
|
|
|
db.session.commit()
|