Skip to content
Closed
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
34 changes: 30 additions & 4 deletions .github/workflows/copilot-review.yml
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ jobs:
EVENT_BASE_REF: ${{ github.event.pull_request.base.ref }}
EVENT_BODY: ${{ github.event.pull_request.body }}
EVENT_TITLE: ${{ github.event.pull_request.title }}
EVENT_UPDATED_AT: ${{ github.event.pull_request.updated_at }}
EVENT_EDITED_AT: ${{ github.event.pull_request.updated_at }}
GH_TOKEN: ${{ github.token }}
HEAD_SHA: ${{ github.event.pull_request.head.sha }}
HEAD_REF: ${{ github.event.pull_request.head.ref }}
Expand Down Expand Up @@ -280,6 +280,34 @@ jobs:
[[ "${BASE_SHA}" =~ ^[0-9a-f]{40}$ ]]
[[ "${HEAD_SHA}" =~ ^[0-9a-f]{40}$ ]]
[[ "${PR_NUMBER}" =~ ^[1-9][0-9]*$ ]]
# For an edited webhook, REST updated_at is the event's edit
# revision. Bind it to GraphQL lastEditedAt because unrelated
# comments and reviews may advance only the live REST updated_at.
[[ "${EVENT_EDITED_AT}" =~ ^[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}Z$ ]]
owner="${REPOSITORY%%/*}"
repository="${REPOSITORY#*/}"
read -r -d '' query <<'GRAPHQL' || true
query($owner: String!, $repository: String!, $number: Int!) {
repository(owner: $owner, name: $repository) {
pullRequest(number: $number) {
number
lastEditedAt
}
}
}
GRAPHQL
metadata="$(api_read graphql \
-f query="${query}" \
-F owner="${owner}" \
-F repository="${repository}" \
-F number="${PR_NUMBER}")"
jq -e \
--arg edited_at "${EVENT_EDITED_AT}" \
--argjson number "${PR_NUMBER}" '
((.errors // []) | length) == 0
and .data.repository.pullRequest.number == $number
and .data.repository.pullRequest.lastEditedAt == $edited_at
' <<<"${metadata}" >/dev/null
pr="$(api_read "repos/${REPOSITORY}/pulls/${PR_NUMBER}")"
jq -e \
--arg base_ref "${EVENT_BASE_REF}" \
Expand All @@ -288,11 +316,9 @@ jobs:
--arg head_ref "${HEAD_REF}" \
--arg head_sha "${HEAD_SHA}" \
--arg repository "${REPOSITORY}" \
--arg title "${EVENT_TITLE}" \
--arg updated_at "${EVENT_UPDATED_AT}" '
--arg title "${EVENT_TITLE}" '
.state == "open"
and .draft == false
and .updated_at == $updated_at
and .title == $title
and (.body // "") == $body
and .base.ref == $base_ref
Expand Down
Loading