diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 0f9209d33..e2617067f 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -2,6 +2,11 @@ CHANGELOG ========= +Release 2.2.3 +--------------------- +* Added version number to template +* Bug fixes for missing author name in GitHub export + Release 2.2.2 --------------------- * Bug fixes for naming GitHub repository for export. diff --git a/apps/__init__.py b/apps/__init__.py index 09fa92559..e69de29bb 100644 --- a/apps/__init__.py +++ b/apps/__init__.py @@ -1,7 +0,0 @@ -__version__ = "2.2.2" -__version_info__ = tuple( - [ - int(num) if num.isdigit() else num - for num in __version__.replace("-", ".", 1).split(".") - ] -) diff --git a/apps/export/export.py b/apps/export/export.py index 5a98f2548..5c7921eb1 100644 --- a/apps/export/export.py +++ b/apps/export/export.py @@ -24,13 +24,12 @@ from django.core.serializers import serialize from django.template.loader import get_template from apps.users.models import User +from apps.readux import __version__ import digitaledition_jekylltheme import config.settings.local as settings from .github import GithubApi, GithubAccountNotFound -__version__ = "2.0.0" - LOGGER = logging.getLogger(__name__) # zip file of base jekyll site with digital edition templates @@ -89,7 +88,7 @@ def get_zip(self, manifest, version, owners=[]): annotators = User.objects.filter( userannotation__canvas__manifest__id=manifest.id ).distinct() - annotators_string = ', '.join([i.fullname() for i in annotators]) + annotators_string = ', '.join([i.name for i in annotators]) # pylint: enable = possibly-unused-variable # pylint: disable = line-too-long @@ -550,12 +549,19 @@ def website_gitrepo(self): # initialize export dir as a git repo, and commit the contents # NOTE: to debug git commands, print the git return to see git output + git_author = None + + if self.user.name is None or not self.user.name: + git_author = GithubApi.github_username(self.user) + else: + git_author = self.user.name + gitcmd = Git(jekyll_dir) # initialize jekyll site as a git repo gitcmd.init() # add and commit all contents gitcmd.config("user.email", self.user.email) - gitcmd.config("user.name", self.user.fullname()) + gitcmd.config("user.name", git_author) # Use the token to authenticate the Git commands. # Required to do this as of June 9, 2020 # https://developer.github.com/changes/2020-02-14-deprecating-oauth-app-endpoint/ @@ -568,7 +574,7 @@ def website_gitrepo(self): v=__version__ ), '--author="{fn} <{ue}>"'.format( - fn=self.user.fullname(), + fn=git_author, ue=self.user.email ) ]) @@ -683,7 +689,7 @@ def update_gitrepo(self): # TODO: if deep zoom is added, we must add that directory as well git_author = git.Actor( - self.user.fullname(), + self.user.name, self.user.email ) # commit all changes diff --git a/apps/export/github.py b/apps/export/github.py index 18db3e858..cf7461356 100644 --- a/apps/export/github.py +++ b/apps/export/github.py @@ -163,6 +163,19 @@ def list_user_repos(self): return repos return None + def list_repo_branches(self, repo, user): + """List branches in repository + + :param repo: Name of repository + :type repo: str + :param user: GitHub user + :type user: apps.users.models.User + :return: List of GitHub repository branch names. + :rtype: list + """ + response = self.session.get(f'{self.url}/{self.github_username(user)}/{repo}/branches') + return [branch['name'] for branch in response.json()] + def create_pull_request(self, repo, title, head, base, text=None): """Create a new pull request. https://developer.github.com/v3/pulls/#create-a-pull-request diff --git a/apps/export/tests/test_github.py b/apps/export/tests/test_github.py index 5e526cc40..14195f4df 100644 --- a/apps/export/tests/test_github.py +++ b/apps/export/tests/test_github.py @@ -123,6 +123,20 @@ def test_list_user_repos(self): repos = self.gh.list_user_repos() assert len(repos) == 6 + @httpretty.activate + def test_repo_branches(self): + resp_body = '[{"name": "branch1", "commit": {"sha": "40767", "url": ""}, "protected": "False"}, {"name": "branch2", "commit": {"sha": "40767", "url": ""}, "protected": "False"}]' + httpretty.register_uri( + httpretty.GET, + f'https://api.github.com/{self.gh.github_username(self.user)}/some-repo/branches', + body=resp_body, + content_type="text/json" + ) + + branches = self.gh.list_repo_branches('some-repo', self.user) + assert len(branches) == 2 + assert 'branch2' in branches + @httpretty.activate def test_create_pr(self): httpretty.register_uri( diff --git a/apps/readux/__init__.py b/apps/readux/__init__.py index f1edb192f..05633ca0c 100644 --- a/apps/readux/__init__.py +++ b/apps/readux/__init__.py @@ -1 +1 @@ -__version__ = '2.2.2' +__version__ = '2.2.3' diff --git a/apps/readux/context_processors.py b/apps/readux/context_processors.py new file mode 100644 index 000000000..0d148f8f8 --- /dev/null +++ b/apps/readux/context_processors.py @@ -0,0 +1,4 @@ +from . import __version__ + +def current_version(request=None): + return {'APP_VERSION': __version__} diff --git a/apps/readux/tests/tests.py b/apps/readux/tests/tests.py index 5d068933c..3a85bba73 100644 --- a/apps/readux/tests/tests.py +++ b/apps/readux/tests/tests.py @@ -4,15 +4,14 @@ from ..annotations import Annotations, AnnotationCrud from django.contrib.auth import get_user_model from django.urls import reverse -from django.template import Context, Template from django.core.serializers import serialize -from apps.iiif.annotations.models import Annotation from apps.iiif.manifests.models import Manifest +from apps import readux from ..models import UserAnnotation -from apps.readux.views import VolumesList, VolumeDetail, CollectionDetail, Collection, ExportOptions, AnnotationsCount +from ..context_processors import current_version +from apps.readux.views import VolumesList, CollectionDetail, ExportOptions, AnnotationsCount from urllib.parse import urlencode from cssutils import parseString -import warnings import json import re import uuid @@ -597,3 +596,6 @@ def test_user_annotation_count(self): assert response.context_data['page'] == self.canvas assert response.context_data['user_annotation_page_count'] == 3 assert response.context_data['user_annotation_count'] == 3 + + def test_current_version_context(self): + assert readux.__version__ == current_version()['APP_VERSION'] diff --git a/apps/templates/footer.html b/apps/templates/footer.html index fbf7f3345..f17d33026 100644 --- a/apps/templates/footer.html +++ b/apps/templates/footer.html @@ -18,7 +18,7 @@
diff --git a/config/settings/base.py b/config/settings/base.py index 9e934e58c..ce99959ef 100644 --- a/config/settings/base.py +++ b/config/settings/base.py @@ -246,6 +246,7 @@ 'apps.custom_styles.context_processors.add_custom_style', 'apps.templates.context_processors.has_ga_tracking_id', 'apps.templates.context_processors.ga_tracking_id', + 'apps.readux.context_processors.current_version', ], }, }, diff --git a/readux/__init__.py b/readux/__init__.py deleted file mode 100644 index f185a5c62..000000000 --- a/readux/__init__.py +++ /dev/null @@ -1,27 +0,0 @@ -__version_info__ = (2, 2, 2, None) - -# Dot-connect all but the last. Last is dash-connected if not None. -__version__ = '.'.join([str(i) for i in __version_info__[:-1]]) -if __version_info__[-1] is not None: - __version__ += ('-%s' % (__version_info__[-1],)) - -# context processor to add version to the template environment -def context_extras(request): - socialauth_providers = [] - # generate a list of social auth providers associated with this account, - # for use in displaying available backends - if not request.user.is_anonymous(): - socialauth_providers = [auth.provider for auth in request.user.social_auth.all()] - return { - # software version - 'SW_VERSION': __version__, - # Alternate names for social-auth backends, - # to be used for display and font-awesome icon (lowercased) - # If not entered here, backend name will be used as-is for - # icon and title-cased for display (i.e., twitter / Twitter). - 'backend_names': { - 'github': 'GitHub', - 'google-oauth2': 'Google', - }, - 'user_socialauth_providers': socialauth_providers - }