Determining the parent build's PR number for a promotion build

I’ve got a config that looks something like this:

  1. On pull_request events, I build and push a Docker image
  2. I then allow those pull_request-triggered builds to be promoted to various targets for testing

This works great. The one thing I’m struggling with is that I’d like to be able to post back to the original PR when the promote-triggered build completes with a status, using this plugin, but there’s no easy way I can find to get at the pull request number for the PR that triggered the parent pull_request build (DRONE_PULL_REQUEST isn’t set to anything useful in the promote build).

The closest I’ve come is attempting to munge DRONE_COMMIT_REF (which for a PR-triggered promote build looks like refs/pull/123/head) into the right shape using the string substitution feature, but I can’t figure out an incantation that quite works, since I need to strip both a prefix and a suffix.

Any ideas on how to achieve this?

(Having written that out, it now occurs to me that I could just teach the plugin how to do this transformation itself, based on the value of the DRONE_COMMIT_REF env var.)

I found another solution that’s kind of gross but at least didn’t involve making any changes to the plugin. In the environment for the comment plugin step, I introduced an intermediate env var to let me strip first the prefix and then the suffix:

        environment: {
          DRONE_COMMIT_REF_NOPREFIX: "${DRONE_COMMIT_REF#refs/pull/}",
          PLUGIN_ISSUE_NUM: "${DRONE_COMMIT_REF_NOPREFIX%/head}",
        },