Skip to content

Commit 71ec763

Browse files
author
Ashishkasaudhan
committed
added new workflow
1 parent 483aa96 commit 71ec763

File tree

1 file changed

+47
-28
lines changed

1 file changed

+47
-28
lines changed

.github/workflows/issue_team_pr.yaml

Lines changed: 47 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -173,50 +173,69 @@ jobs:
173173
if: env.maintainers != '_No response_' || env.team_members != '_No response_'
174174
shell: bash
175175
run: |
176-
# Function to validate a GitHub username
177-
validate_username() {
176+
# Function to validate GitHub username format
177+
validate_username_format() {
178+
local username=$1
179+
# GitHub username regex: between 1-39 alphanumeric or hyphen characters
180+
# Cannot start or end with hyphen, no consecutive hyphens
181+
local username_regex='^[a-zA-Z0-9](?:[a-zA-Z0-9]|-(?=[a-zA-Z0-9])){0,38}$'
182+
if [[ ! "$username" =~ $username_regex ]]; then
183+
echo "::error::Invalid GitHub username format: '$username'"
184+
echo "GitHub usernames must:"
185+
echo "- Be 1-39 characters long"
186+
echo "- Contain only alphanumeric characters or hyphens"
187+
echo "- Not start or end with a hyphen"
188+
echo "- Not contain consecutive hyphens"
189+
exit 1
190+
fi
191+
}
192+
193+
# Function to check if username exists on GitHub
194+
validate_username_existence() {
178195
local username=$1
179196
response=$(curl -s -H "Authorization: token $GITHUB_TOKEN" "https://api.github.com/users/$username")
180197
if echo "$response" | grep -q '"login":'; then
181198
echo "✅ Valid GitHub user: $username"
182199
else
183-
echo "::error::❌ Invalid or non-existent GitHub user: $username"
184-
echo "Response: $response"
200+
echo "::error::❌ GitHub user does not exist: $username"
201+
echo "API Response: $response"
185202
exit 1
186203
fi
187204
}
188205
189-
echo "Checking for users to validate..."
190-
191-
# Validate maintainers if defined
192-
if [[ "$MAINTAINERS" != "_No response_" && "$MAINTAINERS" != "none" && -n "$MAINTAINERS" ]]; then
193-
echo "Validating maintainers..."
194-
IFS=',' read -ra MAINTAINER_ARRAY <<< "$MAINTAINERS"
195-
for user in "${MAINTAINER_ARRAY[@]}"; do
196-
trimmed=$(echo "$user" | xargs)
197-
[ -n "$trimmed" ] && validate_username "$trimmed"
198-
done
199-
else
200-
echo "No maintainers to validate"
201-
fi
206+
# Main validation logic
207+
validate_users() {
208+
local user_type=$1
209+
local users=$2
210+
211+
echo "Processing $user_type..."
212+
if [[ "$users" == "_No response_" || "$users" == "none" || -z "$users" ]]; then
213+
echo "No $user_type to validate"
214+
return
215+
fi
202216
203-
# Validate team members if defined
204-
if [[ "$TEAM_MEMBERS" != "_No response_" && "$TEAM_MEMBERS" != "none" && -n "$TEAM_MEMBERS" ]]; then
205-
echo "Validating team members..."
206-
IFS=',' read -ra MEMBER_ARRAY <<< "$TEAM_MEMBERS"
207-
for user in "${MEMBER_ARRAY[@]}"; do
208-
trimmed=$(echo "$user" | xargs)
209-
[ -n "$trimmed" ] && validate_username "$trimmed"
217+
IFS=',' read -ra USER_ARRAY <<< "$users"
218+
for user in "${USER_ARRAY[@]}"; do
219+
trimmed=$(echo "$user" | xargs) # Trim whitespace
220+
if [ -z "$trimmed" ]; then
221+
echo "::warning::Empty username found in $user_type list"
222+
continue
223+
fi
224+
225+
echo "Validating $user_type: '$trimmed'"
226+
validate_username_format "$trimmed"
227+
validate_username_existence "$trimmed"
210228
done
211-
else
212-
echo "No team members to validate"
213-
fi
229+
}
230+
231+
# Validate both maintainers and team members
232+
validate_users "maintainers" "$MAINTAINERS"
233+
validate_users "team members" "$TEAM_MEMBERS"
214234
env:
215235
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
216236
MAINTAINERS: ${{ env.maintainers }}
217237
TEAM_MEMBERS: ${{ env.team_members }}
218238

219-
220239
- name: Create Pull Request for Team
221240
if: steps.classify.outputs.type == 'team'
222241
uses: peter-evans/create-pull-request@v5

0 commit comments

Comments
 (0)