diff --git a/app/blueprints/packages/packages.py b/app/blueprints/packages/packages.py index 8d038b9b..ec8c9234 100644 --- a/app/blueprints/packages/packages.py +++ b/app/blueprints/packages/packages.py @@ -319,17 +319,6 @@ def create_edit(author=None, name=None): if package.type == PackageType.TXP: package.license = package.media_license - # Dependency.query.filter_by(depender=package).delete() - # deps = Dependency.SpecToList(package, form.harddep_str.data, mpackage_cache) - # for dep in deps: - # dep.optional = False - # db.session.add(dep) - - # deps = Dependency.SpecToList(package, form.softdep_str.data, mpackage_cache) - # for dep in deps: - # dep.optional = True - # db.session.add(dep) - if wasNew and package.type == PackageType.MOD: m = MetaPackage.GetOrCreate(package.name, {}) package.provides.append(m) @@ -344,13 +333,14 @@ def create_edit(author=None, name=None): db.session.commit() # save - next_url = package.getDetailsURL() if wasNew and package.repo is not None: - task = importRepoScreenshot.delay(package.id) - next_url = url_for("tasks.check", id=task.id, r=next_url) + importRepoScreenshot.delay(package.id) + next_url = package.getDetailsURL() if wasNew and ("WTFPL" in package.license.name or "WTFPL" in package.media_license.name): next_url = url_for("flatpage", path="help/wtfpl", r=next_url) + elif wasNew: + next_url = package.getSetupReleasesURL() return redirect(next_url) diff --git a/app/blueprints/packages/releases.py b/app/blueprints/packages/releases.py index 96db5697..e2c69903 100644 --- a/app/blueprints/packages/releases.py +++ b/app/blueprints/packages/releases.py @@ -252,29 +252,60 @@ def delete_release(package, id): class PackageUpdateConfigFrom(FlaskForm): trigger = SelectField("Trigger", [InputRequired()], choices=PackageUpdateTrigger.choices(), coerce=PackageUpdateTrigger.coerce, default=PackageUpdateTrigger.COMMIT) - make_release = BooleanField("Create Release") - submit = SubmitField("Save") + action = SelectField("Action", [InputRequired()], choices=[("notification", "Notification"), ("make_release", "Create Release")], default="make_release") + submit = SubmitField("Save Settings") + disable = SubmitField("Disable") @bp.route("/packages///update-config/", methods=["GET", "POST"]) @login_required @is_package_page def update_config(package): - package.update_config = package.update_config or PackageUpdateConfig() - if not package.checkPerm(current_user, Permission.MAKE_RELEASE): - return redirect(package.getDetailsURL()) + abort(403) + + if not package.repo: + flash("Please add a Git repository URL in order to set up automatic releases", "danger") + return redirect(package.getEditURL()) form = PackageUpdateConfigFrom(obj=package.update_config) - if form.validate_on_submit(): - flash("Changed update configuration", "success") - form.populate_obj(package.update_config) - db.session.add(package.update_config) + if request.method == "GET" and package.update_config: + form.action.data = "make_release" if package.update_config.make_release else "notification" - check_for_updates.delay() + if form.validate_on_submit(): + if form.disable.data: + flash("Deleted update configuration", "success") + if package.update_config: + db.session.delete(package.update_config) + else: + if package.update_config is None: + package.update_config = PackageUpdateConfig() + db.session.add(package.update_config) + + form.populate_obj(package.update_config) + package.update_config.make_release = form.action.data == "make_release" + + check_for_updates.delay() db.session.commit() + if not form.disable.data and package.releases.count() == 0: + flash("Now, please create an initial release", "success") + return redirect(package.getCreateReleaseURL()) + return redirect(package.getDetailsURL()) return render_template("packages/update_config.html", package=package, form=form) + + +@bp.route("/packages///setup-releases/") +@login_required +@is_package_page +def setup_releases(package): + if not package.checkPerm(current_user, Permission.MAKE_RELEASE): + abort(403) + + if package.update_config: + return redirect(package.getUpdateConfigURL()) + + return render_template("packages/release_wizard.html", package=package) diff --git a/app/models/packages.py b/app/models/packages.py index e42f9ff4..0e48a5f8 100644 --- a/app/models/packages.py +++ b/app/models/packages.py @@ -514,6 +514,10 @@ class Package(db.Model): return url_for("packages.update_config", author=self.author.username, name=self.name) + def getSetupReleasesURL(self): + return url_for("packages.setup_releases", + author=self.author.username, name=self.name) + def getDownloadURL(self): return url_for("packages.download", author=self.author.username, name=self.name) diff --git a/app/templates/macros/forms.html b/app/templates/macros/forms.html index a58a2a32..b8a213a0 100644 --- a/app/templates/macros/forms.html +++ b/app/templates/macros/forms.html @@ -177,10 +177,9 @@ {%- endmacro %} -{% macro render_submit_field(field, label=None, tabindex=None) -%} +{% macro render_submit_field(field, label=None, tabindex=None, class_=None) -%} {% if not label %}{% set label=field.label.text %}{% endif %} {##} - + {%- endmacro %} diff --git a/app/templates/macros/package_approval.html b/app/templates/macros/package_approval.html index 8423728f..80d6e747 100644 --- a/app/templates/macros/package_approval.html +++ b/app/templates/macros/package_approval.html @@ -16,17 +16,15 @@ {% set level = "warning" %} {% if package.releases.count() == 0 %} {% set message %} -

Release Required

{% if package.checkPerm(current_user, "MAKE_RELEASE") %} -

You need to create a release before this package can be approved.

-

- A release is a single downloadable version of your {{ package.type.value | lower }}. - You need to create releases even if you use a rolling release development cycle, - as Minetest needs them to check for updates. -

- Create Release + {% if package.update_config %} + Create first release + {% else %} + Set up releases + {% endif %} + {{ _("You need to create a release before this package can be approved.") }} {% else %} - A release is required before this package can be approved. + {{ _("A release is required before this package can be approved.") }} {% endif %} {% endset %} diff --git a/app/templates/packages/release_new.html b/app/templates/packages/release_new.html index adbf5745..2e11863b 100644 --- a/app/templates/packages/release_new.html +++ b/app/templates/packages/release_new.html @@ -1,27 +1,27 @@ {% extends "base.html" %} {% block title %} - Create a release | {{ package.title }} + {{ _("Create a release") }} - {{ package.title }} {% endblock %} {% block content %} -

- {{ _("Learn more") }} - {% if package.checkPerm(current_user, "APPROVE_RELEASE") and package.getIsOnGitHub() %} - {{ _("Setup webhook") }} - +

{{ _("Create a release") }}

- {{ _("Create releases automatically when you push commits or tags to GitHub, using a webhook or the API.") }} - {% elif package.repo %} - + {% if not (package.repo and package.update_config) %} +

+ {% if package.repo %} + {{ _("Set up") }} + - {{ _("You can create releases automatically when you push commits or tags to your repository, using a webhook or the API.") }} - {% else %} - + {{ _("You can create releases automatically when you push commits or tags to your repository.") }} + {% else %} + {{ _("Add Git repo") }} + - {{ _("Using git will allow you to create releases automatically when you push code or tags.") }} - {% endif %} -

+ {{ _("Using Git would allow you to create releases automatically when you push code or tags.") }} + {% endif %} +

+ {% endif %} {% from "macros/forms.html" import render_field, render_submit_field, render_radio_field %}
diff --git a/app/templates/packages/release_wizard.html b/app/templates/packages/release_wizard.html new file mode 100644 index 00000000..82b5b214 --- /dev/null +++ b/app/templates/packages/release_wizard.html @@ -0,0 +1,46 @@ +{% extends "base.html" %} + +{% block title %} + {{ _("How do you want to create releases?") }} +{% endblock %} + +{% block content %} +

{{ self.title() }}

+ +

+ {{ _("A release is a single downloadable version of your %(title)s.", title=package.type.value.lower()) }} + {{ _("You need to create releases even if you use a rolling release development cycle, as Minetest needs them to check for updates.") }} +

+ + {% if package.repo %} +

+ {{ _("When you push a commit or tag to your Git repository, ContentDB can create a new release automatically.") }} + {{ _("ContentDB will check your Git repository at 2am UTC every day, but you can use webhooks or the API for faster updates.") }} +

+ +

+ {{ _("This can be changed later.") }} +

+ +

+ Set up automatic releases + Create releases manually + Later +

+ {% else %} +

+ {{ _("Using Git would allow you to create releases automatically when you push code or tags.") }} + {{ _("Unfortunately, you will otherwise need to create a release manually.") }} +

+ +

+ {{ _("This can be changed later.") }} +

+ +

+ Add Git repo + Create releases manually + Later +

+ {% endif %} +{% endblock %} diff --git a/app/templates/packages/update_config.html b/app/templates/packages/update_config.html index 6431efca..eb20c47b 100644 --- a/app/templates/packages/update_config.html +++ b/app/templates/packages/update_config.html @@ -1,29 +1,41 @@ {% extends "base.html" %} {% block title %} - Configure Update Detection | {{ package.title }} + {{ _("Configure Automatic Releases") }} - {{ package.title }} {% endblock %} {% block content %} -

{{ _("Configure Update Detection") }}

+

{{ _("Configure Automatic Releases") }}

+ +

+ {{ _("When you push a change to your Git repository, ContentDB can create a new release automatically.") }} +

{{ _("ContentDB will poll your Git repository at 2am UTC every day.") }} {{ _("You should consider using webhooks or the API for faster rollouts.") }}

+ {% if package.checkPerm(current_user, "APPROVE_RELEASE") and package.getIsOnGitHub() %} +

+ {{ _("Learn more") }} + {{ _("Setup webhook") }} + + + {{ _("Create releases faster by using a webhook.") }} +

+ {% endif %} + {% from "macros/forms.html" import render_field, render_submit_field, render_checkbox_field %} {{ form.hidden_tag() }} -

Triggers

- {{ render_field(form.trigger) }} - -

Actions

- {{ render_checkbox_field(form.make_release) }} + {{ render_field(form.trigger, class_="mt-5") }} + {{ render_field(form.action) }}

{{ render_submit_field(form.submit) }} + {{ render_submit_field(form.disable, class_="btn btn-secondary ml-2") }}

{% endblock %}