Skip to content
Merged
Show file tree
Hide file tree
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
8 changes: 8 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
.git
.github
.venv
dist
team-spec
**/__pycache__
**/*.pyc
**/.DS_Store
28 changes: 9 additions & 19 deletions .github/actions/setup/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,25 +12,15 @@ runs:
uses: actions/setup-python@v3
with:
python-version: '${{ inputs.python-version }}'
- name: Install poetry
uses: abatilo/actions-poetry@v2
- name: Setup poetry virtual environment
run: |
poetry config virtualenvs.create true --local
poetry config virtualenvs.in-project true --local
shell: bash
- uses: actions/cache/restore@v3
id: cache-restore
name: Restore caches for the virtual environment based on poetry.lock
- name: Install uv
uses: astral-sh/setup-uv@08807647e7069bb48b6ef5acd8ec9567f424441b # v8.1.0
with:
path: ./.venv
key: venv-${{ hashFiles('poetry.lock') }}
version: '0.10.11'
enable-cache: true
cache-dependency-glob: uv.lock
- name: Verify the lockfile
run: uv lock --check
shell: bash
- name: Install the project dependencies
run: poetry install --with dev
run: uv sync --frozen
shell: bash
- uses: actions/cache/save@v3
name: Save caches based on poetry.lock
if: ${{ !steps.cache-restore.outputs.cache-hit }}
with:
path: ./.venv
key: venv-${{ hashFiles('poetry.lock') }}
16 changes: 13 additions & 3 deletions .github/workflows/pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
with:
python-version: "3.10"
- name: Ruff Check
run: poetry run ruff check
run: uv run ruff check

test:
runs-on: ubuntu-latest
Expand All @@ -25,5 +25,15 @@ jobs:
uses: ./.github/actions/setup
with:
python-version: "3.9"
- name: Ruff Check
run: poetry run pytest tests
- name: Run tests
run: uv run pytest tests
- name: Build source and wheel distributions
run: uv build
- name: Smoke test wheel and source distributions
run: |
uv venv .smoke-wheel --python 3.9
uv pip install --python .smoke-wheel/bin/python --no-deps dist/*.whl
.smoke-wheel/bin/python -c "import importlib.resources as resources, src; assert resources.files('src').joinpath('prompts/DIFFS_SUMMARY_PROMPTS_TEMPLATE_en.txt').is_file(); assert resources.files('src').joinpath('locales/zh/LC_MESSAGES/gitlab-bot.mo').is_file()"
uv venv .smoke-sdist --python 3.9
uv pip install --python .smoke-sdist/bin/python --no-deps dist/*.tar.gz
.smoke-sdist/bin/python -c "import importlib.resources as resources, src; assert resources.files('src').joinpath('prompts/DIFFS_SUMMARY_PROMPTS_TEMPLATE_en.txt').is_file(); assert resources.files('src').joinpath('locales/zh/LC_MESSAGES/gitlab-bot.mo').is_file()"
12 changes: 7 additions & 5 deletions .github/workflows/push_docker_hub.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@ name: Push Docker Image
on:
push:
branches:
- master
- main
paths:
- "src/**"
- "*.py"
- "*.toml"
- "requirements.txt"
- ".github/workflows/ci.yml"
- "pyproject.toml"
- "uv.lock"
- "Dockerfile"
- ".dockerignore"
- ".github/workflows/push_docker_hub.yml"
workflow_dispatch:

jobs:
Expand Down Expand Up @@ -45,4 +47,4 @@ jobs:
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache
- name: Image Digest
run: echo ${{ steps.docker_build.outputs.digest }}
run: echo ${{ steps.docker_build.outputs.digest }}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -93,3 +93,4 @@ ENV/
.idea
.DS_Store
/.codex/
/team-spec/
37 changes: 21 additions & 16 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,28 @@
# See the License for the specific language governing permissions and
# limitations under the License.

FROM ghcr.io/astral-sh/uv:0.10.11 AS uv

FROM python:3.9-buster AS builder

COPY --from=uv /uv /bin/uv

WORKDIR /usr/app

# Create and activate virtual environment
RUN python -m venv /usr/app/venv
ENV PATH="/usr/app/venv/bin:$PATH"
ENV UV_COMPILE_BYTECODE=1 \
UV_LINK_MODE=copy \
UV_PYTHON_DOWNLOADS=0

# Preserve the Python 3.9 venv bootstrap packages used by gidgetlab 1.1.0.
RUN python -m venv .venv

# Install dependencies
COPY poetry.lock pyproject.toml ./
# Install dependencies only (no dev dependencies)
RUN poetry export -f requirements.txt | pip install -r /dev/stdin
# Install locked production dependencies before copying application code.
COPY pyproject.toml uv.lock ./
RUN uv lock --check && uv sync --frozen --no-dev --no-install-project --no-editable

# Install project
COPY . .
RUN pip install -e .
# Install the project as a non-editable package for the production stage.
COPY src ./src
RUN uv sync --frozen --no-dev --no-editable

FROM python:3.9-slim AS production

Expand All @@ -42,15 +48,14 @@ ENV BOT_LANGUAGE="en" \

WORKDIR /usr/app

# Copy only necessary files from builder
COPY --from=builder /usr/app/venv ./venv
COPY src src
# Copy only the production environment and application entry point.
COPY --from=builder /usr/app/.venv ./venv
COPY gitlab_bot.py gitlab_bot.py

ENV PATH="/usr/app/venv/bin:$PATH"

# Health check
HEALTHCHECK --interval=30s --timeout=30s --start-period=5s --retries=3 \
CMD curl -f http://localhost:${BOT_PORT}/ || exit 1
# Probe the existing gidgetlab health endpoint with the Python standard library.
HEALTHCHECK --interval=5s --timeout=3s --start-period=5s --retries=12 \
CMD ["python", "-c", "import os, urllib.request; urllib.request.urlopen('http://127.0.0.1:' + os.environ.get('BOT_PORT', '9998') + '/health', timeout=2).read()"]

CMD [ "python", "gitlab_bot.py" ]
29 changes: 21 additions & 8 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,14 +1,27 @@
init:
@pip install -e .
UV ?= uv
UV_REQUIRED_VERSION := 0.10.11

lint:
@poetry run ruff check
.PHONY: check-uv init lint fmt test i18n docker

fmt:
@poetry run ruff format
check-uv:
@command -v $(UV) >/dev/null 2>&1 || { echo "uv is required. Install uv $(UV_REQUIRED_VERSION) before continuing."; exit 1; }
@actual_version="$$( $(UV) --version 2>/dev/null | awk '{print $$2}' )"; \
if [ "$$actual_version" != "$(UV_REQUIRED_VERSION)" ]; then \
echo "uv $(UV_REQUIRED_VERSION) is required (found $$actual_version)."; \
exit 1; \
fi

init: check-uv
@$(UV) sync --frozen

lint: check-uv
@$(UV) run ruff check

fmt: check-uv
@$(UV) run ruff format

test: lint
@poetry run pytest tests
@$(UV) run pytest tests

i18n:
xgettext -d base -o src/locales/gitlab-bot.pot *.py
Expand All @@ -17,4 +30,4 @@ i18n:

docker:
export DOCKER_BUILDKIT=1
docker build -t coolbeevip/gitlab-bot --cache-from coolbeevip/gitlab-bot --build-arg BUILDKIT_INLINE_CACHE=1 .
docker build -t coolbeevip/gitlab-bot --cache-from coolbeevip/gitlab-bot --build-arg BUILDKIT_INLINE_CACHE=1 .
18 changes: 18 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,24 @@ This is a GitLab(13.2+) bot that utilizes [webhooks](https://docs.gitlab.com/ee/
* Pipeline Events (Not yet)
* Build Events (Not yet)

## Development

Install [uv](https://docs.astral.sh/uv/getting-started/installation/) version `0.10.11`, then create the locked development environment:

```shell
make init
```

Use the existing Makefile entry points for common tasks:

```shell
make lint
make fmt
make test
```

These commands use `uv.lock`; they do not install packages globally.

## How to use

In order to start the GitLab Bot, you'll need to prepare three environment variables: `BOT_GITLAB_USERNAME`, `BOT_GITLAB_URL`, and `BOT_GITLAB_TOKEN`.
Expand Down
20 changes: 19 additions & 1 deletion README_ZH.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,24 @@
* 管道事件(尚未支持)
* 构建事件(尚未支持)

## 本地开发

先安装 `0.10.11` 版本的 [uv](https://docs.astral.sh/uv/getting-started/installation/),再创建与锁文件一致的开发环境:

```shell
make init
```

常用操作继续使用现有 Makefile 入口:

```shell
make lint
make fmt
make test
```

这些命令使用 `uv.lock`,不会向全局 Python 环境安装依赖。

## 如何使用

为了启动 GitLab Bot,您需要准备三个环境变量:`BOT_GITLAB_USERNAME`、`BOT_GITLAB_URL` 和 `BOT_GITLAB_TOKEN`。
Expand Down Expand Up @@ -206,4 +224,4 @@ BOT_GIT_COMMIT_SUBJECT_EXAMPLES_MARKDOWN="* feat: 添加认证模块\n* fix: 解

该参数控制向合并请求添加新状态标签 "AI Review" 的功能,从而更好地跟踪 AI 辅助的代码审查。当启用时,当生成 AI 摘要时,会自动添加该标签。更新合并请求时标签会被移除,但 AI 功能被禁用。

默认情况下,此功能是启用的。如要禁用,请将 `BOT_GITLAB_MERGE_REQUEST_AIREVIEW_LABEL_ENABLED` 环境变量设置为 "false"。该功能特别适用于依赖 AI 辅助代码审查的项目,以确保所有代码更改在合并之前进行彻底审查。
默认情况下,此功能是启用的。如要禁用,请将 `BOT_GITLAB_MERGE_REQUEST_AIREVIEW_LABEL_ENABLED` 环境变量设置为 "false"。该功能特别适用于依赖 AI 辅助代码审查的项目,以确保所有代码更改在合并之前进行彻底审查。
Loading
Loading