| name | time-tracking-time-tracking-with-github-actions |
| description | Sub-skill of time-tracking: Time Tracking with GitHub Actions (+1). |
| version | 1.0.0 |
| category | business |
| type | reference |
| scripts_exempt | true |
Time Tracking with GitHub Actions (+1)
Time Tracking with GitHub Actions
name: Log Development Time
on:
push:
branches: [main, develop]
jobs:
log-time:
runs-on: ubuntu-latest
steps:
- name: Log commit time to Toggl
env:
TOGGL_API_TOKEN: ${{ secrets.TOGGL_API_TOKEN }}
TOGGL_WORKSPACE_ID: ${{ secrets.TOGGL_WORKSPACE_ID }}
TOGGL_PROJECT_ID: ${{ secrets.TOGGL_PROJECT_ID }}
run: |
# Log 30 minute entry for each commit
DESCRIPTION="Commit: ${{ github.event.head_commit.message }}"
START_TIME=$(date -u -d '30 minutes ago' +%Y-%m-%dT%H:%M:%S.000Z)
curl -s -X POST -u "$TOGGL_API_TOKEN:api_token" \
-H "Content-Type: application/json" \
"https://api.track.toggl.com/api/v9/workspaces/$TOGGL_WORKSPACE_ID/time_entries" \
-d '{
"created_with": "github_actions",
"description": "'"${DESCRIPTION:0:100}"'",
"workspace_id": '"$TOGGL_WORKSPACE_ID"',
"project_id": '"$TOGGL_PROJECT_ID"',
"start": "'"$START_TIME"'",
"duration": 1800,
"tags": ["github", "automated"]
}'
Slack Daily Summary
"""slack_time_summary.py - Post daily time summary to Slack"""
import os
import requests
from datetime import datetime, timedelta
def post_daily_summary(toggl_token, slack_webhook):
"""Post daily time summary to Slack."""
toggl = TogglClient(toggl_token)
today = datetime.now().date()
start = datetime.combine(today, datetime.min.time())
end = datetime.combine(today, datetime.max.time())
entries = toggl.get_time_entries(start, end) or []
total_hours = sum(
e.get("duration", 0) / 3600
for e in entries
if e.get("duration", 0) > 0
)
message = {
"blocks": [
{
"type": "header",
"text": {
"type": "plain_text",
"text": f"Daily Time Summary - {today}"
}
},
{
"type": "section",
"fields": [
{
"type": "mrkdwn",
"text": f"*Total Hours:*\n{total_hours:.1f}"
},
{
: ,
:
}
]
}
]
}
entries:
activities = .join([
e (entries, key= x: x.get(, ), reverse=)[:]
])
message[].append({
: ,
: {
: ,
:
}
})
response = requests.post(slack_webhook, json=message)
response.status_code ==
__name__ == :
success = post_daily_summary(
toggl_token=os.environ[],
slack_webhook=os.environ[]
)
( success )