Skip to content

Commit 55b918e

Browse files
committed
Issue-Bot: Emit GitHub Action annotation when issues are affected
1 parent 1c270d8 commit 55b918e

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

.github/workflows/issue-bot.yml

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,17 @@ jobs:
160160
if: github.event_name == 'pull_request'
161161
env:
162162
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
163-
run: ./console.php evaluate >> $GITHUB_STEP_SUMMARY
163+
run: |
164+
set +e
165+
./console.php evaluate >> $GITHUB_STEP_SUMMARY
166+
exit_code="$?"
167+
168+
if [[ "$exit_code" == "2" ]]; then
169+
echo "##[info]Issue bot detected open issues which are affected by this pull request."
170+
exit 0
171+
fi
172+
173+
exit $exit_code
164174
165175
- name: "Evaluate results - push"
166176
working-directory: "issue-bot"

issue-bot/src/Console/EvaluateCommand.php

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

3333
class EvaluateCommand extends Command
3434
{
35+
const EXIT_ERROR = 1;
36+
const EXIT_AFFECTS_ISSUES = 2;
37+
const EXIT_NO_AFFECTED_ISSUES = 0;
3538

3639
public function __construct(
3740
private TabCreator $tabCreator,
@@ -133,7 +136,9 @@ protected function execute(InputInterface $input, OutputInterface $output): int
133136
}
134137
}
135138

139+
$exitCode = self::EXIT_AFFECTS_ISSUES;
136140
if (count($toPost) === 0) {
141+
$exitCode = self::EXIT_NO_AFFECTED_ISSUES;
137142
$output->writeln(sprintf('No changes in results in %d code snippets from %d GitHub issues. :tada:', $totalCodeSnippets, count($issueCache->getIssues())));
138143
}
139144

@@ -163,7 +168,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
163168
if ($postComments) {
164169
if (count($toPost) > 20) {
165170
$output->writeln('Too many comments to post, something is probably wrong.');
166-
return 1;
171+
return self::EXIT_ERROR;
167172
}
168173
foreach ($toPost as ['issue' => $issue, 'hash' => $hash, 'users' => $users, 'diff' => $diff, 'details' => $details]) {
169174
$text = sprintf(
@@ -191,7 +196,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
191196
}
192197
}
193198

194-
return 0;
199+
return $exitCode;
195200
}
196201

197202
/**

0 commit comments

Comments
 (0)