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
14 changes: 13 additions & 1 deletion .github/workflows/docker.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
---
name: Build and Push Docker Images

on:
on: # yamllint disable-line rule:truthy
push:
branches: [main]
tags: ['v*.*.*']
Expand All @@ -22,6 +23,17 @@ jobs:
- name: Checkout repository
uses: actions/checkout@v4

- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: 'stable'

- name: Install dependencies
run: make deps

- name: Run tests
run: make ci
Comment on lines +26 to +35
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🔴 Critical

🧩 Analysis chain

Verify that the Makefile targets are ordered correctly.

The workflow runs make deps followed by make ci. Ensure that make ci doesn't already run make deps internally, as this would result in unnecessary duplication. If make ci is comprehensive (including dependency installation), consider removing the separate make deps step.

Run the following script to check the Makefile targets:


🏁 Script executed:

#!/bin/bash
# Description: Examine Makefile to verify deps and ci targets and their dependencies

# Check if Makefile exists and display the deps and ci target definitions
if [ -f "Makefile" ]; then
  echo "=== Makefile deps target ==="
  rg -A 10 '^deps:' Makefile || echo "deps target not found"
  echo ""
  echo "=== Makefile ci target ==="
  rg -A 10 '^ci:' Makefile || echo "ci target not found"
else
  echo "Makefile not found in repository"
fi

Length of output: 287


Remove the duplicate make deps step from the workflow.

The ci target already includes deps as a prerequisite (ci: deps fmt vet test build), so running make deps separately before make ci causes unnecessary duplication. Remove the "Install dependencies" step (line 31-32) and keep only the "Run tests" step, which will automatically install dependencies first.

🤖 Prompt for AI Agents
In .github/workflows/docker.yml around lines 26 to 35, remove the redundant
"Install dependencies" step that runs `make deps` (lines 31-32) because the `ci`
Make target already depends on `deps`; update the workflow to delete those two
lines so only the "Run tests" step remains and `make ci` will handle installing
dependencies first.


- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,6 @@ docker-compose.override.yml
.env

/data/
-e
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🔴 Critical

Remove the erroneous -e entry.

The literal -e entry appears to be a mistake, possibly from an echo -e command that was accidentally committed. This is not a valid ignore pattern and should be removed.

Apply this diff to remove the erroneous entry:

 /data/
--e
 # Build artifacts
 build/
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
-e
/data/
# Build artifacts
build/
🤖 Prompt for AI Agents
In .gitignore around line 39, there's an erroneous literal entry "-e" that is
not a valid ignore pattern; remove that line so the file does not contain the
stray "-e" entry (simply delete the line and save the file), then run a quick
git status to confirm no unintended changes remain and commit the fix.

# Build artifacts
build/
56 changes: 56 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# .pre-commit-config.yaml

---
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v5.0.0
hooks:
- id: trailing-whitespace
always_run: true
- id: end-of-file-fixer
always_run: true
- id: check-yaml
always_run: true
- id: check-added-large-files
always_run: true
- id: check-merge-conflict
always_run: true
- id: check-symlinks
always_run: true
- id: detect-private-key
always_run: true
- id: no-commit-to-branch
args: ['--branch', 'main']
always_run: true

- repo: https://github.com/golangci/golangci-lint
rev: v1.55.2
hooks:
- id: golangci-lint
args: [--fix, --timeout=5m]
always_run: true

- repo: local
hooks:
- id: go-fmt
name: go fmt
entry: gofmt -w .
language: system
types: [go]
always_run: true

- id: go-vet
name: go vet
entry: go vet ./...
language: system
types: [go]
pass_filenames: false
always_run: true

- id: go-tests
name: go test
entry: go test 5mdt/bd_bot/...
language: system
types: [go]
pass_filenames: false
always_run: true
11 changes: 11 additions & 0 deletions .yamllint
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---

extends: default

rules:
braces:
level: warning
max-spaces-inside: 1
comments-indentation: disable
comments: disable
line-length: disable
84 changes: 84 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
# Makefile for bd_bot project

# Go parameters
GOCMD=go
GOBUILD=$(GOCMD) build
GOTEST=$(GOCMD) test
GOVET=$(GOCMD) vet
GOFMT=gofmt

# Directories
CMD_DIR=./cmd/app
INTERNAL_DIR=./internal
BUILD_DIR=./build

# Binary output
BINARY_NAME=bd_bot
BINARY_LINUX=$(BINARY_NAME)_linux
BINARY_DARWIN=$(BINARY_NAME)_darwin
BINARY_WIN=$(BINARY_NAME)_windows.exe

# Packages
PKG=5mdt/bd_bot/...

# Ensure build directory exists
$(shell mkdir -p $(BUILD_DIR))

.PHONY: all test vet fmt clean build build-linux build-darwin build-windows build-all deps pre-commit docker-build docker-run ci

# Default target
all: fmt vet test build

# Run tests
test:
$(GOTEST) $(PKG)

# Run code quality checks
vet:
$(GOVET) $(PKG)

# Format code
fmt:
$(GOFMT) -w .

# Clean build artifacts
clean:
rm -rf $(BUILD_DIR)

# Install dependencies
deps:
$(GOCMD) mod tidy
$(GOCMD) mod download

# Run pre-commit hooks
pre-commit:
pre-commit run --all-files

# Build for current platform
build:
$(GOBUILD) -o $(BUILD_DIR)/$(BINARY_NAME) $(CMD_DIR)

# Build for Linux
build-linux:
GOOS=linux GOARCH=amd64 $(GOBUILD) -o $(BUILD_DIR)/$(BINARY_LINUX) $(CMD_DIR)

# Build for macOS
build-darwin:
GOOS=darwin GOARCH=amd64 $(GOBUILD) -o $(BUILD_DIR)/$(BINARY_DARWIN) $(CMD_DIR)

# Build for Windows
build-windows:
GOOS=windows GOARCH=amd64 $(GOBUILD) -o $(BUILD_DIR)/$(BINARY_WIN) $(CMD_DIR)

# Build for all platforms
build-all: build-linux build-darwin build-windows

# Docker-related tasks
docker-build:
docker build -t bd_bot .

docker-run:
docker run -it --rm bd_bot

# CI tasks
ci: deps fmt vet test build
1 change: 0 additions & 1 deletion cmd/app/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ func main() {

tpl := templates.LoadTemplates()


http.HandleFunc("/", handlers.IndexHandler(tpl, telegramBot))
http.HandleFunc("/bot-info", handlers.BotInfoHandler(tpl, telegramBot))
http.HandleFunc("/save-row", handlers.SaveRowHandler(tpl))
Expand Down
10 changes: 5 additions & 5 deletions cmd/app/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,11 @@ func TestMainHandlers(t *testing.T) {
}

form := url.Values{
"idx": {"-1"},
"name": {"X"},
"birth_date": {"01-01"},
"last_notification":{"2025-01-01T12:00:00Z"},
"chat_id": {"1"},
"idx": {"-1"},
"name": {"X"},
"birth_date": {"01-01"},
"last_notification": {"2025-01-01T12:00:00Z"},
"chat_id": {"1"},
}
w = doRequest(t, "POST", "/save-row", form, handlers.SaveRowHandler(tpl))
if w.Code != http.StatusOK {
Expand Down
2 changes: 2 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
---

services:
app:
build: .
Expand Down
42 changes: 42 additions & 0 deletions internal/bot/birthday_notification_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package bot

import (
"testing"
"time"

"5mdt/bd_bot/internal/models"
)

func TestBirthdayNotificationUniqueness(t *testing.T) {
bot := &Bot{} // Create a minimal bot instance for testing

// Create a test birthday entry
testBirthday := models.Birthday{
Name: "Test User",
BirthDate: time.Now().Format("01-02"), // Today's month and day
ChatID: 12345,
}

// Simulate first birthday notification
shouldSend := bot.shouldSendBirthdayNotification(testBirthday, "BIRTHDAY_TODAY", 0)
if !shouldSend {
t.Error("First birthday notification should be sent")
}

// Update last notification time to now
testBirthday.LastNotification = time.Now()

// Simulate second birthday notification on the same day
shouldSend = bot.shouldSendBirthdayNotification(testBirthday, "BIRTHDAY_TODAY", 0)
if shouldSend {
t.Error("Second birthday notification on the same day should not be sent")
}

// Simulate birthday notification on a different day
futureTime := time.Now().AddDate(0, 0, 1)
testBirthday.LastNotification = futureTime
shouldSend = bot.shouldSendBirthdayNotification(testBirthday, "BIRTHDAY_TODAY", 0)
if !shouldSend {
t.Error("Birthday notification should be sent on a different day")
}
}
Loading