From d34e658108c9d06a543ac43cf0a9669e226e9333 Mon Sep 17 00:00:00 2001 From: Brian Henry Date: Sun, 4 Oct 2020 19:12:42 -0400 Subject: [PATCH] update regexes to support short-form urls --- README.md | 4 ++-- index.js | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 702464d0..0f31aaae 100644 --- a/README.md +++ b/README.md @@ -7,13 +7,13 @@ The action looks for Trello card URLs at the start of a Pull Request description Optionally, this can be configured to also attach (redundant) PR comments with card links/names, similar to what the Trello Power-up will do, for use cases requiring that. ## Link-Finding -URLs need to each be on own line (leading/trailing whitespace and extra blank lines don't matter), and be at top of PR body. URLs embedded in other text are ignored, as are URLs after descriptive (i.e., non-link) text starts. +URLs need to each be on own line (leading/trailing whitespace and extra blank lines don't matter), and be at top of PR body. URLs embedded in other text are ignored, as are URLs after descriptive (i.e., non-link) text starts. Both the short-form (from the "Link to this card" field provided by a card's "Share" button) or long-form (cmd/ctrl+c with card open, copy from url bar with card open, etc.) are supported. So, for : ```text https://trello.com/c/aaaaaaaa -https://trello.com/c/bbbbbbbbb +https://trello.com/c/bbbbbbbbb/111-qqqqqqqqqqqq This PR impl's the above 2 features. These work similarly to feature https://trello.com/c/ccccccccc. The below is a random trello url put in this body, for some reason: https://trello.com/c/dddddddd diff --git a/index.js b/index.js index ac4d2fba..6e41fcc0 100644 --- a/index.js +++ b/index.js @@ -88,7 +88,7 @@ const extractTrelloCardIds = (prBody, stopOnNonLink = true) => { // browsers submit textareas with \r\n line breaks on all platforms const browserEol = '\r\n'; // requires that link be alone own line, and allows leading/trailing whitespace - const linkRegex = /^\s*(https\:\/\/trello\.com\/c\/(\w+)\/\S+)?\s*$/; + const linkRegex = /^\s*(https\:\/\/trello\.com\/c\/(\w+)(\/\S*)?)?\s*$/; const cardIds = []; const lines = prBody.split(browserEol); @@ -110,7 +110,7 @@ const extractTrelloCardIds = (prBody, stopOnNonLink = true) => { } const commentsContainsTrelloLink = async (cardId) => { - const linkRegex = new RegExp(`\\[[^\\]]+\\]\\(https:\\/\\/trello.com\\/c\\/${cardId}\\/[^)]+\\)`); + const linkRegex = new RegExp(`\\[[^\\]]+\\]\\(https:\\/\\/trello.com\\/c\\/${cardId}(\\/[^)]*)?\\)`); const comments = await getPrComments(); return comments.data.some((comment) => linkRegex.test(comment.body));