From 81928c2e10585b5be7a2d5bb51da65d6db10a70f Mon Sep 17 00:00:00 2001 From: Martin Kopec Date: Wed, 12 May 2021 10:12:58 +0000 Subject: [PATCH] Update the guidelines location This patch updates the guidelines location. The guidelines will be moved there by [1]. In order to shorten the transition period we are intentionally doing this *before* [1] is merged (before the guidelines are actually moved) because it takes some time to get this change to production. Due to that the patch also implement a fail-safe mechanism - if the get request for guidelines returns 404, the code will try again with the old (at this moment the current) location. When this gets to production, we will merge [1]. Then the fail-safe mechanism will no longer be needed, therefore it will be removed in a follow up patch. [1] https://review.opendev.org/c/osf/interop/+/786116 Change-Id: I5d81d0168601f2b6c3b5cae996b531ebdb33d9d0 --- refstack/api/app.py | 7 ++++--- refstack/api/guidelines.py | 13 +++++++++++++ 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/refstack/api/app.py b/refstack/api/app.py index 3b213557..410596d5 100644 --- a/refstack/api/app.py +++ b/refstack/api/app.py @@ -81,14 +81,15 @@ API_OPTS = [ help='Template for test result url.' ), cfg.StrOpt('opendev_api_capabilities_url', - default='https://opendev.org/api/v1/repos/osf/interop/contents', + default='https://opendev.org/api/v1/repos/osf/interop/contents/' + 'previous_guidelines', help='The GitHub API URL of the repository and location of the ' 'Interop Working Group capability files. This URL is used ' 'to get a listing of all capability files.' ), cfg.StrOpt('additional_capability_urls', - default='https://opendev.org/api/v1/' - 'repos/osf/interop/contents/add-ons', + default='https://opendev.org/api/v1/repos/osf/interop/contents/' + 'add-ons/previous_guidelines', help=('The GitHub API URL of the repository and location of ' 'any additional guideline sources which will need to ' 'be parsed by the refstack API.')), diff --git a/refstack/api/guidelines.py b/refstack/api/guidelines.py index 448a2118..d252ab0d 100755 --- a/refstack/api/guidelines.py +++ b/refstack/api/guidelines.py @@ -77,6 +77,19 @@ class Guidelines: for src_url in self.guideline_sources: try: resp = requests.get(src_url) + # The following if-statement enables a transition period for + # moving the guidelines to a new location by + # https://review.opendev.org/c/osf/interop/+/786116 + # TODO(kopecmartin) remove this if-statement after the review + # is merged. + if resp.status_code == 404: + if src_url == CONF.api.additional_capability_urls: + src_url = 'https://opendev.org/api/v1/repos/osf/' + src_url += 'interop/contents/add-ons' + elif src_url == CONF.api.opendev_api_capabilities_url: + src_url = 'https://opendev.org/api/v1/repos/osf/' + src_url += 'interop/contents' + resp = requests.get(src_url) LOG.debug("Response Status: %s / Used Requests Cache: %s" % (resp.status_code,