Skip to content

Commit 03e7287

Browse files
authored
Fix get github username pattern (#43)
* Fix get github username pattern * Add test
1 parent 802a56a commit 03e7287

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

app/Actions/ParseAndLinkifyGitHubUsernamesAction.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ public function execute(?string $releaseNotes): ?string
1616
// - `(?<!\[)` and `(?!\])` are negative lookbehind and lookahead assertions, respectively.
1717
// They ensure that the GitHub username is not preceded or followed by a square
1818
// bracket [ or ], which indicates that the username is already wrapped in a link.
19-
// - `@([A-Za-z0-9_]+)` matches the GitHub username itself. It starts with
19+
// - `@([A-Za-z0-9_-]+)` matches the GitHub username itself. It starts with
2020
// the @ symbol and consists of alphanumeric characters and underscores.
21-
$pattern = '/(?<!\[)@([A-Za-z0-9_]+)(?!\])/';
21+
$pattern = '/(?<!\[)@([A-Za-z0-9_-]+)(?!\])/';
2222

2323
$replacement = '[@$1](https://github.com/$1)';
2424

tests/Unit/Actions/ParseAndLinkifyGitHubUsernamesActionTest.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,10 @@
2424

2525
expect($result)->toEqual('This is a string with a [@username](https://github.com/username) in it.');
2626
});
27+
28+
it('replaces GitHub usernames with links if it contains -', function () {
29+
30+
$result = app(ParseAndLinkifyGitHubUsernamesAction::class)->execute('This is a string with a @user-name in it.');
31+
32+
expect($result)->toEqual('This is a string with a [@user-name](https://github.com/user-name) in it.');
33+
});

0 commit comments

Comments
 (0)