Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

frontend: add commands for adding and removing warning banner #2436

Merged
merged 2 commits into from
Dec 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions doc/how_to_release_copr.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,15 @@ good to know what's ahead.
Keep amending this page if you find something not matching reality or expectations.


Create warning banner about release
-----------------------------------


Use script in frontend's ``manage.py`` to announce an outage::

./manage.py warning-banner --outage_time "2022-12-31 13:00-16:00 UTC" --ticket 1234


Pre-release
-----------

Expand Down Expand Up @@ -422,6 +431,11 @@ It is often good idea to put new (filtered) ``%changelogs`` entries there.
Final steps
...........

Remove the warning banner from frontend page by::

./manage.py warning-banner --remove


Check if the `MODIFIED bugs <https://bugzilla.redhat.com/buglist.cgi?bug_status=POST&bug_status=MODIFIED&classification=Community&list_id=4678039&product=Copr&query_format=advanced>`_
(that are not ON_QA) are fixed in released Copr or not, move them ON_QA.

Expand Down
51 changes: 51 additions & 0 deletions frontend/coprs_frontend/commands/warning_banner.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
"""
Command for managing warning banner on the top of frontend page.
"""


import os
import sys
from pathlib import Path

import click
from jinja2 import Template

from coprs.constants import BANNER_LOCATION


@click.command()
@click.option("--outage_time", "-o", default=None, help="start time of the outage")
@click.option("--ticket", "-t", default=None, help="fedora infra ticket ID")
@click.option("--rest", default=None, help="additional code")
@click.option("--remove", is_flag=True, show_default=True, default=False, help="removes banner")
def warning_banner(outage_time, ticket, rest, remove):
"""
Adds a banner to Copr's frontend page with outage warning. `outage_time` or `rest` is required.

In case you need to schedule regular outage, fill in only `outage_time` and `ticket`. In case
you need to add something else, please use the `rest` parameter to dump to warning banner
some additional information. This can be just some text or html code.
`rest` parameter can be used as a standalone option just for showing some warning banner
with specific information. It can be also piece of HTML code.
"""
if remove:
if outage_time or ticket or rest:
print(
"Error: can't remove banner with `outage_time` or `ticket` or `rest`",
file=sys.stderr,
)
return

if os.path.exists(BANNER_LOCATION):
os.remove(BANNER_LOCATION)
return

if outage_time is None and rest is None:
print("Error: `outage_time` or `rest` should be present.", file=sys.stderr)
return

with open(BANNER_LOCATION, "w", encoding="UTF-8") as banner:
banner_path_template = Path(__file__).parent / "../coprs/templates/banner-include.html"
with banner_path_template.open() as banner_template:
template = Template(banner_template.read())
banner.write(template.render(outage_time=outage_time, ticket=ticket, rest=rest))
6 changes: 6 additions & 0 deletions frontend/coprs_frontend/coprs/constants.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
"""
File which contains only constants. Nothing else.
"""


BANNER_LOCATION = "/var/lib/copr/data/banner-include.html"
4 changes: 1 addition & 3 deletions frontend/coprs_frontend/coprs/context_processors.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,10 @@
import flask

from coprs import app
from coprs.constants import BANNER_LOCATION
from coprs.helpers import current_url


BANNER_LOCATION = "/var/lib/copr/banner-include.html"


@app.context_processor
def include_banner():
if os.path.exists(BANNER_LOCATION):
Expand Down
16 changes: 16 additions & 0 deletions frontend/coprs_frontend/coprs/templates/banner-include.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<div class="alert alert-danger" role="alert">
{% if outage_time %}
<b>Warning!</b> Scheduled outage of Copr servers - {{ outage_time }}.
{% endif %}
{% if ticket %}
For more information please refer to
<a href="https://pagure.io/fedora-infrastructure/issue/{{ ticket }}">this ticket</a>.
{% endif %}
<!--
Possible rest of short html code. Something like:
"Check <a href="#" class="alert-link">this document</a> for details."
-->
{% if rest %}
{{ rest }}
{% endif %}
</div>
2 changes: 2 additions & 0 deletions frontend/coprs_frontend/manage.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import commands.delete_orphans
import commands.fixup_unnoticed_chroots
import commands.chroots_template
import commands.warning_banner

from coprs import app

Expand Down Expand Up @@ -90,6 +91,7 @@
"clean_old_builds",
"delete_orphans",
"delete_dirs",
"warning_banner",
]


Expand Down