Skip to content

Commit 91e3c65

Browse files
committed
labels: make authorship reconciliation idempotent
1 parent 83bbc6b commit 91e3c65

1 file changed

Lines changed: 23 additions & 5 deletions

File tree

.github/workflows/agent-authorship-label.yml

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,26 @@ jobs:
159159
grep -Fxq "${label}" <<<"${current_labels}"
160160
}
161161
162+
authorship_labels=(agent-authored agent-assisted mixed-authorship human-authored)
163+
conflicting_labels=()
164+
has_desired_label=false
165+
166+
for label in "${authorship_labels[@]}"; do
167+
if ! has_label "${label}"; then
168+
continue
169+
fi
170+
if [ "${label}" = "${AUTHORSHIP_LABEL}" ]; then
171+
has_desired_label=true
172+
else
173+
conflicting_labels+=("${label}")
174+
fi
175+
done
176+
177+
if [ "${has_desired_label}" = true ] && [ "${#conflicting_labels[@]}" -eq 0 ]; then
178+
echo "Authorship label ${AUTHORSHIP_LABEL} is already current on #${PR_NUMBER}; no label changes needed."
179+
exit 0
180+
fi
181+
162182
delete_label_if_present() {
163183
local label="$1"
164184
local stderr_file
@@ -184,13 +204,11 @@ jobs:
184204
return "${status}"
185205
}
186206
187-
for label in agent-authored agent-assisted mixed-authorship human-authored; do
188-
if [ "${label}" != "${AUTHORSHIP_LABEL}" ] && has_label "${label}"; then
189-
delete_label_if_present "${label}"
190-
fi
207+
for label in "${conflicting_labels[@]}"; do
208+
delete_label_if_present "${label}"
191209
done
192210
193-
if ! has_label "${AUTHORSHIP_LABEL}"; then
211+
if [ "${has_desired_label}" != true ]; then
194212
gh api --method POST "repos/${GITHUB_REPOSITORY}/issues/${PR_NUMBER}/labels" \
195213
-f "labels[]=${AUTHORSHIP_LABEL}" >/dev/null
196214
fi

0 commit comments

Comments
 (0)