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

Commit

Permalink
Merge pull request #13 from delivered/allow-short-card-link
Browse files Browse the repository at this point in the history
update regexes to support short-form urls
  • Loading branch information
Brian Henry authored Oct 4, 2020
2 parents 322c4e7 + 8c54956 commit 411e2e1
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 5 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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "attach-to-trello-card-action",
"version": "2.0.0",
"version": "2.0.1",
"description": "Github Action: Add attachment to a given Trello card URL (e.g., pull request)",
"main": "index.js",
"scripts": {
Expand Down

0 comments on commit 411e2e1

Please sign in to comment.