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

i18n: Mark Missing translations #175

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
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
69 changes: 9 additions & 60 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#
# This file is part of Invenio.
# Copyright (C) 2023 Graz University of Technology.
# Copyright (C) 2024 KTH Royal Institute of Technology.
#
# Invenio is free software; you can redistribute it and/or modify it
# under the terms of the MIT License; see LICENSE file for more details.
Expand All @@ -10,9 +11,11 @@ name: CI

on:
push:
branches: master
branches:
- master
pull_request:
branches: master
branches:
- master
schedule:
# * is a special character in YAML so you have to quote this string
- cron: "0 3 * * 6"
Expand All @@ -24,61 +27,7 @@ on:
default: "Manual trigger"

jobs:
Tests:
runs-on: ubuntu-20.04
strategy:
matrix:
python-version: [3.7, 3.8, 3.9]
requirements-level: [pypi]
db-service: [postgresql13]
search-service: [opensearch2, elasticsearch7]
include:
- db-service: postgresql13
DB_EXTRAS: "postgresql"

- search-service: opensearch2
SEARCH_EXTRAS: "opensearch2"

- search-service: elasticsearch7
SEARCH_EXTRAS: "elasticsearch7"

env:
DB: ${{ matrix.db-service }}
SEARCH: ${{ matrix.search-service }}
EXTRAS: tests,${{ matrix.SEARCH_EXTRAS }}

steps:
- name: Checkout
uses: actions/checkout@v2

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}

- name: Generate dependencies
run: |
pip install wheel requirements-builder
requirements-builder -e "$EXTRAS" --level=${{ matrix.requirements-level }} setup.py > .${{ matrix.requirements-level }}-${{ matrix.python-version }}-requirements.txt
cat .${{ matrix.requirements-level }}-${{ matrix.python-version }}-requirements.txt

- name: Cache pip
uses: actions/cache@v2
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pip-${{ hashFiles('.${{ matrix.requirements-level }}-${{ matrix.python-version }}-requirements.txt') }}

- name: Install dependencies
run: |
pip install -r .${{ matrix.requirements-level }}-${{ matrix.python-version }}-requirements.txt -c constraints-${{ matrix.requirements-level }}.txt
pip install ".[$EXTRAS]"
pip freeze
docker --version
docker-compose --version

- name: Run translations test
run: ./run-i18n-tests.sh

- name: Run tests
run: |
./run-tests.sh
Python:
uses: inveniosoftware/workflows/.github/workflows/tests-python.yml@master
with:
extras: "tests"
14 changes: 9 additions & 5 deletions invenio_github/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#
# This file is part of Invenio.
# Copyright (C) 2023 CERN.
# Copyright (C) 2024 KTH Royal Institute of Technology.
#
# Invenio is free software; you can redistribute it
# and/or modify it under the terms of the GNU General Public License as
Expand Down Expand Up @@ -37,6 +38,7 @@
from invenio_access.permissions import authenticated_user
from invenio_access.utils import get_identity
from invenio_db import db
from invenio_i18n import gettext as _
from invenio_oauth2server.models import Token as ProviderToken
from invenio_oauthclient.handlers import token_getter
from invenio_oauthclient.models import RemoteAccount, RemoteToken
Expand Down Expand Up @@ -134,7 +136,7 @@ def webhook_url(self):
"""Return the url to be used by a GitHub webhook."""
if not self.account.extra_data.get("tokens", {}).get("webhook"):
raise RemoteAccountDataNotSet(
self.user_id, "Webhook data not found for user tokens (remote data)."
self.user_id, _("Webhook data not found for user tokens (remote data).")
)

webhook_token = ProviderToken.query.filter_by(
Expand All @@ -145,13 +147,13 @@ def webhook_url(self):
if wh_url:
return wh_url.format(token=webhook_token.access_token)
else:
raise RuntimeError("You must set GITHUB_WEBHOOK_RECEIVER_URL.")
raise RuntimeError(_("You must set GITHUB_WEBHOOK_RECEIVER_URL."))

def init_account(self):
"""Setup a new GitHub account."""
if not self.account:
raise RemoteAccountNotFound(
self.user_id, "Remote account was not found for user."
self.user_id, _("Remote account was not found for user.")
)

ghuser = self.api.me()
Expand Down Expand Up @@ -426,7 +428,7 @@ def get_last_sync_time(self):
"""
if not self.account.extra_data.get("last_sync"):
raise RemoteAccountDataNotSet(
self.user_id, "Last sync data is not set for user (remote data)."
self.user_id, _("Last sync data is not set for user (remote data).")
)

extra_data = self.account.extra_data
Expand Down Expand Up @@ -574,7 +576,9 @@ def contributors(self):
else:
# Contributors fetch failed
raise UnexpectedGithubResponse(
f"Github returned unexpected code: {status} for release {self.repository_object.github_id}"
_(
"Github returned unexpected code: {status} for release {repo_id}"
).format(status=status, repo_id=self.repository_object.github_id)
)

@cached_property
Expand Down
25 changes: 14 additions & 11 deletions invenio_github/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#
# This file is part of Invenio.
# Copyright (C) 2023 CERN.
# Copyright (C) 2024 KTH Royal Institute of Technology.
#
# Invenio is free software; you can redistribute it
# and/or modify it under the terms of the GNU General Public License as
Expand All @@ -24,6 +25,8 @@

"""Invenio-GitHub errors."""

from invenio_i18n import gettext as _


class GitHubError(Exception):
"""General GitHub error."""
Expand All @@ -32,7 +35,7 @@ class GitHubError(Exception):
class RepositoryAccessError(GitHubError):
"""Repository access permissions error."""

message = "The user cannot access the github repository"
message = _("The user cannot access the github repository")

def __init__(self, user=None, repo=None, repo_id=None, message=None):
"""Constructor."""
Expand All @@ -46,7 +49,7 @@ def __init__(self, user=None, repo=None, repo_id=None, message=None):
class RepositoryDisabledError(GitHubError):
"""Repository access permissions error."""

message = "This repository is not enabled for webhooks."
message = _("This repository is not enabled for webhooks.")

def __init__(self, repo=None, message=None):
"""Constructor."""
Expand All @@ -57,7 +60,7 @@ def __init__(self, repo=None, message=None):
class RepositoryNotFoundError(GitHubError):
"""Repository not found error."""

message = "The repository does not exist."
message = _("The repository does not exist.")

def __init__(self, repo=None, message=None):
"""Constructor."""
Expand All @@ -68,7 +71,7 @@ def __init__(self, repo=None, message=None):
class InvalidSenderError(GitHubError):
"""Invalid release sender error."""

message = "Invalid sender for event"
message = _("Invalid sender for event")

def __init__(self, event=None, user=None, message=None):
"""Constructor."""
Expand All @@ -80,7 +83,7 @@ def __init__(self, event=None, user=None, message=None):
class ReleaseAlreadyReceivedError(GitHubError):
"""Invalid release sender error."""

message = "The release has already been received."
message = _("The release has already been received.")

def __init__(self, release=None, message=None):
"""Constructor."""
Expand All @@ -91,7 +94,7 @@ def __init__(self, release=None, message=None):
class CustomGitHubMetadataError(GitHubError):
"""Invalid Custom GitHub Metadata file."""

message = "The metadata file is not valid JSON."
message = _("The metadata file is not valid JSON.")

def __init__(self, file=None, message=None):
"""Constructor."""
Expand All @@ -102,7 +105,7 @@ def __init__(self, file=None, message=None):
class GithubTokenNotFound(GitHubError):
"""Oauth session token was not found."""

message = "The oauth session token was not found."
message = _("The oauth session token was not found.")

def __init__(self, user=None, message=None):
"""Constructor."""
Expand All @@ -113,7 +116,7 @@ def __init__(self, user=None, message=None):
class RemoteAccountNotFound(GitHubError):
"""Remote account for the user is not setup."""

message = "RemoteAccount not found for user"
message = _("RemoteAccount not found for user")

def __init__(self, user=None, message=None):
"""Constructor."""
Expand All @@ -124,7 +127,7 @@ def __init__(self, user=None, message=None):
class RemoteAccountDataNotSet(GitHubError):
"""Remote account extra data for the user is not set."""

message = "RemoteAccount extra data not set for user."
message = _("RemoteAccount extra data not set for user.")

def __init__(self, user=None, message=None):
"""Constructor."""
Expand All @@ -135,7 +138,7 @@ def __init__(self, user=None, message=None):
class ReleaseNotFound(GitHubError):
"""Release does not exist."""

message = "Release does not exist."
message = _("Release does not exist.")

def __init__(self, message=None):
"""Constructor."""
Expand All @@ -145,7 +148,7 @@ def __init__(self, message=None):
class UnexpectedGithubResponse(GitHubError):
"""Request to Github API returned an unexpected error."""

message = "Github API returned an unexpected error."
message = _("Github API returned an unexpected error.")

def __init__(self, message=None):
"""Constructor."""
Expand Down
4 changes: 3 additions & 1 deletion invenio_github/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#
# This file is part of Invenio.
# Copyright (C) 2023 CERN.
# Copyright (C) 2024 KTH Royal Institute of Technology.
#
# Invenio is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
Expand All @@ -28,6 +29,7 @@
from celery import shared_task
from flask import current_app, g
from invenio_db import db
from invenio_i18n import gettext as _
from invenio_oauthclient.models import RemoteAccount
from invenio_oauthclient.proxies import current_oauthclient

Expand Down Expand Up @@ -82,7 +84,7 @@ def disconnect_github(access_token, repo_hooks):
hook = ghrepo.hook(repo_hook)
if hook and hook.delete():
current_app.logger.info(
"Deleted hook from github repository.",
_("Deleted hook from github repository."),
extra={"hook": hook.id, "repo": ghrepo.full_name},
)
# If we finished our clean-up successfully, we can revoke the token
Expand Down
14 changes: 9 additions & 5 deletions invenio_github/views/github.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
# This file is part of Invenio.
# Copyright (C) 2014, 2015, 2016 CERN.
# Copyright (C) 2024 Graz University of Technology.
# Copyright (C) 2024 KTH Royal Institute of Technology.
#
# Invenio is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
Expand All @@ -28,6 +29,7 @@
from flask import Blueprint, abort, current_app, render_template
from flask_login import current_user, login_required
from invenio_db import db
from invenio_i18n import gettext as _
from sqlalchemy.orm.exc import NoResultFound

from invenio_github.api import GitHubAPI
Expand All @@ -45,7 +47,9 @@ def inner(*args, **kwargs):
token = github.session_token
if token:
return f(*args, **kwargs)
raise GithubTokenNotFound(current_user, "Github session token is requested")
raise GithubTokenNotFound(
current_user, _("Github session token is requested")
)

return inner

Expand Down Expand Up @@ -194,7 +198,7 @@ def enable_repository(repository_id):

if str(repository_id) not in repos:
raise RepositoryNotFoundError(
repository_id, "Failed to enable repository."
repository_id, _("Failed to enable repository.")
)

create_success = github.create_hook(
Expand All @@ -205,7 +209,7 @@ def enable_repository(repository_id):
return "", 201
else:
raise Exception(
"Failed to enable repository, hook creation not successful."
_("Failed to enable repository, hook creation not successful.")
)
except RepositoryAccessError:
abort(403)
Expand Down Expand Up @@ -235,7 +239,7 @@ def disable_repository(repository_id):

if str(repository_id) not in repos:
raise RepositoryNotFoundError(
repository_id, "Failed to disable repository."
repository_id, _("Failed to disable repository.")
)

remove_success = False
Expand All @@ -248,7 +252,7 @@ def disable_repository(repository_id):
return "", 204
else:
raise Exception(
"Failed to disable repository, hook removal not successful."
_("Failed to disable repository, hook removal not successful.")
)
except RepositoryNotFoundError:
abort(404)
Expand Down