-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathfetch-confluence.ps1
More file actions
66 lines (55 loc) · 2.23 KB
/
fetch-confluence.ps1
File metadata and controls
66 lines (55 loc) · 2.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# Fetch Confluence pages as configured in confluence-pages.csv
function Invoke-DotnetRun {
param(
[string[]]$Arguments,
[string]$ErrorMessage
)
dotnet run --project .\ConfluenceRag\ConfluenceRag.csproj -- @Arguments
if ($LASTEXITCODE -ne 0) {
Write-Error "$ErrorMessage Exit code: $LASTEXITCODE"
exit $LASTEXITCODE
}
}
$csvPath = "${PSScriptRoot}\confluence-pages.csv"
if (-not (Test-Path $csvPath)) {
Write-Error "confluence-pages.csv not found. Please create the file with PageId,Name columns."
exit 1
}
try {
$pages = Import-Csv $csvPath
if (-not $pages -or $pages.Count -eq 0) {
Write-Error "confluence-pages.csv is empty or invalid."
exit 1
}
# Validate required columns exist
$firstPage = $pages[0]
if (-not $firstPage.PSObject.Properties.Name -contains "PageId" -or -not $firstPage.PSObject.Properties.Name -contains "Name") {
Write-Error "confluence-pages.csv must contain PageId and Name columns."
exit 1
}
} catch {
Write-Error "Failed to read confluence-pages.csv: $($_.Exception.Message)"
exit 1
}
# Check if set-secrets.ps1 exists
if (-not (Test-Path "${PSScriptRoot}\set-secrets.ps1")) {
Write-Error "set-secrets.ps1 not found. Please create the file to configure environment variables."
exit 1
}
. "${PSScriptRoot}\set-secrets.ps1"
# Check if ATLASSIAN_API_KEY is set
if (-not $env:ATLASSIAN_API_KEY) {
Write-Error "ATLASSIAN_API_KEY environment variable is not set. Please configure it in set-secrets.ps1."
exit 1
}
Write-Host "Fetching people metadata ..." -ForegroundColor Cyan
Invoke-DotnetRun @("fetch-people") "Failed to fetch people metadata."
Write-Host "Done fetching people metadata." -ForegroundColor Green
foreach ($page in $pages) {
Write-Host "Fetching $($page.Name) (ID: $($page.PageId)) ..." -ForegroundColor Cyan
Invoke-DotnetRun @("fetch", $page.PageId) "Failed to fetch $($page.Name) (ID: $($page.PageId))."
Write-Host "Done fetching $($page.Name).`n" -ForegroundColor Green
}
Write-Host "Embedding pages into the database..." -ForegroundColor Cyan
Invoke-DotnetRun @("chunk") "Failed to embed pages into the database."
Write-Host "Done embedding pages." -ForegroundColor Green