Turn "PR 478" into a link

Say "PR four seven eight" and get a link to pull request #478. One replace rule in config.yaml, placed after the step that turns spoken numbers into digits.

What you will get

You say You get
PR four seven eight is ready [#478](https://github.com/OWNER/REPO/pull/478) is ready
Can you look at PR four seven eight? Can you look at [#478](https://github.com/OWNER/REPO/pull/478)?
can you review PR four hundred seventy eight can you review [#478](https://github.com/OWNER/REPO/pull/478)

OWNER/REPO becomes your repository. In Slack the Markdown link arrives as a real link that reads #478. Every other app gets the Markdown text as it is.

How it works

Two steps of the pipeline do the work, in this order:

  1. numbers_en turns the spoken number into digits. “PR four seven eight” becomes “PR 478”. It ships in the pipeline of a new install.
  2. github_refs finds “PR” followed by digits and writes the link. This is the rule you add.

Steps

  1. Open ~/.config/parrotflow/config.yaml. From the menu bar, use Settings, then Edit Config.

  2. Add the rule under the transforms: key that is already in the file. Put your repository in place of OWNER/REPO.

    transforms:
      - name: github_refs
        description: spoken PR numbers as links
        replace:
          '[#$1](https://github.com/OWNER/REPO/pull/$1)':
            ['/\bPR\s*#?(\d+)\b/']

    A source between slashes is a regular expression. $1 in the target is the number it captured.

    A new install already defines a github_refs transform with a wider pattern. If yours has one, do not add a second. Edit OWNER/REPO in the one that is there. See the rule a new config ships.

  3. Add github_refs to the pipeline, on the line after numbers_en. This is the default pipeline with the new step:

    transcription:
      pipeline:
        - transform: fillers
        - transform: fillers_fr
          when: language == "fr"
        - transform: dates_en
        - transform: numbers_en
        - transform: github_refs
        - transform: money_en
        - transform: disfluency

    The order matters. Put github_refs above numbers_en and it sees “PR four seven eight”, which has no digits. The sentence then comes out as “PR 478 is ready”, with no link.

  4. Save the file. The app reloads it at once.

Check that it worked

The commands below use the full path to the app. If you installed with Homebrew, parrotflow runs the same binary.

Ask the app what it loaded:

/Applications/ParrotFlow.app/Contents/MacOS/ParrotFlow --check-config

The pipeline line has numbers_en right before github_refs:

  · pipeline          sentence_repair → vocabulary → transform fillers → transform fillers_fr when language == "fr" → transform dates_en → transform numbers_en → transform github_refs → transform money_en → transform disfluency

Then run one sentence through your pipeline. --replace uses your config and skips the steps that call a model.

/Applications/ParrotFlow.app/Contents/MacOS/ParrotFlow --replace "PR four seven eight is ready"
[#478](https://github.com/OWNER/REPO/pull/478) is ready

Last, dictate “PR four seven eight is ready” into a Slack message.

The rule a new config ships

A config written by a recent install defines github_refs with no step in the pipeline. It also matches “pull request”, “PR number” and issues. The words allowed between “PR” and the number come from ref_words under lists:, which ships in the same file.

lists:
  ref_words: ["number", "nr", "no", "num", "hash", "numéro"]

transforms:
  - name: github_refs
    description: spoken PR and issue numbers as links
    replace:
      '[#$1](https://github.com/OWNER/REPO/pull/$1)':
        ['/\b(?:pull request|PR|P\.R\.)\s*(?:(?:{{ref_words}})\s+)?#?(\d+)\b/']
      '[#$1](https://github.com/OWNER/REPO/issues/$1)':
        ['/\bissues?\s+(?:(?:{{ref_words}})\s+)?#?(\d+)\b/']

With your repository in both URLs and the same pipeline step, it gives:

You say You get
PR number four seven eight [#478](https://github.com/OWNER/REPO/pull/478)
pull request four seven eight [#478](https://github.com/OWNER/REPO/pull/478)
issue twelve is a duplicate [#12](https://github.com/OWNER/REPO/issues/12) is a duplicate

Limits

  • The URL names one repository. Every PR number you say links there.
  • “PR” needs its two letters together. If the recogniser writes “P R 123” with a space, the sentence is left alone.
  • Only Slack gets a real link today. Other apps get the Markdown text.
  • “the PR is ready” has no number, so nothing changes.