Skip to content

Migrate attachments linked in Markdown comments and attachments

After creating an issue or a comment we need to replace the clean up the markdown to be GitLab flavored markdown

Taken from the kind people at GNOME this would mean the following things:

  • Link the attachments: Replace the strings looking like {F[0-9]+}
  • Prevent accidental links to GitLab issues
  • Make sure triple backticks are properly preserved for XML tags

For linking attachments, we'll need to use the file.search api method with the numbers matched out of the F[0-9]+ string as the { ids: [] } constraints.

The response would look like

{
      "id": 747,
      "type": "FILE",
      "phid": "PHID-FILE-ahahaha",
      "fields": {
        "name": "filename.png",
        "dataURI": "the URL from which to fetch the image",
        "size": 47765,
        "dateCreated": 1374660569,
        "dateModified": 1495767275,
        "policy": {
          "view": "users",
          "edit": "no-one"
        }
      },

We can use the filename and dataURI to download the file, store it in GitLab, and create a new markdown link.