Skip to content

Commit aaab484

Browse files
Merge branch 'main' into child
Signed-off-by: Mukund Jha <[email protected]>
2 parents e2e4055 + 5841133 commit aaab484

33 files changed

+691
-183
lines changed

.github/scripts/bot-advanced-check.sh

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -89,26 +89,20 @@ get_intermediate_count() {
8989
already_commented() {
9090
local user=$1
9191
local marker="$COMMENT_MARKER_PREFIX @$user"
92-
9392
gh issue view "$ISSUE_NUMBER" --repo "$REPO" \
9493
--json comments \
95-
--jq --arg marker "$marker" '
96-
.comments[].body
97-
| select(contains($marker))
98-
' | grep -q .
94+
--jq '.comments[].body' | grep -Fq "$marker"
9995
}
10096

10197
#######################################
10298
# Helper: is user currently assigned?
10399
#######################################
100+
104101
is_assigned() {
105102
local user=$1
106-
107103
gh issue view "$ISSUE_NUMBER" --repo "$REPO" \
108104
--json assignees \
109-
--jq --arg user "$user" '
110-
.assignees[].login | select(. == $user)
111-
' | grep -q .
105+
--jq '.assignees[].login' | grep -Fxq "$user"
112106
}
113107

114108
#######################################
@@ -215,8 +209,20 @@ $COMMENT_MARKER_PREFIX @$user"
215209
fi
216210

217211
if is_assigned "$user"; then
218-
log "Unassigning @$user."
219-
gh issue edit "$ISSUE_NUMBER" --repo "$REPO" --remove-assignee "$user"
212+
log "Unassigning @$user ..."
213+
json_body="{\"assignees\": [\"$user\"]}"
214+
response=$(
215+
gh api \
216+
--method DELETE \
217+
"repos/$REPO/issues/$ISSUE_NUMBER/assignees" \
218+
--input <(echo "$json_body") \
219+
|| echo "error"
220+
)
221+
if [[ "$response" != "error" ]]; then
222+
log "Successfully unassigned @$user."
223+
else
224+
log "Failed to unassign @$user."
225+
fi
220226
else
221227
log "User @$user already unassigned. Skipping."
222228
fi
@@ -248,4 +254,4 @@ else
248254
while read -r user; do
249255
[[ -n "$user" ]] && check_user "$user"
250256
done <<< "$ASSIGNEES"
251-
fi
257+
fi

.github/scripts/bot-gfi-assign-on-comment.js

Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -146,28 +146,41 @@ async function isRepoCollaborator({ github, owner, repo, username }) {
146146
}
147147

148148
try {
149-
await github.rest.repos.checkCollaborator({
149+
const response = await github.rest.repos.getCollaboratorPermissionLevel({
150150
owner,
151151
repo,
152152
username,
153153
});
154-
return true; // 204 = collaborator
154+
155+
const permission = response?.data?.permission;
156+
157+
const isTeamMember =
158+
permission === 'admin' ||
159+
permission === 'write' ||
160+
permission === 'maintain' ||
161+
permission === 'read';
162+
163+
console.log('[gfi-assign] isRepoCollaborator:', {
164+
username,
165+
permission,
166+
isTeamMember,
167+
});
168+
169+
return isTeamMember;
155170
} catch (error) {
156-
if (error?.status === 404 || isPermissionFailure(error)) {
157-
if (isPermissionFailure(error)) {
158-
console.log(
159-
'[gfi-assign] isRepoCollaborator: insufficient permissions; treating as non-collaborator',
160-
{ owner, repo, username, status: error.status }
161-
);
162-
}
171+
if (isPermissionFailure(error) || error?.status === 404) {
172+
console.log(
173+
'[gfi-assign] isRepoCollaborator: no permission / not collaborator',
174+
{ username, status: error.status }
175+
);
163176
return false;
164177
}
165-
throw error; // unexpected error
178+
throw error;
166179
}
167-
168180
}
169181

170182

183+
171184
/// START OF SCRIPT ///
172185
module.exports = async ({ github, context }) => {
173186
try {
@@ -220,7 +233,7 @@ module.exports = async ({ github, context }) => {
220233
username,
221234
});
222235

223-
if (isTeamMember) {
236+
if (isTeamMember) {
224237
console.log('[gfi-assign] Skip reminder: commenter is collaborator');
225238
return;
226239
}
@@ -397,4 +410,4 @@ module.exports = async ({ github, context }) => {
397410
});
398411
throw error;
399412
}
400-
};
413+
};

0 commit comments

Comments
 (0)