Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit f6b6762

Browse files
authored
Issue bot: Emit GitHub Action annotation when issues are affected
1 parent 1c270d8 commit f6b6762

File tree

2 files changed

+30
-4
lines changed

2 files changed

+30
-4
lines changed

‎.github/workflows/issue-bot.yml

Lines changed: 22 additions & 2 deletions
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 "::notice file=.github/workflows/issue-bot.yml,line=3 ::Issue bot detected open issues which are affected by this pull request - see https://github.com/$GITHUB_REPOSITORY/actions/runs/$GITHUB_RUN_ID"
170+
exit 0
171+
fi
172+
173+
exit $exit_code
164174
165175
- name: "Evaluate results - push"
166176
working-directory: "issue-bot"
@@ -169,4 +179,14 @@ jobs:
169179
GITHUB_PAT: ${{ secrets.PHPSTAN_BOT_TOKEN }}
170180
PHPSTAN_SRC_COMMIT_BEFORE: ${{ github.event.before }}
171181
PHPSTAN_SRC_COMMIT_AFTER: ${{ github.event.after }}
172-
run: ./console.php evaluate --post-comments >> $GITHUB_STEP_SUMMARY
182+
run: |
183+
set +e
184+
./console.php evaluate --post-comments >> $GITHUB_STEP_SUMMARY
185+
exit_code="$?"
186+
187+
# its fine when issue-bot found affected issues
188+
if [[ "$exit_code" == "2" ]]; then
189+
exit 0
190+
fi
191+
192+
exit $exit_code

‎issue-bot/src/Console/EvaluateCommand.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@
3333
class EvaluateCommand extends Command
3434
{
3535

36+
private const EXIT_ERROR = 1;
37+
private const EXIT_AFFECTS_ISSUES = 2;
38+
private const EXIT_NO_AFFECTED_ISSUES = 0;
39+
3640
public function __construct(
3741
private TabCreator $tabCreator,
3842
private PostGenerator $postGenerator,
@@ -133,7 +137,9 @@ protected function execute(InputInterface $input, OutputInterface $output): int
133137
}
134138
}
135139

140+
$exitCode = self::EXIT_AFFECTS_ISSUES;
136141
if (count($toPost) === 0) {
142+
$exitCode = self::EXIT_NO_AFFECTED_ISSUES;
137143
$output->writeln(sprintf('No changes in results in %d code snippets from %d GitHub issues. :tada:', $totalCodeSnippets, count($issueCache->getIssues())));
138144
}
139145

@@ -163,7 +169,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
163169
if ($postComments) {
164170
if (count($toPost) > 20) {
165171
$output->writeln('Too many comments to post, something is probably wrong.');
166-
return 1;
172+
return self::EXIT_ERROR;
167173
}
168174
foreach ($toPost as ['issue' => $issue, 'hash' => $hash, 'users' => $users, 'diff' => $diff, 'details' => $details]) {
169175
$text = sprintf(
@@ -191,7 +197,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
191197
}
192198
}
193199

194-
return 0;
200+
return $exitCode;
195201
}
196202

197203
/**

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /