Skip to content
Merged
Changes from all 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
103 changes: 93 additions & 10 deletions .github/workflows/codex-review.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ jobs:
concurrency:
group: codex-review-${{ github.event.pull_request.number || github.event.issue.number }}
cancel-in-progress: true
runs-on: blacksmith-2vcpu-ubuntu-2404
runs-on: ubuntu-latest
permissions:
contents: read
pull-requests: read
Expand All @@ -45,7 +45,7 @@ jobs:
ACTOR_ASSOCIATION: ${{ case(github.event_name == 'pull_request_target', github.event.pull_request.author_association, github.event.comment.author_association) }}
steps:
- name: Checkout
uses: useblacksmith/checkout@c9796daa2a4bdebdab5bd16be2c09a70cd4e1121 # v1
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
# Important: `pull_request_target` should never checkout the PR head.
ref: ${{ github.event_name == 'pull_request_target' && github.event.pull_request.base.sha || github.sha }}
Expand All @@ -60,6 +60,32 @@ jobs:
GITHUB_TOKEN: ${{ github.token }}
OS_BOTIFY_TOKEN: ${{ secrets.OS_BOTIFY_TOKEN }}

- name: Add review in progress reaction
if: steps.gate.outputs.IS_AUTHORIZED == 'true'
Comment on lines +63 to +64
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Make the in-progress reaction non-blocking

When the optional createForIssue/createForIssueComment call fails here (for example due to a transient GitHub API error or secondary rate limit), actions/github-script fails the step and the workflow never reaches the prompt build, Codex run, or feedback posting steps that follow. Since the eyes reaction is only cosmetic, this step should catch/log errors or use continue-on-error so review generation is not blocked.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I think this is fine. We want the in-progress reaction, and if it fails the workflow should end.

uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v7
env:
PR_NUMBER: ${{ env.PR_NUMBER }}
with:
script: |
const {owner, repo} = context.repo;

if (context.eventName === 'pull_request_target') {
await github.rest.reactions.createForIssue({
owner,
repo,
issue_number: Number(process.env.PR_NUMBER),
content: 'eyes',
});
return;
}

await github.rest.reactions.createForIssueComment({
owner,
repo,
comment_id: context.payload.comment.id,
content: 'eyes',
});

- name: Build Codex prompt from PR diff
if: steps.gate.outputs.IS_AUTHORIZED == 'true'
env:
Expand Down Expand Up @@ -103,25 +129,82 @@ jobs:
prompt-file: prompt.txt

- name: Post Codex feedback
if: steps.gate.outputs.IS_AUTHORIZED == 'true' && steps.codex.outputs.final-message != ''
if: steps.gate.outputs.IS_AUTHORIZED == 'true' && steps.codex.outcome == 'success'
uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v7
env:
PR_NUMBER: ${{ env.PR_NUMBER }}
CODEX_FINAL_MESSAGE: ${{ steps.codex.outputs.final-message }}
WORKFLOW_RUN_URL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
with:
script: |
const body = [
'## Codex review',
'',
process.env.CODEX_FINAL_MESSAGE,
'',
`_[Workflow run](${process.env.WORKFLOW_RUN_URL})_`,
].join('\n');
const codexMessage = process.env.CODEX_FINAL_MESSAGE?.trim() ?? '';
const body =
codexMessage === ''
? 'LGTM :+1:'
: [
'## Codex review',
'',
codexMessage,
'',
`_[Workflow run](${process.env.WORKFLOW_RUN_URL})_`,
].join('\n');

await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: Number(process.env.PR_NUMBER),
body,
});

- name: Remove review in progress reaction
if: always() && steps.gate.outputs.IS_AUTHORIZED == 'true'
Comment thread
roryabraham marked this conversation as resolved.
uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v7
env:
PR_NUMBER: ${{ env.PR_NUMBER }}
with:
script: |
const {owner, repo} = context.repo;
const botLogin = 'github-actions[bot]';

const deleteEyesReaction = async (reactions, deleteReaction) => {
const eyesReaction = reactions.find(
(reaction) => reaction.content === 'eyes' && reaction.user.login === botLogin,
);

if (eyesReaction) {
await deleteReaction(eyesReaction.id);
}
};

if (context.eventName === 'pull_request_target') {
const {data: reactions} = await github.rest.reactions.listForIssue({
owner,
repo,
issue_number: Number(process.env.PR_NUMBER),
});

await deleteEyesReaction(reactions, (reactionId) =>
github.rest.reactions.deleteForIssue({
owner,
repo,
issue_number: Number(process.env.PR_NUMBER),
reaction_id: reactionId,
}),
);
return;
}

const {data: reactions} = await github.rest.reactions.listForIssueComment({
owner,
repo,
comment_id: context.payload.comment.id,
});

await deleteEyesReaction(reactions, (reactionId) =>
github.rest.reactions.deleteForIssueComment({
owner,
repo,
comment_id: context.payload.comment.id,
reaction_id: reactionId,
}),
);
Loading