Skip to content
This repository has been archived by the owner on Dec 1, 2023. It is now read-only.

Commit

Permalink
update regexes to support short-form urls
Browse files Browse the repository at this point in the history
  • Loading branch information
Brian Henry committed Oct 4, 2020
1 parent a2cb319 commit d34e658
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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));
Expand Down

0 comments on commit d34e658

Please sign in to comment.