diff --git a/.github/workflows/biweekly-time-reporting.yml b/.github/workflows/biweekly-time-reporting.yml new file mode 100644 index 0000000..7c7b143 --- /dev/null +++ b/.github/workflows/biweekly-time-reporting.yml @@ -0,0 +1,86 @@ +name: Bi-Weekly Time Reporting +description: Posts a time report from Toggl to Slack of all billable time in the date range (defaults to prior 2 weeks). + +on: + workflow_dispatch: + inputs: + start-date: + description: "Start date for the report period (YYYY-MM-DD)" + required: false + end-date: + description: "End date for the report period (YYYY-MM-DD)" + required: false + +jobs: + time-reporting: + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v6 + + - name: Set up Python + uses: actions/setup-python@v6 + with: + python-version-file: .github/workflows/.python-version + + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install -e . + + - name: Download Toggl time entries + id: download + env: + TOGGL_API_TOKEN: "${{ secrets.TOGGL_API_TOKEN }}" + TOGGL_USER_AGENT: "compilerla/compiler-admin" + TOGGL_WORKSPACE_ID: "${{ secrets.TOGGL_WORKSPACE_ID }}" + run: | + START_DATE="${{ github.event.inputs.start-date }}" + END_DATE="${{ github.event.inputs.end-date }}" + + if [[ -z "$START_DATE" && -z "$END_DATE" ]]; then + END_DATE=$(date -d "yesterday" +%Y-%m-%d) + START_DATE=$(date -d "$END_DATE - 13 days" +%Y-%m-%d) + elif [[ -n "$START_DATE" && -z "$END_DATE" ]]; then + END_DATE=$(date -d "$START_DATE + 13 days" +%Y-%m-%d) + elif [[ -z "$START_DATE" && -n "$END_DATE" ]]; then + START_DATE=$(date -d "$END_DATE - 13 days" +%Y-%m-%d) + fi + + ARGS="--start=$START_DATE --end=$END_DATE" + + OUTPUT=$(compiler-admin time download $ARGS) + echo "$OUTPUT" + + FILENAME=$(echo "$OUTPUT" | grep "Download complete:" | cut -d' ' -f3) + echo "filename=$FILENAME" >> $GITHUB_OUTPUT + + - name: Summarize + id: summarize + run: | + FILENAME="${{ steps.download.outputs.filename }}" + { + echo "summary<> "$GITHUB_OUTPUT" + + - name: Post to Slack + id: slack + if: success() + uses: slackapi/slack-github-action@v3.0.1 + with: + method: files.uploadV2 + token: ${{ secrets.SLACK_BOT_TOKEN }} + payload: | + channel_id: ${{ secrets.SLACK_CHANNEL_ID }} + initial_comment: "${{ steps.summarize.outputs.summary }}" + file: ${{ steps.download.outputs.filename }} + filename: ${{ steps.download.outputs.filename }} + + - name: Cleanup + id: cleanup + if: always() + run: | + FILENAME="${{ steps.download.outputs.filename }}" + rm -f "$FILENAME" diff --git a/.github/workflows/time-reporting.yml b/.github/workflows/monthly-time-reporting.yml similarity index 100% rename from .github/workflows/time-reporting.yml rename to .github/workflows/monthly-time-reporting.yml