Repository: jupyterhub/repo2docker (Python)

Issue:
Packagemanager.rstudio.com migration broke R buildpack
<!-- Thank you for contributing. These HTML commments will not render in the issue, but you can delete them once you've read them if you prefer! -->

### Bug description

Per https://status.posit.co/ Rstudio-now-Posit PackageManager server was migrated from https://packagemanager.rstudio.com to https://packagemanager.posit.co/. `RBuildPack.get_rspm_snapshot_url` doesn't handle the redirect properly.
<!-- Use this section to clearly and concisely describe the bug. -->

#### Expected behaviour

r2d outputs Dockerfile to stdout
<!-- Tell us what you thought would happen. -->

#### Actual behaviour

```
[Repo2Docker] Looking for repo2docker_config in /tmp/a
Picked Local content provider.
Using local repo ..
Traceback (most recent call last):
  File "/home/xarth/codes/jupyterhub/repo2docker/venv/lib/python3.10/site-packages/requests/models.py", line 971, in json
    return complexjson.loads(self.text, **kwargs)
  File "/usr/lib/python3.10/json/__init__.py", line 346, in loads
    return _default_decoder.decode(s)
  File "/usr/lib/python3.10/json/decoder.py", line 340, in decode
    raise JSONDecodeError("Extra data", s, end)
json.decoder.JSONDecodeError: Extra data: line 1 column 5 (char 4)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/xarth/codes/jupyterhub/repo2docker/venv/bin/jupyter-repo2docker", line 33, in <module>
    sys.exit(load_entry_point('jupyter-repo2docker', 'console_scripts', 'jupyter-repo2docker')())
  File "/home/xarth/codes/jupyterhub/repo2docker/repo2docker/__main__.py", line 469, in main
    r2d.start()
  File "/home/xarth/codes/jupyterhub/repo2docker/repo2docker/app.py", line 850, in start
    self.build()
  File "/home/xarth/codes/jupyterhub/repo2docker/repo2docker/app.py", line 799, in build
    print(picked_buildpack.render(build_args))
  File "/home/xarth/codes/jupyterhub/repo2docker/repo2docker/buildpacks/base.py", line 464, in render
    for user, script in self.get_build_scripts():
  File "/home/xarth/codes/jupyterhub/repo2docker/repo2docker/buildpacks/r.py", line 278, in get_build_scripts
    cran_mirror_url = self.get_cran_mirror_url(self.checkpoint_date)
  File "/home/xarth/codes/jupyterhub/repo2docker/repo2docker/buildpacks/r.py", line 241, in get_cran_mirror_url
    return self.get_rspm_snapshot_url(snapshot_date)
  File "/home/xarth/codes/jupyterhub/repo2docker/repo2docker/buildpacks/r.py", line 209, in get_rspm_snapshot_url
    ).json()
  File "/home/xarth/codes/jupyterhub/repo2docker/venv/lib/python3.10/site-packages/requests/models.py", line 975, in json
    raise RequestsJSONDecodeError(e.msg, e.doc, e.pos)
requests.exceptions.JSONDecodeError: Extra data: line 1 column 5 (char 4)
```
<!-- Tell us what you actually happens. -->

### How to reproduce

<!-- Use this section to describe the steps that a user would take to experience this bug. -->

1. `mkdir /tmp/foo`
2. `echo "r-2022-05-05" > /tmp/foo/runtime.txt`
3. `jupyter-repo2docker --no-build --debug /tmp/foo`
4. See error

### Your personal set up

<!-- Tell us a little about the system you're using. You can see the guidelines for setting up and reporting this information at https://repo2docker.readthedocs.io/en/latest/contributing/contributing.html#setting-up-for-local-development. -->

- OS: Linux
- Docker version: 24.0.0
- repo2docker version: 2022.10.0+69.g364bf2e.dirty  (dirty cause I already tested a patch)



Discussion:
Will there be a release with this fix in soon?



Patch:
diff --git a/docs/source/howto/languages.rst b/docs/source/howto/languages.rst
index abf76e0a1..75ea7e537 100644
--- a/docs/source/howto/languages.rst
+++ b/docs/source/howto/languages.rst
@@ -66,11 +66,11 @@ by adding a :ref:`install.R<install.R>` file to your repo. RStudio and IRKernel
 installed by default for all R versions.
 
 If you request R 4.1 or later, or specify a snapshot date newer than
-``2022-01-01``, `packagemanager.rstudio.com <https://packagemanager.rstudio.com/client/#/>`_
+``2022-01-01``, `packagemanager.posit.co <https://packagemanager.posit.co/client/#/>`_
 will be used to provide much faster installations via `binary packages <https://www.rstudio.com/blog/package-manager-v1-1-no-interruptions/>`_.
 For *some* packages, this might require you install underlying system libraries
 using :ref:`apt.txt` - look at the page for the CRAN package you are interested in at
-`packagemanager.rstudio.com <https://packagemanager.rstudio.com/client/#/>`_ to find
+`packagemanager.posit.co <https://packagemanager.posit.co/client/#/>`_ to find
 a list.
 
 For older R versions with an older snapshot date, `MRAN <https://mran.microsoft.com/>`_
diff --git a/repo2docker/buildpacks/r.py b/repo2docker/buildpacks/r.py
index 03aa4ae61..26190c742 100644
--- a/repo2docker/buildpacks/r.py
+++ b/repo2docker/buildpacks/r.py
@@ -22,8 +22,8 @@ class RBuildPack(PythonBuildPack):
 
        Where 'year', 'month' and 'date' refer to a specific
        date whose CRAN snapshot we will use to fetch packages.
-       Uses https://packagemanager.rstudio.com, or MRAN if no snapshot
-       is found on packagemanager.rstudio.com
+       Uses https://packagemanager.posit.co, or MRAN if no snapshot
+       is found on packagemanager.posit.co
 
     2. A `DESCRIPTION` file signaling an R package
 
@@ -204,7 +204,7 @@ def get_packages(self):
     def get_rspm_snapshot_url(self, snapshot_date, max_days_prior=7):
         for i in range(max_days_prior):
             snapshots = requests.post(
-                "https://packagemanager.rstudio.com/__api__/url",
+                "https://packagemanager.posit.co/__api__/url",
                 # Ask for midnight UTC snapshot
                 json={
                     "repo": "all",
@@ -216,11 +216,11 @@ def get_rspm_snapshot_url(self, snapshot_date, max_days_prior=7):
             # Construct a snapshot URL that will give us binary packages for Ubuntu Bionic (18.04)
             if "upsi" in snapshots:
                 return (
-                    "https://packagemanager.rstudio.com/all/__linux__/bionic/"
+                    "https://packagemanager.posit.co/all/__linux__/bionic/"
                     + snapshots["upsi"]
                 )
         raise ValueError(
-            "No snapshot found for {} or {} days prior in packagemanager.rstudio.com".format(
+            "No snapshot found for {} or {} days prior in packagemanager.posit.co".format(
                 snapshot_date.strftime("%Y-%m-%d"), max_days_prior
             )
         )
@@ -229,7 +229,7 @@ def get_rspm_snapshot_url(self, snapshot_date, max_days_prior=7):
     def get_mran_snapshot_url(self, snapshot_date, max_days_prior=7):
         for i in range(max_days_prior):
             try_date = snapshot_date - datetime.timedelta(days=i)
-            # Fall back to MRAN if packagemanager.rstudio.com doesn't have it
+            # Fall back to MRAN if packagemanager.posit.co doesn't have it
             url = f"https://mran.microsoft.com/snapshot/{try_date.isoformat()}"
             r = requests.head(url)
             if r.ok:
@@ -258,11 +258,11 @@ def get_devtools_snapshot_url(self):
         devtools is part of our 'core' base install, so we should have some
         control over what version we install here.
         """
-        # Picked from https://packagemanager.rstudio.com/client/#/repos/1/overview
+        # Picked from https://packagemanager.posit.co/client/#/repos/1/overview
         # Hardcoded rather than dynamically determined from a date to avoid extra API calls
-        # Plus, we can always use packagemanager.rstudio.com here as we always install the
+        # Plus, we can always use packagemanager.posit.co here as we always install the
         # necessary apt packages.
-        return "https://packagemanager.rstudio.com/all/__linux__/bionic/2022-01-04+Y3JhbiwyOjQ1MjYyMTU7NzlBRkJEMzg"
+        return "https://packagemanager.posit.co/all/__linux__/bionic/2022-01-04+Y3JhbiwyOjQ1MjYyMTU7NzlBRkJEMzg"
 
     @lru_cache()
     def get_build_scripts(self):


Test patch:
diff --git a/tests/r/r4.0-rspm/verify b/tests/r/r4.0-rspm/verify
index 21bac29d8..835f141c0 100755
--- a/tests/r/r4.0-rspm/verify
+++ b/tests/r/r4.0-rspm/verify
@@ -8,6 +8,6 @@ if (!(version$major == "4" && as.double(version$minor) >= 0 && as.double(version
 }
 
 # The date we have chosen should give us an rspm mirror
-if (!(startsWith(options()$repos["CRAN"], "https://packagemanager.rstudio.com"))) {
+if (!(startsWith(options()$repos["CRAN"], "https://packagemanager.posit.co"))) {
   quit("yes", 1)
-}
\ No newline at end of file
+}
diff --git a/tests/unit/test_r.py b/tests/unit/test_r.py
index a5d7db7c0..7f7e5a0e1 100644
--- a/tests/unit/test_r.py
+++ b/tests/unit/test_r.py
@@ -26,7 +26,7 @@ def test_version_completion(tmpdir):
     tmpdir.chdir()
 
     with open("runtime.txt", "w") as f:
-        f.write(f"r-3.6-2019-01-01")
+        f.write("r-3.6-2019-01-01")
 
     r = buildpacks.RBuildPack()
     assert r.r_version == "3.6.3"
@@ -52,7 +52,7 @@ def test_mran_date(tmpdir, runtime, expected):
 
 def test_snapshot_rspm_date():
     test_dates = {
-        # Even though there is no snapshot specified in the interface at https://packagemanager.rstudio.com/client/#/repos/1/overview
+        # Even though there is no snapshot specified in the interface at https://packagemanager.posit.co/client/#/repos/1/overview
         # For 2021 Oct 22, the API still returns a valid URL that one can install
         # packages from - probably some server side magic that repeats our client side logic.
         # No snapshot for this date from
@@ -65,7 +65,7 @@ def test_snapshot_rspm_date():
     for requested, expected in test_dates.items():
         snapshot_url = r.get_rspm_snapshot_url(requested)
         assert snapshot_url.startswith(
-            "https://packagemanager.rstudio.com/all/__linux__/bionic/"
+            "https://packagemanager.posit.co/all/__linux__/bionic/"
             + expected.strftime("%Y-%m-%d")
         )