Skip to content

Commit 8eb843b

Browse files
authored
Merge pull request #201 from wikando-ck/feat/multi-directory-working-dirs
feat: add working directory to comment locator for monorepo support
2 parents 40e3bdf + 0c73468 commit 8eb843b

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

generate-comments/comment.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44

55
$diff = file_get_contents('/workdir/' . $argv[1] . '.md');
66
$prNumber = json_decode(file_get_contents(getenv('GITHUB_EVENT_PATH')), true)['pull_request']['number'];
7-
$locator = '<!-- @)}---^----- wyrihaximus/github-action-composer.lock-diff ' . getenv('GITHUB_WORKFLOW') . ' __/<+>\__ ' . $argv[1] . ' -----^---{(@ -->';
7+
$workingDirectory = getenv('INPUT_WORKINGDIRECTORY') ?: '/';
8+
$locator = '<!-- @)}---^----- wyrihaximus/github-action-composer.lock-diff ' . getenv('GITHUB_WORKFLOW') . ' __/<+>\__ ' . $argv[1] . ' __/<*>\__ ' . $workingDirectory . ' -----^---{(@ -->';
9+
$legacyLocator = '<!-- @)}---^----- wyrihaximus/github-action-composer.lock-diff ' . getenv('GITHUB_WORKFLOW') . ' __/<+>\__ ' . $argv[1] . ' -----^---{(@ -->';
810
$commentContents = $locator . PHP_EOL . $argv[2] . PHP_EOL . $diff . PHP_EOL;
911

1012
$client = new GuzzleHttp\Client();
@@ -17,7 +19,9 @@
1719
$comments = json_decode($res->getBody()->getContents(), true);
1820

1921
foreach ($comments as $comment) {
20-
if (strpos($comment['body'], $locator) === 0) {
22+
$isCurrentLocator = strpos($comment['body'], $locator) === 0;
23+
$isLegacyLocator = !$isCurrentLocator && !getenv('INPUT_WORKINGDIRECTORY') && strpos($comment['body'], $legacyLocator) === 0;
24+
if ($isCurrentLocator || $isLegacyLocator) {
2125
if (strlen($diff) === 0) {
2226
echo 'Deleting ', $argv[1], ' comment', PHP_EOL;
2327
$client->request('DELETE', 'https://api.github.com/repos/' . getenv('GITHUB_REPOSITORY') . '/issues/comments/' . $comment['id'], [

generate-comments/entrypoint.sh

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,13 @@ echo "${delimiter}" >> "${GITHUB_OUTPUT}"
4545
if [ "$INPUT_DRYRUN" != "yes" ]
4646
then
4747
echo "Not in a dry run so upserting comments when desirable"
48-
php /workdir/comment.php production "🏰 Composer Production Dependency changes 🏰"
49-
php /workdir/comment.php development "🚧 Composer Development Dependency changes 🚧"
48+
if [ -n "${workingDirectory}" ]; then
49+
directoryLabel=" (${workingDirectory%/})"
50+
else
51+
directoryLabel=""
52+
fi
53+
php /workdir/comment.php production "🏰 Composer Production Dependency changes${directoryLabel} 🏰"
54+
php /workdir/comment.php development "🚧 Composer Development Dependency changes${directoryLabel} 🚧"
5055
else
5156
echo "In a dry run so not upserting comments when desirable"
5257
fi

0 commit comments

Comments
 (0)