Skip to content
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 21 additions & 2 deletions .github/workflows/issue-bot.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# https://help.github.com/en/categories/automating-your-workflow-with-github-actions

name: "Issue bot"

Check notice on line 3 in .github/workflows/issue-bot.yml

View workflow job for this annotation

GitHub Actions / Evaluate results

Issue bot detected open issues which are affected by this pull request - see https://github.com/phpstan/phpstan-src/actions/runs/17676622064

on:
workflow_dispatch:
Expand Down Expand Up @@ -160,7 +160,17 @@
if: github.event_name == 'pull_request'
env:
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
run: ./console.php evaluate >> $GITHUB_STEP_SUMMARY
run: |
set +e
./console.php evaluate >> $GITHUB_STEP_SUMMARY
exit_code="$?"

if [[ "$exit_code" == "2" ]]; then
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"
exit 0
fi

exit $exit_code

- name: "Evaluate results - push"
working-directory: "issue-bot"
Expand All @@ -169,4 +179,13 @@
GITHUB_PAT: ${{ secrets.PHPSTAN_BOT_TOKEN }}
PHPSTAN_SRC_COMMIT_BEFORE: ${{ github.event.before }}
PHPSTAN_SRC_COMMIT_AFTER: ${{ github.event.after }}
run: ./console.php evaluate --post-comments >> $GITHUB_STEP_SUMMARY
run: |
set +e
./console.php evaluate --post-comments >> $GITHUB_STEP_SUMMARY

# its fine when issue-bot found affected issues
if [[ "$exit_code" == "2" ]]; then
exit 0
fi

exit $exit_code
12 changes: 10 additions & 2 deletions issue-bot/src/Console/EvaluateCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@
class EvaluateCommand extends Command
{

private const EXIT_ERROR = 1;
private const EXIT_AFFECTS_ISSUES = 2;
private const EXIT_NO_AFFECTED_ISSUES = 0;

public function __construct(
private TabCreator $tabCreator,
private PostGenerator $postGenerator,
Expand Down Expand Up @@ -133,9 +137,13 @@ protected function execute(InputInterface $input, OutputInterface $output): int
}
}

$exitCode = self::EXIT_AFFECTS_ISSUES;
if (count($toPost) === 0) {
$exitCode = self::EXIT_NO_AFFECTED_ISSUES;
$output->writeln(sprintf('No changes in results in %d code snippets from %d GitHub issues. :tada:', $totalCodeSnippets, count($issueCache->getIssues())));
}
// XXX debug test
$exitCode = self::EXIT_AFFECTS_ISSUES;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

todo: remove this debug line, which atm enforce rendering of the github action annotation message


foreach ($toPost as ['issue' => $issue, 'hash' => $hash, 'users' => $users, 'diff' => $diff, 'details' => $details]) {
$text = sprintf(
Expand Down Expand Up @@ -163,7 +171,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
if ($postComments) {
if (count($toPost) > 20) {
$output->writeln('Too many comments to post, something is probably wrong.');
return 1;
return self::EXIT_ERROR;
}
foreach ($toPost as ['issue' => $issue, 'hash' => $hash, 'users' => $users, 'diff' => $diff, 'details' => $details]) {
$text = sprintf(
Expand Down Expand Up @@ -191,7 +199,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
}
}

return 0;
return $exitCode;
}

/**
Expand Down
Loading