File tree Expand file tree Collapse file tree 5 files changed +73
-2
lines changed Expand file tree Collapse file tree 5 files changed +73
-2
lines changed Original file line number Diff line number Diff line change 1+ TOGGL_API_TOKEN = {YOUR_API_TOKEN}
2+ TOGGL_WORKSPACE_ID = {YOUR_WORKSPACE_ID}
Original file line number Diff line number Diff line change 1- Tests /config.json
1+ Tests /config.json
2+ .env
Original file line number Diff line number Diff line change @@ -27,4 +27,15 @@ PowerShell module to interact with the [**Toggl API**](https://engineering.toggl
2727- ** Remove-TogglTimeEntry** : Deletes a time entry.
2828
2929### Authentication
30- - ** Get-TogglAuthHeader** : Generates the authentication header from the API token.
30+ - ** Get-TogglAuthHeader** : Generates the authentication header from the API token.
31+
32+ ## Development
33+
34+ ### Tests
35+ To run tests you need to have your own API key and workspace. Once you have it create ` .env ` using ` .env.example ` as an example.
36+
37+ To load environment variables to current session use ` .\scripts\load-env.ps1 `
38+
39+ To cleanup workspace use ` .\scripts\cleanup-workspace.ps1 `
40+
41+ Tests load settins either from environment variables or from ` .\Tests\config.json `
Original file line number Diff line number Diff line change 1+ param (
2+ [Parameter (Mandatory = $false )]
3+ [string ]$ApiToken = $env: TOGGL_API_TOKEN ,
4+
5+ [Parameter (Mandatory = $false )]
6+ [int ]$WorkspaceId = [int ]$env: TOGGL_WORKSPACE_ID
7+ )
8+
9+ if (-not $ApiToken ) {
10+ Write-Error " ApiToken is required."
11+ return
12+ }
13+
14+ if (-not $WorkspaceId ) {
15+ Write-Error " WorkspaceId is required."
16+ return
17+ }
18+
19+ Clear-Host
20+ Import-Module .\Toggl.API\Toggl.API.psm1 - Force
21+
22+ Write-Host " Cleaning up the workspace"
23+
24+ Write-Host " Removing projects" - ForegroundColor DarkGreen
25+ Get-TogglProjects - ApiToken $ApiToken - WorkspaceId $WorkspaceId | % {
26+ Write-Host " Removing project: $ ( $_.name ) " - ForegroundColor DarkGray
27+ Remove-TogglProject `
28+ - ApiToken $ApiToken `
29+ - WorkspaceId $WorkspaceId `
30+ - ProjectId $_.id
31+ }
32+
33+ Write-Host " Removing tags" - ForegroundColor DarkGreen
34+ Get-TogglTags - ApiToken $ApiToken - WorkspaceId $WorkspaceId | % {
35+ Write-Host " Removing tag: $ ( $_.name ) " - ForegroundColor DarkGray
36+ Remove-TogglTag `
37+ - ApiToken $ApiToken `
38+ - WorkspaceId $WorkspaceId `
39+ - TagId $_.id
40+ }
41+
42+ Write-Host " Removing time entries" - ForegroundColor DarkGreen
43+ Get-TogglTimeEntries - ApiToken $ApiToken | ? { $_.wid -eq $WorkspaceId } | ? { $_.server_deleted_at -eq $null } | % {
44+ Write-Host " Removing time entry: $ ( $_.description ) " - ForegroundColor DarkGray
45+ Remove-TogglTimeEntry `
46+ - ApiToken $ApiToken `
47+ - WorkspaceId $WorkspaceId `
48+ - TimeEntryId $_.id
49+ }
Original file line number Diff line number Diff line change 1+ Get-Content " $PSScriptRoot \..\.env" | ForEach-Object {
2+ if ($_ -match ' ^(.*?)=(.*)$' ) {
3+ $key = $matches [1 ].Trim()
4+ $value = $matches [2 ].Trim()
5+ Write-Host " Setting environment variable: $key =$value " - ForegroundColor Green
6+ Set-Item " env:$key " $value
7+ }
8+ }
You can’t perform that action at this time.
0 commit comments