Files
xc-llm-ascend/tools/collect_user_first_contribution.sh
whx e2175d9c7e [Lint] Adapt lint tools for windows (#6727)
### What this PR does / why we need it?
If users run bash format.sh with `git bash` on windows system, there
exists `Executable /bin/bash not found` error. This is because in
Windows Git Bash environment, the Bash executable is actually located at
`/usr/bin/bash`, while the `/bin` directory may not exist, or may be
just an empty directory or a broken symlink that does not contain bash.

### Does this PR introduce _any_ user-facing change?
None

### How was this patch tested?
With this PR and `pre-commit` installed, windows coders can directly run
`bash format.sh` to clean lint issues.

- vLLM version: v0.15.0
- vLLM main:
9562912cea

Signed-off-by: whx-sjtu <2952154980@qq.com>
2026-02-13 15:53:16 +08:00

83 lines
3.0 KiB
Bash

#!/usr/bin/env bash
#
# Copyright (c) 2025 Huawei Technologies Co., Ltd. All Rights Reserved.
# Copyright 2023 The vLLM team.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# This file is a part of the vllm-ascend project.
# Adapted from https://github.com/vllm-project/vllm/tree/main/tools
#
set -euo pipefail
function usage() {
echo "This script collects the first contributions of new users in a given GitHub repository."
echo "Please set the environment variable GITHUB_TOKEN with repo read permission."
echo "Refer to https://docs.github.com/en/rest/authentication/authenticating-to-the-rest-api?apiVersion=2022-11-28"
echo ""
echo "Usage: $0 owner/repo base_sha head_sha"
echo "Example: $0 myorg/myrepo abcdef1 ghijk23"
}
if [ "$#" -ne 3 ]; then
usage
exit 1
fi
REPO="$1" # Example: myorg/myrepo
BASE="$2" # older commit (exclusive)
HEAD="$3" # newer commit (inclusive)
GITHUB_TOKEN="${GITHUB_TOKEN:-}"
if [ -z "$GITHUB_TOKEN" ]; then
echo "Please set the environment variable GITHUB_TOKEN with repo read permission."
echo "Refer to https://docs.github.com/en/rest/authentication/authenticating-to-the-rest-api?apiVersion=2022-11-28"
exit 1
fi
# All commits in the time order, format: sha|email|name|date
ALLCOMMITS=$(mktemp)
git log --pretty=format:'%H|%aE|%aN|%cI' --reverse --all > "$ALLCOMMITS"
# Get the first commit in this repo for each author email
FIRST_BY_EMAIL=$(mktemp)
awk -F'|' '!seen[$2]++ {print $2 "|" $1 "|" $4 "|" $3}' "$ALLCOMMITS" > "$FIRST_BY_EMAIL"
# format: email|first_sha|date|name
# Get the commit sha list in the range (base..head)
RANGE_SHAS=$(mktemp)
git rev-list "${BASE}..${HEAD}" > "$RANGE_SHAS"
echo "New user's first commit in ${REPO} (${BASE}..${HEAD})"
echo
# Get each email's first commit, if the first commit sha is in the range, query GitHub mapping and output
while IFS='|' read -r email sha date name; do
if grep -Fxq "$sha" "$RANGE_SHAS"; then
# Using GitHub API to check commit's author.login (if exists)
api_url="https://api.github.com/repos/${REPO}/commits/${sha}"
resp=$(curl -s -H "Authorization: token ${GITHUB_TOKEN}" -H "Accept: application/vnd.github.v3+json" "$api_url")
login=$(echo "$resp" | jq -r '.author.login // empty')
# fallback to name and email if login not found
if [ -n "$login" ]; then
user_display="@${login}"
else
user_display="$(echo "$name" | sed 's/^[[:space:]]*//;s/[[:space:]]*$//') <${email}>"
fi
echo "- ${user_display} — \`${sha}\` — ${date}"
fi
done < "$FIRST_BY_EMAIL"
# cleanup
rm -f "$ALLCOMMITS" "$FIRST_BY_EMAIL" "$RANGE_SHAS"