Skip to content

Commit 8134536

Browse files
committed
Added helper scripts
- load .env file - cleanup workspace
1 parent 8a1c705 commit 8134536

File tree

5 files changed

+73
-2
lines changed

5 files changed

+73
-2
lines changed

.env.example

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
TOGGL_API_TOKEN={YOUR_API_TOKEN}
2+
TOGGL_WORKSPACE_ID={YOUR_WORKSPACE_ID}

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
Tests/config.json
1+
Tests/config.json
2+
.env

README.md

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff 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`

scripts/cleanup-workspace.ps1

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
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+
}

scripts/load-env.ps1

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
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+
}

0 commit comments

Comments
 (0)