Skip to content

utkuufuk/habit-service

Repository files navigation

habit-service

CI Latest Release Coverage Status

Habit service for entrello, built on top of Google Sheets.

Spreadsheet Format

You must have a dedicated sheet for the current month in your spreadsheet.

Do not delete sheets for past months as they may be used by the progress report feature.

Sheet names must follow a certain convention. Some examples:

Example Sheet Names

The sheet format must follow this specific convention:

  • Dates go to the first column, starting from A3. (Leave A1 and A2 blank.)
  • Habit names go to the first row, starting from B1.
  • Scores go to the second row, starting from B2.

Here's an example:

Example Sheet

Conditional formatting of the colors can be adjusted from Google Sheets UI.

Usage

Start the server:

go run ./cmd/server

GET <SERVER_URL>/entrello

Fetch all habits that are not marked yet as done/skipped/failed.

entrello will periodically call this endpoint and create a Trello card for each returned habit.

Alternatively, you can run following command to print the same result set on the console:

go run ./cmd/cli

POST <SERVER_URL>/entrello

Mark a habit as done/skipped/failed.

entrello will call this endpoint whenever a habit card is archived on your Trello board.

POST <SERVER_URL>/progress-report

Generate and send a progress report as a Telegram message.

This endpoint will not be called by entrello. It's meant to be called by a separate scheduled job, or manually on demand. You don't have to put anything in the POST request body, but if you set the SECRET environment variable, you must also set the X-API-Key header accordingly.

Alternatively, you can run following command to generate and send a progress report:

go run ./cmd/cli progress-report

Configuration

Put your environment variables in a file called .env, based on .env.example.

Environment Variable Description
TIMEZONE_LOCATION Timezone, e.g. "Europe/Istanbul"
GSHEETS_CLIENT_ID Google Sheets Client ID
GSHEETS_CLIENT_SECRET Google Sheets Client Secret
GSHEETS_ACCESS_TOKEN Google Sheets Access Token
GSHEETS_REFRESH_TOKEN Google Sheets Refresh Token
SPREADSHEET_ID Google Spreadsheet ID
PORT HTTP port (server mode only)
SECRET API secret (server mode only, optional)
PROGRESS_REPORT_SKIP_LIST Comma-separated habit names to be excluded from progress reports
TELEGRAM_TOKEN Telegram Bot API Token
TELEGRAM_CHAT_ID Telegram Bot Chat ID

Running With Docker

A new Docker image will be created upon each release.

  1. Authenticate with the GitHub container registry (only once):

    echo $GITHUB_ACCESS_TOKEN | docker login ghcr.io -u GITHUB_USERNAME --password-stdin
  2. Pull the latest Docker image:

    docker pull ghcr.io/utkuufuk/habit-service/image:latest
  3. Start a container:

    # server
    docker run -d \
        -p <PORT>:<PORT> \
        --env-file </abs/path/to/.env> \
        --restart unless-stopped \
        --name habit-service \
        ghcr.io/utkuufuk/habit-service/image:latest
    
    # CLI
    docker run --rm \
        --env-file </abs/path/to/.env> \
        ghcr.io/utkuufuk/habit-service/image:latest \
        ./cli